From c369f03baf372e06c9047920e34212fcc73713d4 Mon Sep 17 00:00:00 2001 From: Yoshiaki Togami Date: Fri, 30 Apr 2021 16:20:36 +0900 Subject: [PATCH 1/2] test(cli): add test for get-userpoolgroup-list.ts --- .../get-userpoolgroup-list.test.ts | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 packages/amplify-cli/src/__tests__/extensions/amplify-helpers/get-userpoolgroup-list.test.ts diff --git a/packages/amplify-cli/src/__tests__/extensions/amplify-helpers/get-userpoolgroup-list.test.ts b/packages/amplify-cli/src/__tests__/extensions/amplify-helpers/get-userpoolgroup-list.test.ts new file mode 100644 index 00000000000..fa0d42f710d --- /dev/null +++ b/packages/amplify-cli/src/__tests__/extensions/amplify-helpers/get-userpoolgroup-list.test.ts @@ -0,0 +1,43 @@ +import { getUserPoolGroupList } from '../../../../src/extensions/amplify-helpers/get-userpoolgroup-list'; + +jest.mock('amplify-cli-core', () => ({ + pathManager: { + getBackendDirPath: jest.fn().mockImplementation(() => ''), + }, + JSONUtilities: { + readJson: jest.fn().mockImplementation(() => [ + { + groupName: 'Admins', + precedence: 1, + customPolicies: [ + { + PolicyName: 'admin-group-policy', + PolicyDocument: { + Version: '2012-10-17', + Statement: [ + { + Sid: 'statement1', + Effect: 'Allow', + Action: ['s3:CreateBucket'], + Resource: ['arn:aws:s3:::*'], + }, + ], + }, + }, + ], + }, + { + groupName: 'Editors', + precedence: 2, + }, + ]), + }, +})); + +describe('getUserPoolGroupList', () => { + const mock_context = {}; + it('should return array of groupNames', () => { + const userPoolGroupList = getUserPoolGroupList(mock_context); + expect(userPoolGroupList).toStrictEqual(['Admins', 'Editors']); + }); +}); From 018fa3036afc15e2af4af9d41269f5e778b126cc Mon Sep 17 00:00:00 2001 From: Yoshiaki Togami Date: Sun, 2 May 2021 21:38:12 +0900 Subject: [PATCH 2/2] fix: simplify the path --- .../extensions/amplify-helpers/get-userpoolgroup-list.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/amplify-cli/src/__tests__/extensions/amplify-helpers/get-userpoolgroup-list.test.ts b/packages/amplify-cli/src/__tests__/extensions/amplify-helpers/get-userpoolgroup-list.test.ts index fa0d42f710d..18145fa7a39 100644 --- a/packages/amplify-cli/src/__tests__/extensions/amplify-helpers/get-userpoolgroup-list.test.ts +++ b/packages/amplify-cli/src/__tests__/extensions/amplify-helpers/get-userpoolgroup-list.test.ts @@ -1,4 +1,4 @@ -import { getUserPoolGroupList } from '../../../../src/extensions/amplify-helpers/get-userpoolgroup-list'; +import { getUserPoolGroupList } from '../../../extensions/amplify-helpers/get-userpoolgroup-list'; jest.mock('amplify-cli-core', () => ({ pathManager: {