-
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
6d52cf8
commit 73b3a43
Showing
4 changed files
with
166 additions
and
33 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
109 changes: 109 additions & 0 deletions
109
packages/eas-cli/src/commands/env/__tests__/EnvironmentVariableGet.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,109 @@ | ||
import { Config } from '@oclif/core'; | ||
|
||
import { ExpoGraphqlClient } from '../../../commandUtils/context/contextUtils/createGraphqlClient'; | ||
import { testProjectId } from '../../../credentials/__tests__/fixtures-constants'; | ||
import { | ||
EnvironmentVariableEnvironment, | ||
EnvironmentVariableScope, | ||
EnvironmentVariableVisibility, | ||
} from '../../../graphql/generated'; | ||
import { EnvironmentVariablesQuery } from '../../../graphql/queries/EnvironmentVariablesQuery'; | ||
import Log from '../../../log'; | ||
import { promptVariableEnvironmentAsync, promptVariableNameAsync } from '../../../utils/prompts'; | ||
import EnvironmentVariableGet from '../get'; | ||
|
||
jest.mock('../../../graphql/mutations/EnvironmentVariableMutation'); | ||
jest.mock('../../../graphql/queries/AppQuery'); | ||
jest.mock('../../../graphql/queries/EnvironmentVariablesQuery'); | ||
jest.mock('../../../utils/prompts'); | ||
|
||
describe(EnvironmentVariableGet, () => { | ||
const graphqlClient = {} as any as ExpoGraphqlClient; | ||
const mockConfig = {} as unknown as Config; | ||
const mockVariables = [ | ||
{ | ||
id: 'var1', | ||
name: 'TEST_VAR_1', | ||
value: 'value1', | ||
environments: [EnvironmentVariableEnvironment.Production], | ||
createdAt: new Date().toISOString(), | ||
updatedAt: new Date().toISOString(), | ||
scope: EnvironmentVariableScope.Project, | ||
visibility: EnvironmentVariableVisibility.Public, | ||
}, | ||
]; | ||
|
||
it('retrieves environment variables successfully', async () => { | ||
jest | ||
.mocked(EnvironmentVariablesQuery.byAppIdWithSensitiveAsync) | ||
.mockResolvedValueOnce(mockVariables); | ||
jest.spyOn(Log, 'log').mockImplementation(() => {}); | ||
|
||
const command = new EnvironmentVariableGet(['--variable-name', 'TEST_VAR_1'], 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, | ||
filterNames: ['TEST_VAR_1'], | ||
} | ||
); | ||
expect(Log.log).toHaveBeenCalledWith(expect.stringContaining('TEST_VAR_1')); | ||
}); | ||
|
||
it('handles errors during retrieval', async () => { | ||
const errorMessage = | ||
"Variable name is required. Run the command with '--variable-name VARIABLE_NAME' flag"; | ||
|
||
const command = new EnvironmentVariableGet([], mockConfig); | ||
|
||
// @ts-expect-error | ||
jest.spyOn(command, 'getContextAsync').mockReturnValue({ | ||
loggedIn: { graphqlClient }, | ||
privateProjectConfig: { projectId: testProjectId }, | ||
}); | ||
|
||
await expect(command.runAsync()).rejects.toThrow(errorMessage); | ||
}); | ||
|
||
it('prompts for variable name and environment if the name is ambigous', async () => { | ||
jest | ||
.mocked(promptVariableEnvironmentAsync) | ||
.mockResolvedValueOnce(EnvironmentVariableEnvironment.Production); | ||
jest.mocked(promptVariableNameAsync).mockResolvedValueOnce('TEST_VAR_1'); | ||
|
||
const command = new EnvironmentVariableGet([], mockConfig); | ||
|
||
// @ts-expect-error | ||
jest.spyOn(command, 'getContextAsync').mockReturnValue({ | ||
loggedIn: { graphqlClient }, | ||
privateProjectConfig: { projectId: testProjectId }, | ||
}); | ||
jest.mocked(EnvironmentVariablesQuery.byAppIdWithSensitiveAsync).mockResolvedValueOnce([ | ||
...mockVariables, | ||
{ | ||
id: 'var2', | ||
name: 'TEST_VAR_1', | ||
value: 'value1', | ||
environments: [EnvironmentVariableEnvironment.Development], | ||
createdAt: new Date().toISOString(), | ||
updatedAt: new Date().toISOString(), | ||
scope: EnvironmentVariableScope.Project, | ||
visibility: EnvironmentVariableVisibility.Public, | ||
}, | ||
]); | ||
await command.runAsync(); | ||
|
||
expect(promptVariableEnvironmentAsync).toHaveBeenCalled(); | ||
expect(promptVariableNameAsync).toHaveBeenCalled(); | ||
}); | ||
}); |
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