diff --git a/packages/ember-simple-auth/src/session-stores/ephemeral.js b/packages/ember-simple-auth/src/session-stores/ephemeral.js index 3b7a71122..7d89e17c4 100644 --- a/packages/ember-simple-auth/src/session-stores/ephemeral.js +++ b/packages/ember-simple-auth/src/session-stores/ephemeral.js @@ -10,11 +10,12 @@ import BaseStore from './base'; @extends BaseStore @public */ -export default BaseStore.extend({ - init() { - this._super(...arguments); +export default class EphemeralStore extends BaseStore { + constructor(owner, args) { + super(owner, args); + this.clear(); - }, + } /** Persists `data`. This replaces all currently stored data. @@ -29,7 +30,7 @@ export default BaseStore.extend({ this._data = JSON.stringify(data || {}); return Promise.resolve(); - }, + } /** Returns all data currently stored as a plain object. @@ -43,7 +44,7 @@ export default BaseStore.extend({ const data = JSON.parse(this._data) || {}; return Promise.resolve(data); - }, + } /** Clears the store. @@ -58,5 +59,5 @@ export default BaseStore.extend({ this._data = '{}'; return Promise.resolve(); - }, -}); + } +} diff --git a/packages/ember-simple-auth/src/session-stores/local-storage.js b/packages/ember-simple-auth/src/session-stores/local-storage.js index 0c379bf81..2daf1dcd9 100644 --- a/packages/ember-simple-auth/src/session-stores/local-storage.js +++ b/packages/ember-simple-auth/src/session-stores/local-storage.js @@ -22,7 +22,7 @@ import isFastBoot from '../utils/is-fastboot'; @extends BaseStore @public */ -export default BaseStore.extend({ +export default class LocalStorageStore extends BaseStore { /** The `localStorage` key the store persists data in. @@ -32,7 +32,7 @@ export default BaseStore.extend({ @default 'ember_simple_auth-session' @public */ - key: 'ember_simple_auth-session', + key = 'ember_simple_auth-session'; init() { this._super(...arguments); @@ -44,13 +44,13 @@ export default BaseStore.extend({ if (!this.get('_isFastBoot')) { window.addEventListener('storage', this._boundHandler); } - }, + } willDestroy() { if (!this.get('_isFastBoot')) { window.removeEventListener('storage', this._boundHandler); } - }, + } /** Persists the `data` in the `localStorage`. @@ -67,7 +67,7 @@ export default BaseStore.extend({ localStorage.setItem(this.key, data); return Promise.resolve(); - }, + } /** Returns all data currently stored in the `localStorage` as a plain object. @@ -81,7 +81,7 @@ export default BaseStore.extend({ let data = localStorage.getItem(this.key); return Promise.resolve(JSON.parse(data) || {}); - }, + } /** Clears the store by deleting the @@ -98,7 +98,7 @@ export default BaseStore.extend({ this._lastData = {}; return Promise.resolve(); - }, + } _handleStorageEvent(e) { if (e.key === this.get('key')) { @@ -109,5 +109,5 @@ export default BaseStore.extend({ } }); } - }, -}); + } +} diff --git a/packages/ember-simple-auth/src/session-stores/session-storage.js b/packages/ember-simple-auth/src/session-stores/session-storage.js index 101acb437..1032667c8 100644 --- a/packages/ember-simple-auth/src/session-stores/session-storage.js +++ b/packages/ember-simple-auth/src/session-stores/session-storage.js @@ -18,7 +18,7 @@ import isFastBoot from '../utils/is-fastboot'; @extends BaseStore @public */ -export default BaseStore.extend({ +export default class SessionStorageStore extends BaseStore { /** The `sessionStorage` key the store persists data in. @@ -28,7 +28,7 @@ export default BaseStore.extend({ @default 'ember_simple_auth-session' @public */ - key: 'ember_simple_auth-session', + key = 'ember_simple_auth-session'; init() { this._super(...arguments); @@ -39,13 +39,13 @@ export default BaseStore.extend({ if (!this.get('_isFastBoot')) { window.addEventListener('storage', bind(this, this._handleStorageEvent)); } - }, + } willDestroy() { if (!this.get('_isFastBoot')) { window.removeEventListener('storage', bind(this, this._handleStorageEvent)); } - }, + } /** Persists the `data` in the `sessionStorage`. @@ -62,7 +62,7 @@ export default BaseStore.extend({ sessionStorage.setItem(this.key, data); return Promise.resolve(); - }, + } /** Returns all data currently stored in the `sessionStorage` as a plain object. @@ -76,7 +76,7 @@ export default BaseStore.extend({ let data = sessionStorage.getItem(this.key); return Promise.resolve(JSON.parse(data) || {}); - }, + } /** Clears the store by deleting the @@ -93,7 +93,7 @@ export default BaseStore.extend({ this._lastData = {}; return Promise.resolve(); - }, + } _handleStorageEvent(e) { if (e.key === this.get('key')) { @@ -104,5 +104,5 @@ export default BaseStore.extend({ } }); } - }, -}); + } +} diff --git a/packages/test-esa/tests/unit/session-stores/ephemeral-test.js b/packages/test-esa/tests/unit/session-stores/ephemeral-test.js index a4bf35673..ac3a85932 100644 --- a/packages/test-esa/tests/unit/session-stores/ephemeral-test.js +++ b/packages/test-esa/tests/unit/session-stores/ephemeral-test.js @@ -6,7 +6,7 @@ module('EphemeralStore', function (hooks) { itBehavesLikeAStore({ hooks, store() { - return Ephemeral.create(); + return new Ephemeral(); }, }); }); diff --git a/packages/test-esa/tests/unit/session-stores/local-storage-test.js b/packages/test-esa/tests/unit/session-stores/local-storage-test.js index e854c336e..65d3c830d 100644 --- a/packages/test-esa/tests/unit/session-stores/local-storage-test.js +++ b/packages/test-esa/tests/unit/session-stores/local-storage-test.js @@ -2,23 +2,28 @@ import { module } from 'qunit'; import LocalStorage from 'ember-simple-auth/session-stores/local-storage'; import itBehavesLikeAStore from './shared/store-behavior'; import itBehavesLikeAStorageEventHandler from './shared/storage-event-handler-behavior'; +import { setupTest } from 'ember-qunit'; + +class TestLocalStorage extends LocalStorage { + _isFastBoot = false; +} module('LocalStorageStore', function (hooks) { + setupTest(hooks); + itBehavesLikeAStore({ hooks, - store() { - return LocalStorage.create({ - _isFastBoot: false, - }); + store(_sinon, owner) { + owner.register('session-store:local-storage', TestLocalStorage); + return owner.lookup('session-store:local-storage'); }, }); itBehavesLikeAStorageEventHandler({ hooks, - store() { - return LocalStorage.create({ - _isFastBoot: false, - }); + store(_sinon, owner) { + owner.register('session-store:local-storage', TestLocalStorage); + return owner.lookup('session-store:local-storage'); }, }); }); diff --git a/packages/test-esa/tests/unit/session-stores/session-storage-test.js b/packages/test-esa/tests/unit/session-stores/session-storage-test.js index b3e547547..e7208180f 100644 --- a/packages/test-esa/tests/unit/session-stores/session-storage-test.js +++ b/packages/test-esa/tests/unit/session-stores/session-storage-test.js @@ -2,23 +2,28 @@ import { module } from 'qunit'; import SessionStorage from 'ember-simple-auth/session-stores/session-storage'; import itBehavesLikeAStore from './shared/store-behavior'; import itBehavesLikeAStorageEventHandler from './shared/storage-event-handler-behavior'; +import { setupTest } from 'ember-qunit'; + +class TestSessionStorage extends SessionStorage { + _isFastBoot = false; +} module('SessionStorageStore', function (hooks) { + setupTest(hooks); + itBehavesLikeAStore({ hooks, - store() { - return SessionStorage.create({ - _isFastBoot: false, - }); + store(_sinon, owner) { + owner.register('session-store:session-storage', TestSessionStorage); + return owner.lookup('session-store:session-storage'); }, }); itBehavesLikeAStorageEventHandler({ hooks, - store() { - return SessionStorage.create({ - _isFastBoot: false, - }); + store(_sinon, owner) { + owner.register('session-store:session-storage', TestSessionStorage); + return owner.lookup('session-store:session-storage'); }, }); }); diff --git a/packages/test-esa/tests/unit/session-stores/shared/storage-event-handler-behavior.js b/packages/test-esa/tests/unit/session-stores/shared/storage-event-handler-behavior.js index 44f5f8ee9..6d27fe5ba 100644 --- a/packages/test-esa/tests/unit/session-stores/shared/storage-event-handler-behavior.js +++ b/packages/test-esa/tests/unit/session-stores/shared/storage-event-handler-behavior.js @@ -10,7 +10,6 @@ export default function (options) { hooks.beforeEach(function () { sinon = sinonjs.createSandbox(); - store = options.store(); }); hooks.afterEach(function () { @@ -21,6 +20,7 @@ export default function (options) { hooks.beforeEach(function () { sinon.spy(window, 'addEventListener'); sinon.spy(window, 'removeEventListener'); + store = options.store(sinon, this.owner); }); hooks.afterEach(function () { @@ -29,8 +29,6 @@ export default function (options) { }); test('binds to "storage" events on the window when created', function (assert) { - store = options.store(); - assert.ok(window.addEventListener.calledOnce); });