2019-12-08 00:32:00 +05:30
|
|
|
import expect from 'app/test/unexpected';
|
2017-02-23 00:03:15 +05:30
|
|
|
import sinon from 'sinon';
|
|
|
|
|
2019-12-08 00:32:00 +05:30
|
|
|
import BsodMiddleware from 'app/components/ui/bsod/BsodMiddleware';
|
2017-02-23 00:03:15 +05:30
|
|
|
|
|
|
|
describe('BsodMiddleware', () => {
|
2019-11-27 14:33:32 +05:30
|
|
|
[500, 503, 555].forEach(code =>
|
|
|
|
it(`should dispatch for ${code}`, () => {
|
|
|
|
const resp = {
|
|
|
|
originalResponse: { status: code },
|
|
|
|
};
|
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
const dispatchBsod = sinon.spy();
|
2019-11-27 14:33:32 +05:30
|
|
|
const logger = { warn: sinon.spy() };
|
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
const middleware = new BsodMiddleware(dispatchBsod, logger as any);
|
2019-11-27 14:33:32 +05:30
|
|
|
|
|
|
|
return expect(middleware.catch(resp), 'to be rejected with', resp).then(
|
|
|
|
() => {
|
2019-12-07 16:58:52 +05:30
|
|
|
expect(dispatchBsod, 'was called');
|
2019-11-27 14:33:32 +05:30
|
|
|
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 16:58:52 +05:30
|
|
|
const dispatchBsod = sinon.spy();
|
2019-11-27 14:33:32 +05:30
|
|
|
const logger = { warn: sinon.spy() };
|
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
const middleware = new BsodMiddleware(dispatchBsod, logger as any);
|
2019-11-27 14:33:32 +05:30
|
|
|
|
|
|
|
return expect(middleware.catch(resp), 'to be rejected with', resp).then(
|
|
|
|
() => {
|
2019-12-07 16:58:52 +05:30
|
|
|
expect(dispatchBsod, 'was not called');
|
2019-11-27 14:33:32 +05:30
|
|
|
expect(logger.warn, 'was not called');
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
2017-02-23 00:03:15 +05:30
|
|
|
});
|