mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-11-30 10:42:34 +05:30
#389: do not send token with /api/options request
This commit is contained in:
parent
1bfcb17ae4
commit
6135fea66c
@ -1,14 +1,15 @@
|
||||
// @flow
|
||||
import request from 'services/request';
|
||||
|
||||
let options;
|
||||
|
||||
export default {
|
||||
get() {
|
||||
get(): Promise<{ reCaptchaPublicKey: string }> {
|
||||
if (options) {
|
||||
return Promise.resolve(options);
|
||||
}
|
||||
|
||||
return request.get('/api/options').then((resp) => {
|
||||
return request.get('/api/options', {}, { token: null }).then((resp) => {
|
||||
options = resp;
|
||||
|
||||
return resp;
|
||||
|
38
src/services/api/options.test.js
Normal file
38
src/services/api/options.test.js
Normal file
@ -0,0 +1,38 @@
|
||||
import expect from 'unexpected';
|
||||
import sinon from 'sinon';
|
||||
import request from 'services/request';
|
||||
import options from './options';
|
||||
|
||||
describe('services/api/options', () => {
|
||||
const expectedResp = {foo: 'bar'};
|
||||
|
||||
beforeEach(() => {
|
||||
sinon.stub(request, 'get')
|
||||
.named('request.get')
|
||||
.returns(Promise.resolve(expectedResp));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
request.get.restore();
|
||||
});
|
||||
|
||||
it('should request options without token', () =>
|
||||
options.get().then((resp) => {
|
||||
expect(resp, 'to be', expectedResp);
|
||||
expect(request.get, 'to have a call satisfying', [
|
||||
'/api/options',
|
||||
{},
|
||||
{ token: null }
|
||||
]);
|
||||
})
|
||||
);
|
||||
|
||||
it('should cache options', () =>
|
||||
// NOTE: this is bad practice, but we are relying on the state from
|
||||
// the previous test
|
||||
options.get().then((resp) => {
|
||||
expect(resp, 'to be', expectedResp);
|
||||
expect(request.get, 'was not called');
|
||||
})
|
||||
);
|
||||
});
|
Loading…
Reference in New Issue
Block a user