accounts-frontend/src/services/api/options.test.ts

38 lines
955 B
TypeScript
Raw Normal View History

import expect from 'test/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(() => {
2019-12-07 16:58:52 +05:30
(request.get as any).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');
}));
});