@ministryofjustice/probation-search-frontend
Version:
A shared UI component to search for probation cases from within your Express/Nunjucks application
45 lines • 2.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const url_1 = require("./url");
describe('getAbsoluteUrl', () => {
test.each([
['http', 'example.com', '/path', 'http://example.com/path'],
['https', 'example.com', '/path', 'https://example.com/path'],
['http', 'localhost:3000', '/path?param=value', 'http://localhost:3000/path?param=value'],
])('returns the correct absolute URL for %s://%s%s', (protocol, host, originalUrl, expected) => {
const req = { protocol, originalUrl, get: () => host };
expect((0, url_1.getAbsoluteUrl)(req)).toBe(expected);
});
});
describe('addParameters', () => {
it.each([
['https://example.com', { p1: 'value1' }, 'https://example.com/?p1=value1'],
['https://example.com/path', { p1: 'value1' }, 'https://example.com/path?p1=value1'],
['https://example.com?p1=value1', { p1: 'newValue', p2: 'value2' }, 'https://example.com/?p1=newValue&p2=value2'],
[
'https://example.com?p1%5B%5D=value1',
{ p1: ['1', '2', '3'] },
'https://example.com/?p1%5B%5D=1&p1%5B%5D=2&p1%5B%5D=3',
],
['https://example.com/path?p1=value1', undefined, 'https://example.com/path?p1=value1'],
])('should add parameters to the URL', (url, params, expected) => {
const result = (0, url_1.addParameters)(url, params);
expect(result).toBe(expected);
});
});
describe('removeParameters', () => {
it.each([
[
'https://example.com/?param1=value1¶m2=value2¶m3=value3',
['param1', 'param3'],
'https://example.com/?param2=value2',
],
['https://example.com/?param1=value1', [], 'https://example.com/?param1=value1'],
['https://example.com/?param1=value1', ['param2'], 'https://example.com/?param1=value1'],
['https://example.com/path', ['param1'], 'https://example.com/path'],
])('should remove specified parameters from the URL (%s)', (url, paramsToRemove, expected) => {
const result = (0, url_1.removeParameters)(url, ...paramsToRemove);
expect(result).toBe(expected);
});
});
//# sourceMappingURL=url.test.js.map