This repository has been archived by the owner on Jul 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #592 from Shopify/add-email-env
Add SLATE_USER_EMAIL env variable for slate-analytics
- Loading branch information
Showing
8 changed files
with
86 additions
and
9 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,3 +1,5 @@ | ||
/* eslint-disable no-process-env */ | ||
|
||
jest.mock('../prompt'); | ||
jest.mock('axios'); | ||
|
||
|
@@ -100,6 +102,24 @@ describe('init()', () => { | |
expect(config.trackingVersion).toBe(packageJson.trackingVersion); | ||
}); | ||
}); | ||
|
||
describe('skips prompting new user for tracking consent', () => { | ||
test('if SLATE_USER_EMAIL environment variable is set to a valid email', async () => { | ||
const analytics = require('../index'); | ||
const prompt = require('../prompt'); | ||
const mock = require('mock-fs'); | ||
|
||
process.env.SLATE_USER_EMAIL = '[email protected]'; | ||
|
||
mock(); | ||
|
||
await analytics.init(); | ||
|
||
expect(prompt.forNewConsent).not.toHaveBeenCalled(); | ||
|
||
delete process.env.SLATE_USER_EMAIL; | ||
}); | ||
}); | ||
}); | ||
|
||
describe('event()', () => { | ||
|
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
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,6 @@ | ||
module.exports = { | ||
validateEmail(input) { | ||
const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; | ||
return re.test(String(input).toLowerCase()); | ||
}, | ||
}; |
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ const TEST_ENV = { | |
[config.envPasswordVar]: '123456789', | ||
[config.envThemeIdVar]: '987654321', | ||
[config.envIgnoreFilesVar]: 'config/settings_data.json', | ||
[config.envUserEmail]: '[email protected]', | ||
}; | ||
|
||
function setVars(vars) { | ||
|
@@ -64,6 +65,19 @@ describe('Slate Env', () => { | |
}); | ||
}); | ||
|
||
describe('getDefaultSlateEnv', () => { | ||
test('returns an object which contains the default variables and values of an env file', () => { | ||
const emptyTestVars = { | ||
[config.envStoreVar]: '', | ||
[config.envPasswordVar]: '', | ||
[config.envThemeIdVar]: '', | ||
[config.envIgnoreFilesVar]: '', | ||
}; | ||
|
||
expect(slateEnv.getDefaultSlateEnv()).toEqual(emptyTestVars); | ||
}); | ||
}); | ||
|
||
describe('getEmptySlateEnv()', () => { | ||
test('returns object containing all env file variables with empty values', () => { | ||
const emptyTestVars = Object.assign({}, TEST_ENV); | ||
|
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