TST: Set up auth unit tests (#14)
This commit is contained in:
parent
253aac1fd4
commit
453840f948
3 changed files with 69 additions and 1 deletions
|
@ -4,7 +4,11 @@
|
||||||
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
|
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
|
||||||
|
|
||||||
module.exports = function(defaults) {
|
module.exports = function(defaults) {
|
||||||
let app = new EmberApp(defaults, {});
|
let app = new EmberApp(defaults, {
|
||||||
|
'ember-cli-babel': {
|
||||||
|
includePolyfill: (EmberApp.env() === 'test'),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
app.import('bower_components/bootstrap/dist/css/bootstrap.min.css');
|
app.import('bower_components/bootstrap/dist/css/bootstrap.min.css');
|
||||||
app.import('bower_components/bootstrap/dist/css/bootstrap-theme.min.css');
|
app.import('bower_components/bootstrap/dist/css/bootstrap-theme.min.css');
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
"ember-cli": "~2.14.0",
|
"ember-cli": "~2.14.0",
|
||||||
"ember-cli-app-version": "^3.0.0",
|
"ember-cli-app-version": "^3.0.0",
|
||||||
"ember-cli-babel": "^6.3.0",
|
"ember-cli-babel": "^6.3.0",
|
||||||
|
"ember-cli-code-coverage": "^0.4.1",
|
||||||
"ember-cli-dependency-checker": "^1.3.0",
|
"ember-cli-dependency-checker": "^1.3.0",
|
||||||
"ember-cli-eslint": "^3.0.0",
|
"ember-cli-eslint": "^3.0.0",
|
||||||
"ember-cli-flash": "1.4.3",
|
"ember-cli-flash": "1.4.3",
|
||||||
|
@ -41,6 +42,7 @@
|
||||||
"ember-resolver": "^4.0.0",
|
"ember-resolver": "^4.0.0",
|
||||||
"ember-responsive": "^2.0.4",
|
"ember-responsive": "^2.0.4",
|
||||||
"ember-simple-auth": "1.4.0",
|
"ember-simple-auth": "1.4.0",
|
||||||
|
"ember-sinon": "^1.0.0",
|
||||||
"ember-source": "~2.14.0",
|
"ember-source": "~2.14.0",
|
||||||
"loader.js": "^4.2.3"
|
"loader.js": "^4.2.3"
|
||||||
},
|
},
|
||||||
|
|
62
tests/unit/authenticators/application-test.js
Normal file
62
tests/unit/authenticators/application-test.js
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
import { moduleFor, test } from 'ember-qunit';
|
||||||
|
import sinon from 'sinon';
|
||||||
|
import Ember from 'ember';
|
||||||
|
|
||||||
|
moduleFor('authenticator:application', 'Unit | application', {
|
||||||
|
unit: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('should restore session when token is present', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
const authenticator = this.subject();
|
||||||
|
const data = {data: {token: 'foo'}};
|
||||||
|
return authenticator.restore(data).then((obs) => {
|
||||||
|
assert.equal(obs, data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should not restore session when token is absent', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
const authenticator = this.subject();
|
||||||
|
const data = {data: {token: ''}};
|
||||||
|
return authenticator.restore(data).catch(() => {
|
||||||
|
assert.ok(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('`invalidate` should invalidate the session', function(assert) {
|
||||||
|
assert.expect(1);
|
||||||
|
const authenticator = this.subject();
|
||||||
|
return authenticator.invalidate().then(() => {
|
||||||
|
assert.ok(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('`makeRequest` should make a request', function(assert) {
|
||||||
|
assert.expect(2);
|
||||||
|
const stub = sinon.stub(Ember.$, 'ajax');
|
||||||
|
stub.resolves(42);
|
||||||
|
const authenticator = this.subject();
|
||||||
|
authenticator.set('serverTokenEndpoint', 'foo')
|
||||||
|
const promise = authenticator.makeRequest({bar: 'baz'}).then((d) => {
|
||||||
|
assert.equal(d, 42);
|
||||||
|
});
|
||||||
|
assert.ok(Ember.$.ajax.calledWithMatch({url: 'foo', data: {bar: 'baz'}}));
|
||||||
|
Ember.$.ajax.restore();
|
||||||
|
return promise;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('authenticate should craft a nice payload', function(assert) {
|
||||||
|
assert.expect(2);
|
||||||
|
const stub = sinon.stub(Ember.$, 'ajax');
|
||||||
|
stub.resolves(42);
|
||||||
|
const authenticator = this.subject();
|
||||||
|
authenticator.set('serverTokenEndpoint', 'foo')
|
||||||
|
const promise = authenticator.authenticate('myusername', 'mypassword').then((d) => {
|
||||||
|
assert.equal(d, 42);
|
||||||
|
});
|
||||||
|
assert.ok(Ember.$.ajax.calledWithMatch({url: 'foo', data: {username: 'myusername', password: 'mypassword'}}));
|
||||||
|
Ember.$.ajax.restore();
|
||||||
|
return promise;
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue