mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-05-31 14:11:58 +05:30
#188: persist oauth data if if user tries to register during oauth
This commit is contained in:
@@ -33,6 +33,59 @@ describe('AuthFlow', () => {
|
||||
expect(() => flow.actions.test = 'hacked', 'to throw', /readonly/);
|
||||
});
|
||||
|
||||
describe('#setStore', () => {
|
||||
afterEach(() => {
|
||||
localStorage.removeItem('oauthData');
|
||||
});
|
||||
|
||||
it('should create #navigate, #getState, #dispatch', () => {
|
||||
flow.setStore({
|
||||
getState() {},
|
||||
dispatch() {}
|
||||
});
|
||||
|
||||
expect(flow.getState, 'to be defined');
|
||||
expect(flow.dispatch, 'to be defined');
|
||||
expect(flow.navigate, 'to be defined');
|
||||
});
|
||||
|
||||
it('should restore oauth state from localStorage', () => {
|
||||
const oauthData = {};
|
||||
localStorage.setItem('oauthData', JSON.stringify({
|
||||
timestamp: Date.now() - 10,
|
||||
payload: oauthData
|
||||
}));
|
||||
|
||||
sinon.stub(flow, 'run').named('flow.run');
|
||||
|
||||
flow.setStore({
|
||||
getState() {},
|
||||
dispatch() {}
|
||||
});
|
||||
|
||||
expect(flow.run, 'to have a call satisfying', [
|
||||
'oAuthValidate', oauthData
|
||||
]);
|
||||
});
|
||||
|
||||
it('should not restore outdated (>1h) oauth state', () => {
|
||||
const oauthData = {};
|
||||
localStorage.setItem('oauthData', JSON.stringify({
|
||||
timestamp: Date.now() - 60 * 60 * 1000,
|
||||
payload: oauthData
|
||||
}));
|
||||
|
||||
sinon.stub(flow, 'run').named('flow.run');
|
||||
|
||||
flow.setStore({
|
||||
getState() {},
|
||||
dispatch() {}
|
||||
});
|
||||
|
||||
expect(flow.run, 'was not called');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setState', () => {
|
||||
it('should change state', () => {
|
||||
const state = new AbstractState();
|
||||
@@ -198,13 +251,6 @@ describe('AuthFlow', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should run setOAuthRequest if /', () => {
|
||||
flow.handleRequest({path: '/'});
|
||||
|
||||
expect(flow.run, 'was called once');
|
||||
expect(flow.run, 'to have a call satisfying', ['setOAuthRequest', {}]);
|
||||
});
|
||||
|
||||
it('should call callback', () => {
|
||||
const callback = sinon.stub().named('callback');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user