diff --git a/ember-cli-build.js b/ember-cli-build.js index eba9ff4..2e0af58 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -4,7 +4,11 @@ const EmberApp = require('ember-cli/lib/broccoli/ember-app'); 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-theme.min.css'); diff --git a/package.json b/package.json index 1905667..8a41093 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "ember-cli": "~2.14.0", "ember-cli-app-version": "^3.0.0", "ember-cli-babel": "^6.3.0", + "ember-cli-code-coverage": "^0.4.1", "ember-cli-dependency-checker": "^1.3.0", "ember-cli-eslint": "^3.0.0", "ember-cli-flash": "1.4.3", @@ -41,6 +42,7 @@ "ember-resolver": "^4.0.0", "ember-responsive": "^2.0.4", "ember-simple-auth": "1.4.0", + "ember-sinon": "^1.0.0", "ember-source": "~2.14.0", "loader.js": "^4.2.3" }, diff --git a/tests/unit/authenticators/application-test.js b/tests/unit/authenticators/application-test.js new file mode 100644 index 0000000..48847fb --- /dev/null +++ b/tests/unit/authenticators/application-test.js @@ -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; +});