-
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
8a2ed45
commit a400056
Showing
2 changed files
with
123 additions
and
15 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
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,99 @@ | ||
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(['--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 '--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 environment and name', 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); | ||
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