accounts-frontend/packages/app/services/api/options.test.ts

47 lines
1.3 KiB
TypeScript
Raw Normal View History

import expect from 'app/test/unexpected';
import sinon from 'sinon';
import request from 'app/services/request';
import options from './options';
describe('services/api/options', () => {
2020-05-24 04:38:24 +05:30
const expectedResp = {
foo: 'bar',
};
2020-05-24 04:38:24 +05:30
beforeEach(() => {
sinon
.stub(request, 'get')
.named('request.get')
.returns(
Promise.resolve({
originalResponse: new Response(),
...expectedResp,
}),
);
});
2020-05-24 04:38:24 +05:30
afterEach(() => {
(request.get as any).restore();
});
2020-05-24 04:38:24 +05:30
it('should request options without token', () =>
options.get().then((resp) => {
expect(resp, 'to satisfy', {
...expectedResp,
originalResponse: expect.it('to be a', Response),
});
expect(request.get, 'to have a call satisfying', ['/api/options', {}, { token: null }]);
}));
2020-05-24 04:38:24 +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 satisfy', {
...expectedResp,
originalResponse: expect.it('to be a', Response),
});
expect(request.get, 'was not called');
}));
});