-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make HUBAPI_DOMAIN_OVERRIDE environment independent (#50)
Reworks getHubSpotApiOrigin to append the environment suffix to a passed environment variable HUBAPI_DOMAIN_OVERRIDE. This makes the override independent to environments. You can no longer mistakenly pass a domain override which conflicts with the environment of the account. It also lets you "set and forget" the HUBAPI_DOMAIN_OVERRIDE variable in your shell settings, say in .zshrc, and it will work as expected in all cases. Adds tests for urls.js to test the normal cases, as well as tests for the override behavior.
- Loading branch information
1 parent
b992345
commit 8ccb1e5
Showing
2 changed files
with
66 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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const { getHubSpotApiOrigin } = require('../urls'); | ||
|
||
describe('urls', () => { | ||
describe('getHubSpotApiOrigin()', () => { | ||
// Suggestion taken from stack overflow https://stackoverflow.com/a/48042799 | ||
const OLD_ENV = process.env; | ||
|
||
beforeEach(() => { | ||
process.env = { ...OLD_ENV }; | ||
}); | ||
|
||
afterAll(() => { | ||
process.env = OLD_ENV; | ||
}); | ||
|
||
it('gets qa url', () => { | ||
const url = getHubSpotApiOrigin('qa', false); | ||
|
||
expect(url).toBe('https://api.hubapiqa.com'); | ||
}); | ||
|
||
it('gets prod url', () => { | ||
const url = getHubSpotApiOrigin('prod', false); | ||
|
||
expect(url).toBe('https://api.hubapi.com'); | ||
}); | ||
|
||
it('gets qa local url', () => { | ||
const url = getHubSpotApiOrigin('qa', true); | ||
|
||
expect(url).toBe('https://local.hubapiqa.com'); | ||
}); | ||
|
||
it('gets prod local url', () => { | ||
const url = getHubSpotApiOrigin('prod', true); | ||
|
||
expect(url).toBe('https://local.hubapi.com'); | ||
}); | ||
|
||
it('gets qa override url', () => { | ||
process.env.HUBAPI_DOMAIN_OVERRIDE = 'api.hubspot'; | ||
const url = getHubSpotApiOrigin('qa', false); | ||
|
||
expect(url).toBe('https://api.hubspotqa.com'); | ||
}); | ||
|
||
it('gets prod override url', () => { | ||
process.env.HUBAPI_DOMAIN_OVERRIDE = 'api.hubspot'; | ||
const url = getHubSpotApiOrigin('prod', false); | ||
|
||
expect(url).toBe('https://api.hubspot.com'); | ||
}); | ||
|
||
it('ignores local argument when using override', () => { | ||
process.env.HUBAPI_DOMAIN_OVERRIDE = 'api.hubspot'; | ||
const url = getHubSpotApiOrigin('qa', true); | ||
|
||
expect(url).toBe('https://api.hubspotqa.com'); | ||
}); | ||
}); | ||
}); |
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