-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UXE-4356] feat: add secrets segment variables in the workflows (#1597)
- Loading branch information
Showing
9 changed files
with
70 additions
and
49 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
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
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,13 @@ | ||
function makeSegmentToken() { | ||
const segmentToken = import.meta.env['VITE_SEGMENT_TOKEN'] | ||
|
||
if (!segmentToken) { | ||
// eslint-disable-next-line no-console | ||
console.warn('Segment token is missing') | ||
return | ||
} | ||
|
||
return segmentToken | ||
} | ||
|
||
export { makeSegmentToken } |
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
36 changes: 36 additions & 0 deletions
36
src/tests/plugins/factories/segment-handler-token-factory.test.js
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,36 @@ | ||
import { describe, it, expect, vi, afterEach } from 'vitest' | ||
import { makeSegmentToken } from '@/plugins/factories/segment-handler-token-factory' | ||
|
||
afterEach(() => { | ||
vi.unstubAllEnvs() | ||
vi.unstubAllGlobals() | ||
}) | ||
|
||
describe('makeSegmentToken', () => { | ||
it('should return the production token if environment is production', () => { | ||
vi.stubEnv('VITE_SEGMENT_TOKEN', 'prod_token_value') | ||
const result = makeSegmentToken() | ||
|
||
expect(result).toBe('prod_token_value') | ||
}) | ||
|
||
it('should return the stage token if environment is not production', () => { | ||
vi.stubEnv('VITE_SEGMENT_TOKEN', 'stage_token_value') | ||
|
||
const result = makeSegmentToken() | ||
|
||
expect(result).toBe('stage_token_value') | ||
}) | ||
|
||
it('should warn and return an empty string if the token is missing', () => { | ||
const warnMock = vi.spyOn(console, 'warn').mockImplementation(() => {}) | ||
vi.stubEnv('VITE_SEGMENT_TOKEN', '') | ||
|
||
const result = makeSegmentToken() | ||
|
||
expect(warnMock).toHaveBeenCalledWith('Segment token is missing') | ||
expect(result).toBeUndefined() | ||
|
||
warnMock.mockRestore() | ||
}) | ||
}) |