#48: fix the bug, whent account.current was requested without disabling refreshToken middleware

This commit is contained in:
SleepWalker
2016-11-08 08:30:53 +02:00
parent 0d8696b4f7
commit a2afac867a
7 changed files with 35 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
import expect from 'unexpected';
import accounts from 'services/api/accounts';
import authentication from 'services/api/authentication';
import { authenticate, revoke, add, activate, remove, ADD, REMOVE, ACTIVATE } from 'components/accounts/actions';
import { SET_LOCALE } from 'components/i18n/actions';
@@ -36,11 +37,18 @@ describe('Accounts actions', () => {
user: {}
});
sinon.stub(authentication, 'validateToken').named('authentication.validateToken');
authentication.validateToken.returns(Promise.resolve({
token: account.token,
refreshToken: account.refreshToken
}));
sinon.stub(accounts, 'current').named('accounts.current');
accounts.current.returns(Promise.resolve(user));
});
afterEach(() => {
authentication.validateToken.restore();
accounts.current.restore();
});

View File

@@ -76,10 +76,10 @@ describe('refreshTokenMiddleware', () => {
expect(authentication.requestToken, 'was not called');
});
it('should not apply if options.autoRefreshToken === false', () => {
it('should not auto refresh token if options.token specified', () => {
const data = {
url: 'foo',
options: {autoRefreshToken: false}
options: {token: 'foo'}
};
middleware.before(data);
@@ -257,10 +257,10 @@ describe('refreshTokenMiddleware', () => {
)
);
it('should pass the request through if options.autoRefreshToken === false', () => {
it('should pass the request through if options.token specified', () => {
const promise = middleware.catch(expiredResponse, {
options: {
autoRefreshToken: false
token: 'foo'
}
}, restart);

View File

@@ -21,7 +21,7 @@ describe('authentication api', () => {
expect(authentication.validateToken(validTokens), 'to be fulfilled')
.then(() => {
expect(accounts.current, 'to have a call satisfying', [
{token: 'foo', autoRefreshToken: false}
{token: 'foo'}
]);
})
);