accounts-frontend/packages/app/components/ui/bsod/BsodMiddleware.test.ts

50 lines
1.3 KiB
TypeScript
Raw Normal View History

import expect from 'app/test/unexpected';
2017-02-22 20:33:15 +02:00
import sinon from 'sinon';
import BsodMiddleware from 'app/components/ui/bsod/BsodMiddleware';
2017-02-22 20:33:15 +02:00
describe('BsodMiddleware', () => {
[500, 503, 555].forEach((code) =>
it(`should dispatch for ${code}`, () => {
const resp = {
originalResponse: { status: code },
};
2019-12-07 13:28:52 +02:00
const dispatchBsod = sinon.spy();
const logger = { warn: sinon.spy() };
2019-12-07 13:28:52 +02:00
const middleware = new BsodMiddleware(dispatchBsod, logger as any);
return expect(middleware.catch(resp), 'to be rejected with', resp).then(
() => {
2019-12-07 13:28:52 +02:00
expect(dispatchBsod, 'was called');
expect(logger.warn, 'to have a call satisfying', [
'Unexpected response (BSoD)',
{ resp },
]);
},
);
}),
);
[200, 404].forEach((code) =>
it(`should not dispatch for ${code}`, () => {
const resp = {
originalResponse: { status: code },
};
2019-12-07 13:28:52 +02:00
const dispatchBsod = sinon.spy();
const logger = { warn: sinon.spy() };
2019-12-07 13:28:52 +02:00
const middleware = new BsodMiddleware(dispatchBsod, logger as any);
return expect(middleware.catch(resp), 'to be rejected with', resp).then(
() => {
2019-12-07 13:28:52 +02:00
expect(dispatchBsod, 'was not called');
expect(logger.warn, 'was not called');
},
);
}),
);
2017-02-22 20:33:15 +02:00
});