This repository has been archived by the owner on Aug 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial buildLink helper 🐿 v2.9.0 * add unit tests 🐿 v2.9.0 * bump circle testing to node 8 🐿 v2.9.0 * add default param 🐿 v2.9.0
- Loading branch information
Showing
5 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
machine: | ||
node: | ||
version: 6.11.0 | ||
version: 8.11.3 | ||
|
||
deployment: | ||
release: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { URL } = require('url'); | ||
|
||
module.exports = function (url, queryParams = {}) { | ||
if (!url) return ''; | ||
const urlObject = new URL(url); | ||
Object.keys(queryParams).forEach(key => { | ||
urlObject.searchParams.set(key, queryParams[key]); | ||
}); | ||
return urlObject.href; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { expect } = require('chai'); | ||
const buildLink = require('../src/helpers/buildLink'); | ||
|
||
describe('Build Link Helper', () => { | ||
|
||
const url = 'https://ft.com/somePath'; | ||
const queryParams = { | ||
cpccampaign: 'test', | ||
something: 'else' | ||
}; | ||
|
||
it('should correctly generate links', () => { | ||
expect(buildLink(url, queryParams)).to.equal('https://ft.com/somePath?cpccampaign=test&something=else'); | ||
}); | ||
|
||
it('should return an empty string if no URL specified', () => { | ||
expect(buildLink()).to.equal(''); | ||
}); | ||
|
||
it('should not break if no query params are passed', () => { | ||
expect(buildLink(url)).to.equal(url); | ||
}); | ||
|
||
it('should not duplicate query params', () => { | ||
const urlWithParam = `${url}?something=new`; | ||
expect(buildLink(urlWithParam, queryParams)).to.equal('https://ft.com/somePath?something=else&cpccampaign=test'); | ||
}); | ||
}); |