-
Notifications
You must be signed in to change notification settings - Fork 604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2308] Refactor Adaptive store to use DI #2312
[2308] Refactor Adaptive store to use DI #2312
Conversation
56c6516
to
d753b58
Compare
c4ae621
to
d753b58
Compare
d753b58
to
50b1f2b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work – this is one of the messiest parts of the codebase 🙌
@@ -53,6 +57,8 @@ export default Base.extend({ | |||
*/ | |||
localStorageKey: 'ember_simple_auth-session', | |||
|
|||
localStorage: injectStore('local-storage'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be set in init
instead?
this.localStorage = getOwner(this).lookup(`session-store:local-storage`);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, yes 👍
_cookies: service('cookies'), | ||
cookie: injectStore('cookie'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above
|
||
store = this._createStore(Cookie, options); | ||
store._initialize(options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
store._initialize(options); | |
store.setProperties(options); |
not work here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could check that out, although _initalize
currently needs to treat the cookieName
property in a special way.
The proxy properties that were receiving some default values on initialization weren't causing any issues before, but right now since we can't really pass any properties during init, but we set them after instead - its causing e.g cookieName
to be cached with a wrong value.
sinon.spy(cookieService, 'read'); | ||
sinon.spy(cookieService, 'write'); | ||
store = createAdaptiveStore(cookieService, { | ||
_isLocal: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to exist anywhere actually? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's true, I will remove it, also noticed that some of the _isFastBoot
properties were miswritten, we have _isFastBoot
and _isFastboot
currently somewhere i believe.
@@ -311,7 +302,8 @@ export default function(options) { | |||
); | |||
}); | |||
|
|||
it('clears cached expiration times when setting expiration to null', function() { | |||
// eslint-disable-next-line require-await | |||
it('clears cached expiration times when setting expiration to null', async function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this async
in fact necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, otherwise the mocha test is failing, it's throwing some error saying done() wasn't called after the test finished
and it's failing because of that. The test works correctly, the expectations inside in fact are working, though for some reason I wasn't able to debunk why the test has to be async.
It started happening after I've used setupTest
, so I believe that it's the cause.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like we're working around something – this test itself has nothing asynchronous. We should look into this a bit closer – happy to pair on it next week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK 👍
I was able to remove it from one of the places, I figured that it was caused by beforeEach calling an async method on store.
Though can't find the cause for the other one so far, although I wouldn't be surprised if it actually be caused by mocha setupTest
which expects the hook callback to be thenable
https://github.com/emberjs/ember-mocha/blob/master/addon-test-support/ember-mocha/setup-test.js#L21
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's figure out how we can fix this one as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, for now I've removed the eslint disable line, so it fails PR until it's fixed.
}); | ||
|
||
it('restores expiration time from cookie', function() { | ||
// eslint-disable-next-line require-await | ||
it('restores expiration time from cookie', async function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this async
necessary? There's nothing asynchronous going on in the test?
localStorage.setProperties(options); | ||
|
||
store = localStorage; | ||
this.localStorage = localStorage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I was under the impression that we want to expose the services as properties as well.
I'll remove that next time.
store = this._createStore(Cookie, options); | ||
this.set('cookieExpirationTime', store.get('cookieExpirationTime')); | ||
store = cookieStorage; | ||
this.cookieStorage = cookieStorage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used anywhere?
@@ -311,7 +302,8 @@ export default function(options) { | |||
); | |||
}); | |||
|
|||
it('clears cached expiration times when setting expiration to null', function() { | |||
// eslint-disable-next-line require-await | |||
it('clears cached expiration times when setting expiration to null', async function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's figure out how we can fix this one as well.
a942305
to
d976a4d
Compare
setupTest
so there's access to ember's containersetupTest
is that it seems to require the test to be asynchronous, so all test functions are marked asasync
so they return a promise implicitly_initialize
method that handles setting of properties that would normally be provided during creation of CookieStore instance.cookieName
property to_cookieName
in some tests because using 'non private' property would override the underlying computed property which acts as a proxy, because of this behaviour, the private 'default' values are changed and not the public ones.closes #2308