accounts-frontend/src/components/ui/bsod/BsodMiddleware.test.js

48 lines
1.5 KiB
JavaScript
Raw Normal View History

import expect from 'test/unexpected';
2017-02-23 00:03:15 +05:30
import sinon from 'sinon';
import BsodMiddleware from 'components/ui/bsod/BsodMiddleware';
describe('BsodMiddleware', () => {
2018-05-03 00:38:31 +05:30
[500, 503, 555].forEach((code) =>
2017-02-23 00:03:15 +05:30
it(`should dispatch for ${code}`, () => {
const resp = {
originalResponse: {status: code}
};
const dispatch = sinon.spy();
const logger = {warn: sinon.spy()};
const middleware = new BsodMiddleware(dispatch, logger);
return expect(middleware.catch(resp), 'to be rejected with', resp)
.then(() => {
expect(dispatch, 'was called');
expect(logger.warn, 'to have a call satisfying', [
'Unexpected response (BSoD)',
2017-02-23 00:03:15 +05:30
{resp}
]);
});
})
);
2018-05-03 00:38:31 +05:30
[200, 404].forEach((code) =>
it(`should not dispatch for ${code}`, () => {
const resp = {
originalResponse: {status: code}
};
2017-02-23 00:03:15 +05:30
2018-05-03 00:38:31 +05:30
const dispatch = sinon.spy();
const logger = {warn: sinon.spy()};
2017-02-23 00:03:15 +05:30
2018-05-03 00:38:31 +05:30
const middleware = new BsodMiddleware(dispatch, logger);
2017-02-23 00:03:15 +05:30
2018-05-03 00:38:31 +05:30
return expect(middleware.catch(resp), 'to be rejected with', resp)
.then(() => {
expect(dispatch, 'was not called');
expect(logger.warn, 'was not called');
});
})
);
2017-02-23 00:03:15 +05:30
});