Skip to content

Commit

Permalink
fix: trigger analytics migration on update/configure notifications (#…
Browse files Browse the repository at this point in the history
…11285)

* fix: trigger analytics migration on update/configure notifications
  • Loading branch information
lazpavel committed Oct 28, 2022
1 parent af714b1 commit 0972ef9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { $TSContext } from 'amplify-cli-core';
import { migrationCheck } from '../migrations/index';
import * as apiAnalyticsClient from '../plugin-client-api-analytics';

const mockContext = {
input: { command: undefined },
} as unknown as $TSContext;

jest.mock('../plugin-client-api-analytics', () => ({ invokeAnalyticsMigrations: jest.fn() }));

describe('notifications tests', () => {
beforeEach(() => {
jest.resetAllMocks();
});

test('notification migrations calls analytics migration', async () => {
mockContext.input.command = 'add';
await migrationCheck(mockContext);
expect(apiAnalyticsClient.invokeAnalyticsMigrations).toBeCalled();
jest.resetAllMocks();

mockContext.input.command = 'configure';
await migrationCheck(mockContext);
expect(apiAnalyticsClient.invokeAnalyticsMigrations).toBeCalled();
jest.resetAllMocks();

mockContext.input.command = 'update';
await migrationCheck(mockContext);
expect(apiAnalyticsClient.invokeAnalyticsMigrations).toBeCalled();
jest.resetAllMocks();

mockContext.input.command = 'push';
await migrationCheck(mockContext);
expect(apiAnalyticsClient.invokeAnalyticsMigrations).toBeCalled();
jest.resetAllMocks();

mockContext.input.command = 'remove';
await migrationCheck(mockContext);
expect(apiAnalyticsClient.invokeAnalyticsMigrations).not.toBeCalled();
jest.resetAllMocks();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { invokeAnalyticsMigrations } from '../plugin-client-api-analytics';
* checks if the project has been migrated to the latest version
*/
export const migrationCheck = async (context: $TSContext): Promise<void> => {
if (['add', 'update', 'push'].includes(context.input.command)) {
if (['add', 'configure', 'update', 'push'].includes(context.input.command)) {
await invokeAnalyticsMigrations(context);
}
};

0 comments on commit 0972ef9

Please sign in to comment.