@pact-foundation/pact
Version:
Pact for all things Javascript
56 lines • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const vitest_1 = require("vitest");
const stateHandler_1 = require("./stateHandler");
describe('#createProxyStateHandler', () => {
const state = {
state: 'thing exists',
action: 'setup',
};
let res;
const mockResponse = {
status: (status) => {
res = status;
return {
send: () => { },
};
},
json: (data) => data,
};
afterEach(() => {
vitest_1.vi.restoreAllMocks();
});
describe('when valid state handlers are provided', () => {
it('returns a 200', async () => {
const stateHandlers = {
'thing exists': () => Promise.resolve(),
};
const h = (0, stateHandler_1.createProxyStateHandler)({
stateHandlers,
});
await h({
body: state,
}, mockResponse);
});
});
describe('when there is a problem with a state handler', () => {
const badStateHandlers = {
'thing exists': {
setup: () => Promise.reject(new Error('bad')),
},
};
it('returns a 200 and logs an error', async () => {
const spy = vitest_1.vi.spyOn(console, 'log');
const h = (0, stateHandler_1.createProxyStateHandler)({
stateHandlers: badStateHandlers,
});
await h({
body: state,
}, mockResponse);
expect(res).toBe(200);
expect(spy).toHaveBeenCalledTimes(3);
expect(spy.mock.calls[0][0]).toContain("Error executing state handler for state 'thing exists' on 'setup'.");
});
});
});
//# sourceMappingURL=stateHandler.spec.js.map