2019-12-08 00:32:00 +05:30
|
|
|
import expect from 'app/test/unexpected';
|
2018-02-13 02:26:10 +05:30
|
|
|
import sinon from 'sinon';
|
2019-12-08 00:32:00 +05:30
|
|
|
import request from 'app/services/request';
|
2018-02-13 02:26:10 +05:30
|
|
|
import options from './options';
|
|
|
|
|
|
|
|
describe('services/api/options', () => {
|
2019-11-27 14:33:32 +05:30
|
|
|
const expectedResp = { foo: 'bar' };
|
2018-02-13 02:26:10 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
sinon
|
|
|
|
.stub(request, 'get')
|
|
|
|
.named('request.get')
|
|
|
|
.returns(Promise.resolve(expectedResp));
|
|
|
|
});
|
2018-02-13 02:26:10 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
afterEach(() => {
|
2019-12-07 16:58:52 +05:30
|
|
|
(request.get as any).restore();
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
2018-02-13 02:26:10 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
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 },
|
|
|
|
]);
|
|
|
|
}));
|
2018-02-13 02:26:10 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
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');
|
|
|
|
}));
|
2018-02-13 02:26:10 +05:30
|
|
|
});
|