-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a23e973
commit 9023b05
Showing
2 changed files
with
288 additions
and
63 deletions.
There are no files selected for viewing
211 changes: 211 additions & 0 deletions
211
packages/eas-cli/src/commands/env/__tests__/EnvironmentVariableList.test.ts
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,211 @@ | ||
import { Config } from '@oclif/core'; | ||
|
||
import { getMockAppFragment } from '../../../__tests__/commands/utils'; | ||
import { ExpoGraphqlClient } from '../../../commandUtils/context/contextUtils/createGraphqlClient'; | ||
import { testProjectId } from '../../../credentials/__tests__/fixtures-constants'; | ||
import { | ||
EnvironmentVariableEnvironment, | ||
EnvironmentVariableFragment, | ||
EnvironmentVariableScope, | ||
EnvironmentVariableVisibility, | ||
} from '../../../graphql/generated'; | ||
import { AppQuery } from '../../../graphql/queries/AppQuery'; | ||
import { EnvironmentVariablesQuery } from '../../../graphql/queries/EnvironmentVariablesQuery'; | ||
import EnvironmentVariableList from '../list'; | ||
import Log from '../../../log'; | ||
|
||
jest.mock('../../../graphql/queries/EnvironmentVariablesQuery'); | ||
jest.mock('../../../graphql/queries/AppQuery'); | ||
jest.mock('../../../log'); | ||
|
||
describe(EnvironmentVariableList, () => { | ||
const graphqlClient = {} as any as ExpoGraphqlClient; | ||
const mockConfig = {} as unknown as Config; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
jest.mocked(AppQuery.byIdAsync).mockImplementation(async () => getMockAppFragment()); | ||
}); | ||
|
||
it('lists project environment variables successfully', async () => { | ||
const mockVariables: EnvironmentVariableFragment[] = [ | ||
{ | ||
id: 'var1', | ||
name: 'TEST_VAR_1', | ||
value: 'value1', | ||
environments: [EnvironmentVariableEnvironment.Production], | ||
scope: EnvironmentVariableScope.Project, | ||
visibility: EnvironmentVariableVisibility.Public, | ||
createdAt: undefined, | ||
updatedAt: undefined, | ||
}, | ||
{ | ||
id: 'var2', | ||
name: 'TEST_VAR_2', | ||
value: 'value2', | ||
environments: [EnvironmentVariableEnvironment.Development], | ||
scope: EnvironmentVariableScope.Project, | ||
visibility: EnvironmentVariableVisibility.Public, | ||
createdAt: undefined, | ||
updatedAt: undefined, | ||
}, | ||
]; | ||
|
||
jest.mocked(EnvironmentVariablesQuery.byAppIdAsync).mockResolvedValueOnce(mockVariables); | ||
|
||
const command = new EnvironmentVariableList([], mockConfig); | ||
|
||
// @ts-expect-error | ||
jest.spyOn(command, 'getContextAsync').mockReturnValue({ | ||
loggedIn: { graphqlClient }, | ||
privateProjectConfig: { projectId: testProjectId }, | ||
}); | ||
await command.runAsync(); | ||
|
||
expect(EnvironmentVariablesQuery.byAppIdAsync).toHaveBeenCalledWith(graphqlClient, { | ||
appId: testProjectId, | ||
environment: undefined, | ||
}); | ||
expect(Log.log).toHaveBeenCalledWith(expect.stringContaining('TEST_VAR_1')); | ||
expect(Log.log).toHaveBeenCalledWith(expect.stringContaining('TEST_VAR_2')); | ||
}); | ||
|
||
it('lists project environment variables including sensitive values', async () => { | ||
const mockVariables: EnvironmentVariableFragment[] = [ | ||
{ | ||
id: 'var1', | ||
name: 'TEST_VAR_1', | ||
value: 'value1', | ||
environments: [EnvironmentVariableEnvironment.Production], | ||
scope: EnvironmentVariableScope.Project, | ||
visibility: EnvironmentVariableVisibility.Public, | ||
createdAt: undefined, | ||
updatedAt: undefined, | ||
}, | ||
{ | ||
id: 'var2', | ||
name: 'TEST_VAR_2', | ||
value: 'value2', | ||
environments: [EnvironmentVariableEnvironment.Development], | ||
scope: EnvironmentVariableScope.Project, | ||
visibility: EnvironmentVariableVisibility.Sensitive, | ||
createdAt: undefined, | ||
updatedAt: undefined, | ||
}, | ||
]; | ||
|
||
jest | ||
.mocked(EnvironmentVariablesQuery.byAppIdWithSensitiveAsync) | ||
.mockResolvedValueOnce(mockVariables); | ||
|
||
const command = new EnvironmentVariableList(['--include-sensitive'], mockConfig); | ||
|
||
// @ts-expect-error | ||
jest.spyOn(command, 'getContextAsync').mockReturnValue({ | ||
loggedIn: { graphqlClient }, | ||
privateProjectConfig: { projectId: testProjectId }, | ||
}); | ||
await command.runAsync(); | ||
|
||
expect(EnvironmentVariablesQuery.byAppIdWithSensitiveAsync).toHaveBeenCalledWith( | ||
graphqlClient, | ||
{ | ||
appId: testProjectId, | ||
environment: undefined, | ||
} | ||
); | ||
expect(Log.log).toHaveBeenCalledWith(expect.stringContaining('TEST_VAR_1')); | ||
expect(Log.log).toHaveBeenCalledWith(expect.stringContaining('TEST_VAR_2')); | ||
}); | ||
|
||
it('lists shared environment variables successfully', async () => { | ||
const mockVariables: EnvironmentVariableFragment[] = [ | ||
{ | ||
id: 'var1', | ||
name: 'TEST_VAR_1', | ||
value: 'value1', | ||
environments: [EnvironmentVariableEnvironment.Production], | ||
scope: EnvironmentVariableScope.Shared, | ||
visibility: EnvironmentVariableVisibility.Public, | ||
createdAt: undefined, | ||
updatedAt: undefined, | ||
}, | ||
{ | ||
id: 'var2', | ||
name: 'TEST_VAR_2', | ||
value: 'value2', | ||
environments: [EnvironmentVariableEnvironment.Development], | ||
scope: EnvironmentVariableScope.Shared, | ||
visibility: EnvironmentVariableVisibility.Public, | ||
createdAt: undefined, | ||
updatedAt: undefined, | ||
}, | ||
]; | ||
|
||
jest.mocked(EnvironmentVariablesQuery.sharedAsync).mockResolvedValueOnce(mockVariables); | ||
|
||
const command = new EnvironmentVariableList(['--scope', 'shared'], mockConfig); | ||
|
||
// @ts-expect-error | ||
jest.spyOn(command, 'getContextAsync').mockReturnValue({ | ||
loggedIn: { graphqlClient }, | ||
privateProjectConfig: { projectId: testProjectId }, | ||
}); | ||
await command.runAsync(); | ||
|
||
expect(EnvironmentVariablesQuery.sharedAsync).toHaveBeenCalledWith(graphqlClient, { | ||
appId: testProjectId, | ||
environment: undefined, | ||
}); | ||
expect(Log.log).toHaveBeenCalledWith(expect.stringContaining('TEST_VAR_1')); | ||
expect(Log.log).toHaveBeenCalledWith(expect.stringContaining('TEST_VAR_2')); | ||
}); | ||
|
||
it('lists shared environment variables including sensitive values', async () => { | ||
const mockVariables: EnvironmentVariableFragment[] = [ | ||
{ | ||
id: 'var1', | ||
name: 'TEST_VAR_1', | ||
value: 'value1', | ||
environments: [EnvironmentVariableEnvironment.Production], | ||
scope: EnvironmentVariableScope.Shared, | ||
visibility: EnvironmentVariableVisibility.Public, | ||
createdAt: undefined, | ||
updatedAt: undefined, | ||
}, | ||
{ | ||
id: 'var2', | ||
name: 'TEST_VAR_2', | ||
value: 'value2', | ||
environments: [EnvironmentVariableEnvironment.Development], | ||
scope: EnvironmentVariableScope.Shared, | ||
visibility: EnvironmentVariableVisibility.Sensitive, | ||
createdAt: undefined, | ||
updatedAt: undefined, | ||
}, | ||
]; | ||
|
||
jest | ||
.mocked(EnvironmentVariablesQuery.sharedWithSensitiveAsync) | ||
.mockResolvedValueOnce(mockVariables); | ||
|
||
const command = new EnvironmentVariableList( | ||
['--include-sensitive', '--scope', 'shared'], | ||
mockConfig | ||
); | ||
|
||
// @ts-expect-error | ||
jest.spyOn(command, 'getContextAsync').mockReturnValue({ | ||
loggedIn: { graphqlClient }, | ||
privateProjectConfig: { projectId: testProjectId }, | ||
}); | ||
await command.runAsync(); | ||
|
||
expect(EnvironmentVariablesQuery.sharedWithSensitiveAsync).toHaveBeenCalledWith(graphqlClient, { | ||
appId: testProjectId, | ||
environment: undefined, | ||
}); | ||
expect(Log.log).toHaveBeenCalledWith(expect.stringContaining('TEST_VAR_1')); | ||
expect(Log.log).toHaveBeenCalledWith(expect.stringContaining('TEST_VAR_2')); | ||
}); | ||
}); |
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