Ignore token for some guest-specific requests

This commit is contained in:
SleepWalker 2016-12-25 20:09:47 +02:00
parent 4888b37047
commit 2301aff3d5
4 changed files with 111 additions and 3 deletions

View File

@ -9,7 +9,8 @@ const authentication = {
}) { }) {
return request.post( return request.post(
'/api/authentication/login', '/api/authentication/login',
{login, password, rememberMe} {login, password, rememberMe},
{token: null}
); );
}, },

View File

@ -12,14 +12,16 @@ export default {
}) { }) {
return request.post( return request.post(
'/api/signup', '/api/signup',
{email, username, password, rePassword, rulesAgreement, lang, captcha} {email, username, password, rePassword, rulesAgreement, lang, captcha},
{token: null}
); );
}, },
activate({key = ''}) { activate({key = ''}) {
return request.post( return request.post(
'/api/signup/confirm', '/api/signup/confirm',
{key} {key},
{token: null}
); );
}, },

View File

@ -0,0 +1,73 @@
import expect from 'unexpected';
import sinon from 'sinon';
import request from 'services/request';
import signup from 'services/api/signup';
describe('signup api', () => {
describe('#register', () => {
const params = {
email: 'email',
username: 'username',
password: 'password',
rePassword: 'rePassword',
rulesAgreement: false,
lang: 'lang',
captcha: 'captcha'
};
beforeEach(() => {
sinon.stub(request, 'post').named('request.post');
});
afterEach(() => {
request.post.restore();
});
it('should post to register api', () => {
signup.register(params);
expect(request.post, 'to have a call satisfying', [
'/api/signup', params, {}
]);
});
it('should disable any token', () => {
signup.register(params);
expect(request.post, 'to have a call satisfying', [
'/api/signup', params, {token: null}
]);
});
});
describe('#activate', () => {
const params = {
key: 'key'
};
beforeEach(() => {
sinon.stub(request, 'post').named('request.post');
});
afterEach(() => {
request.post.restore();
});
it('should post to confirmation api', () => {
signup.activate(params);
expect(request.post, 'to have a call satisfying', [
'/api/signup/confirm', params, {}
]);
});
it('should disable any token', () => {
signup.activate(params);
expect(request.post, 'to have a call satisfying', [
'/api/signup/confirm', params, {token: null}
]);
});
});
});

View File

@ -6,6 +6,38 @@ import authentication from 'services/api/authentication';
import accounts from 'services/api/accounts'; import accounts from 'services/api/accounts';
describe('authentication api', () => { describe('authentication api', () => {
describe('#login', () => {
const params = {
login: 'foo',
password: 'secret',
rememberMe: false
};
beforeEach(() => {
sinon.stub(request, 'post').named('request.post');
});
afterEach(() => {
request.post.restore();
});
it('should post to login api', () => {
authentication.login(params);
expect(request.post, 'to have a call satisfying', [
'/api/authentication/login', params, {}
]);
});
it('should disable any token', () => {
authentication.login(params);
expect(request.post, 'to have a call satisfying', [
'/api/authentication/login', params, {token: null}
]);
});
});
describe('#validateToken()', () => { describe('#validateToken()', () => {
const validTokens = {token: 'foo', refreshToken: 'bar'}; const validTokens = {token: 'foo', refreshToken: 'bar'};