Unverified Commit 59585bd5 authored by Matthieu COLLÉ's avatar Matthieu COLLÉ
Browse files

refactor(UrlHelpers): [#715] created safelyAppendUrlParameter method

parent 87ce7649
export function safelyAppendUrlParameter (url: string, parameterKey: string, parameterValue: string): string {
const separator = url.includes('?') ? '&' : '?';
return `${url}${separator}${parameterKey}=${parameterValue}`;
}
import { safelyAppendUrlParameter } from '../../../src/helpers/url';
describe('safelyAppendUrlParameter method', function () {
let fixtureUrl: string;
const fixtureParameterKey = 'parameterKey';
const fixtureParameterValue = 'parameterValue';
describe('given the url already has parameter', function () {
it('should return the url with the parameter correctly appended', function () {
fixtureUrl = 'https://www.domain.tld/path/to/page?key=value';
const assertionURL = `${fixtureUrl}&${fixtureParameterKey}=${fixtureParameterValue}`;
expect(safelyAppendUrlParameter(fixtureUrl, fixtureParameterKey, fixtureParameterValue))
.toEqual(assertionURL);
});
});
describe('given the url does not already have parameter', function () {
it('should return the url with the parameter correctly appended', function () {
fixtureUrl = 'https://www.domain.tld/path/to/page';
const assertionURL = `${fixtureUrl}?${fixtureParameterKey}=${fixtureParameterValue}`;
expect(safelyAppendUrlParameter(fixtureUrl, fixtureParameterKey, fixtureParameterValue))
.toEqual(assertionURL);
});
});
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment