UNPKG

@pact-foundation/pact

Version:
70 lines 2.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const ffi_1 = require("./ffi"); describe('Pact FFI', () => { describe('#contentTypeFromHeaders', () => { ['content-type', 'Content-Type', 'CONTent-TYPE'].forEach((t) => { describe(`when the "${t}" header is set`, () => { it('detects the content type from the header', () => { const headers = { [t]: 'some-mime-type' }; expect((0, ffi_1.contentTypeFromHeaders)(headers, 'application/json')).toBe('some-mime-type'); }); }); }); describe(`when the no content-type header is set`, () => { it('uses a default', () => { expect((0, ffi_1.contentTypeFromHeaders)({}, 'application/json')).toBe('application/json'); }); }); }); describe('#setQuery', () => { describe('with array values', () => { it('calls the query ffi function for each value', () => { const queryMock = vitest_1.vi.fn(); const interaction = { withQuery: queryMock, }; const query = { foo: ['bar', 'baz'], }; (0, ffi_1.setQuery)(interaction, query); expect(queryMock).toHaveBeenCalledTimes(2); expect(queryMock).toHaveBeenCalledWith('foo', 0, 'bar'); expect(queryMock).toHaveBeenCalledWith('foo', 1, 'baz'); }); }); describe('with single values', () => { it('calls the query ffi function for each value', () => { const queryMock = vitest_1.vi.fn(); const interaction = { withQuery: queryMock, }; const query = { foo: 'bar', }; (0, ffi_1.setQuery)(interaction, query); expect(queryMock).toHaveBeenCalledOnce(); expect(queryMock).toHaveBeenCalledWith('foo', 0, 'bar'); }); }); describe('with array and single values', () => { it('calls the query ffi function for each value', () => { const queryMock = vitest_1.vi.fn(); const interaction = { withQuery: queryMock, }; const query = { foo: 'bar', baz: ['bat', 'foo'], }; (0, ffi_1.setQuery)(interaction, query); expect(queryMock).toHaveBeenCalledTimes(3); expect(queryMock).toHaveBeenCalledWith('foo', 0, 'bar'); expect(queryMock).toHaveBeenCalledWith('baz', 0, 'bat'); expect(queryMock).toHaveBeenCalledWith('baz', 1, 'foo'); }); }); }); }); //# sourceMappingURL=ffi.spec.js.map