Skip to content

Commit

Permalink
fix: opensearch warning, add optional chaining to get api category (#…
Browse files Browse the repository at this point in the history
…8371)

* fix: opensearch warning, add optional chaining to get api category

* fix: opensearch warning, add test with existing categories
  • Loading branch information
josefaidt committed Oct 6, 2021
1 parent 721d4fc commit 2bdae3a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,19 @@ describe('graphql schema checks', () => {
searchablePushChecks(contextMock, map, 'test_api_name');
expect(printerMock.warn).not.toBeCalled();
});

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: {},
},
});
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/',
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function searchablePushChecks(context, map, apiName): void {
if (searchableModelTypes.length) {
const currEnv = context.amplify.getEnvInfo().envName;
const teamProviderInfo = stateManager.getTeamProviderInfo();
const apiCategory = teamProviderInfo[currEnv]?.categories?.api[apiName];
const apiCategory = teamProviderInfo[currEnv]?.categories?.api?.[apiName];
const instanceType =
apiCategory && apiCategory[ResourceConstants.PARAMETERS.ElasticsearchInstanceType]
? apiCategory[ResourceConstants.PARAMETERS.ElasticsearchInstanceType]
Expand Down

0 comments on commit 2bdae3a

Please sign in to comment.