Skip to content
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

Added argument passing to invalidate method #1093

Merged
merged 6 commits into from
Feb 3, 2017

Conversation

leuprechtroman
Copy link
Contributor

I saw, that the authenticate method passes the arguments into the authenticator. But the invalidate method does not do that. So I simply added the arguments into the method call to enable the same behaviour as seen in the authenticate method.

@marcoow
Copy link
Member

marcoow commented Nov 7, 2016

What's your use case for this? This would also need a test ;)

@leuprechtroman
Copy link
Contributor Author

leuprechtroman commented Nov 7, 2016

I have certain cases in which I know the backend will revoke the session (Platform-Update, etc..) and need to invalidate it on client side without doing a server call. Also you can send additional data on the logout (leaving message) or build advanced logic into the invalidate call.
Last but not least it adds consistent behaviour, since the authenticate() call does argument passing as well.

I'll write tests for this in the next days 👍

hajjem-ayoub pushed a commit to hajjem-ayoub/ember-simple-auth that referenced this pull request Nov 11, 2016
@hajjem-ayoub
Copy link

@leuprechtroman i just did a pull request to your fork with a test case for this feature.

leuprechtroman added a commit to leuprechtroman/ember-simple-auth that referenced this pull request Feb 1, 2017
mainmatter#1093 test related to your update in the invalidate with params
@leuprechtroman
Copy link
Contributor Author

@hajjem-ayoub Thank you so much!

I updated my repo, included the tests and made everything pass the tests.

Copy link
Member

@marcoow marcoow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 🎉, only left a few style-related comments.

@@ -385,7 +385,17 @@ describe('InternalSession', () => {
return session.authenticate('authenticator');
});

describe('when the authenticator resolves invaldiation', () => {
describe('when the authenticator resolves invalidation with params', () => {
it('when some data is sent with invalidate', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test descriptions should always start with a verb actually, e.g. it("passes the params on to the authenticator's invalidate method".

let invalidateSession = sinon.spy(authenticator, 'invalidate');
let param = { some: 'random data' };
session.invalidate(param);
invalidateSession.restore();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll always want to set up spies (and especially restore the original methods) in beforeEach/afterEach hooks so you can be sure spies will always be cleaned up reliably, even if an exception is thrown in the test case.

let param = { some: 'random data' };
session.invalidate(param);
invalidateSession.restore();
sinon.assert.calledWith(invalidateSession, session.get('authenticated'), param);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESA generally uses chai (and sinon-chai) for assertions, e.g. in this case:

expect(authenticator.invalidate).to.have.been.calledWith(session.get('authenticated'), param);

@leuprechtroman
Copy link
Contributor Author

Thanks for your feedback, I've adapted everything according to it!

@@ -385,7 +385,25 @@ describe('InternalSession', () => {
return session.authenticate('authenticator');
});

describe('when the authenticator resolves invaldiation', () => {
describe('when the authenticator resolves invalidation with params', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, oversaw that: this is the wrong text actually. This block is not actually about the authenticator resolving or rejecting, instead you'd want something like describe('when arguments are passed', () => {.

@marcoow marcoow added this to the 1.3 milestone Feb 3, 2017
@marcoow marcoow merged commit 5e755b2 into mainmatter:master Feb 3, 2017
@marcoow marcoow modified the milestones: 1.3, 1.2.1 Mar 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants