-
Notifications
You must be signed in to change notification settings - Fork 826
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(graphql-model-transformer): fix open search instance check for v1…
… and v2 transformers (#8354)
- Loading branch information
Showing
3 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
packages/amplify-provider-awscloudformation/src/__tests__/graphql-push-schema-checks.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 { stateManager } from 'amplify-cli-core'; | ||
import { printer } from 'amplify-prompts'; | ||
import { searchablePushChecks } from '../transform-graphql-schema'; | ||
|
||
jest.mock('amplify-cli-core'); | ||
jest.mock('amplify-prompts'); | ||
|
||
const printerMock = printer as jest.Mocked<typeof printer>; | ||
const stateManagerMock = stateManager as jest.Mocked<typeof stateManager>; | ||
|
||
describe('graphql schema checks', () => { | ||
const contextMock = { | ||
amplify: { | ||
getEnvInfo: jest.fn(), | ||
}, | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should warn users if they use not recommended open search instance without overrides', async () => { | ||
printerMock.warn.mockImplementation(jest.fn()); | ||
stateManagerMock.getTeamProviderInfo.mockReturnValue({}); | ||
contextMock.amplify.getEnvInfo.mockReturnValue({ envName: 'test' }); | ||
const map = { Post: ['model', 'searchable'] }; | ||
searchablePushChecks(contextMock, map, 'test_api_name'); | ||
expect(printerMock.warn).lastCalledWith( | ||
'Your instance type for OpenSearch is t2.small.elasticsearch, you may experience performance issues or data loss. Consider reconfiguring with the instructions here https://docs.amplify.aws/cli/graphql-transformer/searchable/', | ||
); | ||
}); | ||
|
||
it('should warn users if they use not recommended open search instance with overrides', async () => { | ||
printerMock.warn.mockImplementation(jest.fn()); | ||
stateManagerMock.getTeamProviderInfo.mockReturnValue({ | ||
test: { | ||
categories: { | ||
api: { | ||
test_api_name: { | ||
ElasticSearchInstanceType: 't2.small.elasticsearch', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
contextMock.amplify.getEnvInfo.mockReturnValue({ envName: 'test' }); | ||
const map = { Post: ['model', 'searchable'] }; | ||
searchablePushChecks(contextMock, map, 'test_api_name'); | ||
expect(printerMock.warn).lastCalledWith( | ||
'Your instance type for OpenSearch is t2.small.elasticsearch, you may experience performance issues or data loss. Consider reconfiguring with the instructions here https://docs.amplify.aws/cli/graphql-transformer/searchable/', | ||
); | ||
}); | ||
|
||
it('should NOT warn users if they use recommended open search instance', async () => { | ||
printerMock.warn.mockImplementation(jest.fn()); | ||
stateManagerMock.getTeamProviderInfo.mockReturnValue({ | ||
test: { | ||
categories: { | ||
api: { | ||
test_api_name: { | ||
ElasticSearchInstanceType: 't2.medium.elasticsearch', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
contextMock.amplify.getEnvInfo.mockReturnValue({ envName: 'test' }); | ||
const map = { Post: ['model', 'searchable'] }; | ||
searchablePushChecks(contextMock, map, 'test_api_name'); | ||
expect(printerMock.warn).not.toBeCalled(); | ||
}); | ||
|
||
it('should NOT warn users if they use recommended open search instance on the environment', async () => { | ||
printerMock.warn.mockImplementation(jest.fn()); | ||
stateManagerMock.getTeamProviderInfo.mockReturnValue({ | ||
dev: { | ||
categories: { | ||
api: { | ||
test_api_name: { | ||
ElasticSearchInstanceType: 't2.small.elasticsearch', | ||
}, | ||
}, | ||
}, | ||
}, | ||
prod: { | ||
categories: { | ||
api: { | ||
test_api_name: { | ||
ElasticSearchInstanceType: 't2.medium.elasticsearch', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
contextMock.amplify.getEnvInfo.mockReturnValue({ envName: 'prod' }); | ||
const map = { Post: ['model', 'searchable'] }; | ||
searchablePushChecks(contextMock, map, 'test_api_name'); | ||
expect(printerMock.warn).not.toBeCalled(); | ||
}); | ||
|
||
it('should NOT warn users if they do NOT use searchable', async () => { | ||
printerMock.warn.mockImplementation(jest.fn()); | ||
stateManagerMock.getTeamProviderInfo.mockReturnValue({}); | ||
contextMock.amplify.getEnvInfo.mockReturnValue({ envName: 'test' }); | ||
const map = { Post: ['model'] }; | ||
searchablePushChecks(contextMock, map, 'test_api_name'); | ||
expect(printerMock.warn).not.toBeCalled(); | ||
}); | ||
}); |
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