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', () => {
|
2020-05-21 23:38:47 +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')
|
2020-01-18 02:07:52 +05:30
|
|
|
.returns(
|
|
|
|
Promise.resolve({
|
|
|
|
originalResponse: new Response(),
|
|
|
|
...expectedResp,
|
|
|
|
}),
|
|
|
|
);
|
2019-11-27 14:33:32 +05:30
|
|
|
});
|
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', () =>
|
2020-05-20 22:05:52 +05:30
|
|
|
options.get().then((resp) => {
|
2020-05-21 23:38:47 +05:30
|
|
|
expect(resp, 'to satisfy', {
|
|
|
|
...expectedResp,
|
|
|
|
originalResponse: expect.it('to be a', Response),
|
|
|
|
});
|
2019-11-27 14:33:32 +05:30
|
|
|
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
|
2020-05-20 22:05:52 +05:30
|
|
|
options.get().then((resp) => {
|
2020-05-21 23:38:47 +05:30
|
|
|
expect(resp, 'to satisfy', {
|
|
|
|
...expectedResp,
|
|
|
|
originalResponse: expect.it('to be a', Response),
|
|
|
|
});
|
2019-11-27 14:33:32 +05:30
|
|
|
expect(request.get, 'was not called');
|
|
|
|
}));
|
2018-02-13 02:26:10 +05:30
|
|
|
});
|