Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpdl-bloxberg
certify-verifier-js
Commits
59585bd5
Unverified
Commit
59585bd5
authored
Sep 04, 2020
by
Matthieu COLLÉ
Browse files
refactor(UrlHelpers): [#715] created safelyAppendUrlParameter method
parent
87ce7649
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/helpers/url.ts
0 → 100644
View file @
59585bd5
export
function
safelyAppendUrlParameter
(
url
:
string
,
parameterKey
:
string
,
parameterValue
:
string
):
string
{
const
separator
=
url
.
includes
(
'
?
'
)
?
'
&
'
:
'
?
'
;
return
`
${
url
}${
separator
}${
parameterKey
}
=
${
parameterValue
}
`
;
}
test/application/helpers/url.test.ts
0 → 100644
View file @
59585bd5
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
);
});
});
});
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment