Skip to content

Commit

Permalink
Merge branch 'master' into lambda-timeout/should-be-an-integar
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Brewer committed Jul 22, 2021
2 parents 9494e68 + ef12705 commit cbe850c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 39 deletions.
21 changes: 0 additions & 21 deletions .github/stale.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ServiceQuestionsResult } from '../../../../provider-utils/awscloudformation/service-walkthrough-types';
import { ServiceQuestionsResult, AttributeType } from '../../../../provider-utils/awscloudformation/service-walkthrough-types';
import { doesConfigurationIncludeSMS } from '../../../../provider-utils/awscloudformation/utils/auth-sms-workflow-helper';

describe('doesConfigurationIncludeSMS', () => {
Expand Down Expand Up @@ -47,17 +47,17 @@ describe('doesConfigurationIncludeSMS', () => {
});

it('should return true when userNameAttribute contains phone number', () => {
request.usernameAttributes = ['phone_number'];
request.usernameAttributes = [AttributeType.PHONE_NUMBER];
expect(doesConfigurationIncludeSMS(request)).toBeTruthy();
});

it('should return true when userNameAttribute contains phone number', () => {
request.usernameAttributes = ['email, phone_number'] as any;
request.usernameAttributes = [AttributeType.EMAIL, AttributeType.PHONE_NUMBER] as any;
expect(doesConfigurationIncludeSMS(request)).toBeTruthy();
});

it('should return false when username attribute does not contain phone number', () => {
request.usernameAttributes = ['email'] as any;
request.usernameAttributes = [AttributeType.EMAIL] as any;
expect(doesConfigurationIncludeSMS(request)).toBeFalsy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ const mfaTypeMap: Record<'SMS' | 'TOTP', 'SMS Text Message' | 'TOTP'> = {

const signinAttributeMap: Record<CognitoUserPoolSigninMethod, UsernameAttributes[] | undefined> = {
[CognitoUserPoolSigninMethod.USERNAME]: undefined,
[CognitoUserPoolSigninMethod.EMAIL]: ['email'],
[CognitoUserPoolSigninMethod.PHONE_NUMBER]: ['phone_number'],
[CognitoUserPoolSigninMethod.EMAIL_AND_PHONE_NUMBER]: ['email', 'phone_number'],
[CognitoUserPoolSigninMethod.EMAIL]: [AttributeType.EMAIL],
[CognitoUserPoolSigninMethod.PHONE_NUMBER]: [AttributeType.PHONE_NUMBER],
[CognitoUserPoolSigninMethod.EMAIL_AND_PHONE_NUMBER]: [AttributeType.EMAIL, AttributeType.PHONE_NUMBER],
};

const aliasAttributeMap: Record<CognitoUserAliasAttributes, AliasAttributes> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import execa from 'execa';
import * as fs from 'fs-extra';
import { hideSync } from 'hidefile';
import { setRegPendingDelete } from '../../utils/win-utils';
import { windowsPathSerializer } from '../testUtils/snapshot-serializer';
import * as path from 'path';

jest.mock('execa');
const execa_mock = execa as jest.Mocked<typeof execa>;
Expand Down Expand Up @@ -44,6 +46,8 @@ const setRegPendingDelete_mock = setRegPendingDelete as jest.MockedFunction<type
// save original process.platform
const originalPlatform = process.platform;

expect.addSnapshotSerializer(windowsPathSerializer);

const context_stub_typed = (context_stub as unknown) as $TSContext;

describe('uninstall packaged CLI on mac / linux', () => {
Expand All @@ -60,6 +64,7 @@ describe('uninstall packaged CLI on mac / linux', () => {
value: originalPlatform,
});
});

it('removes the .amplify dir', async () => {
await run(context_stub_typed);

Expand Down Expand Up @@ -106,7 +111,7 @@ describe('uninstall packaged CLI on windows', () => {

expect(fs_mock.move.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"homedir/.amplify/bin/amplify.exe",
"${path.join('homedir', '.amplify', 'bin', 'amplify.exe')}",
"a/test/path/.amplify-pending-delete.exe",
Object {
"overwrite": true,
Expand Down
23 changes: 13 additions & 10 deletions packages/amplify-cli/src/__tests__/commands/upgrade.pkg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { run } from '../../commands/upgrade';
import fetch, { Response } from 'node-fetch';
import { $TSContext } from 'amplify-cli-core';
import * as core from 'amplify-cli-core';

import * as path from 'path';
import { windowsPathSerializer } from '../testUtils/snapshot-serializer';
jest.mock('fs-extra');
const fs_mock = (fs as unknown) as jest.Mocked<typeof fs>;

Expand Down Expand Up @@ -45,6 +46,7 @@ const context_stub_typed = (context_stub as unknown) as $TSContext;

// save original process.platform
const originalPlatform = process.platform;
expect.addSnapshotSerializer(windowsPathSerializer);

describe('run upgrade using packaged CLI', () => {
beforeEach(() => jest.clearAllMocks());
Expand All @@ -53,7 +55,7 @@ describe('run upgrade using packaged CLI', () => {
value: originalPlatform,
});
});

it('exits early if no new packaged version available', async () => {
// setup
fetch_mock.mockResolvedValueOnce(({
Expand Down Expand Up @@ -98,16 +100,17 @@ describe('run upgrade using packaged CLI', () => {
// validate
expect(fs_mock.move.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"homedir/bin/amplify-pkg-linux",
"homedir/bin/amplify",
"${path.join('homedir', 'bin', 'amplify-pkg-linux')}",
"${path.join('homedir', 'bin', 'amplify')}",
Object {
"overwrite": true,
},
]
`);

expect(fs_mock.chmod.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"homedir/bin/amplify",
"${path.join('homedir', 'bin', 'amplify')}",
"700",
]
`);
Expand Down Expand Up @@ -149,22 +152,22 @@ describe('run upgrade using packaged CLI', () => {
// validate
expect(fs_mock.move.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"homedir/bin/amplify.exe",
"homedir/bin/amplify-old.exe",
"${path.join('homedir', 'bin', 'amplify.exe')}",
"${path.join('homedir', 'bin', 'amplify-old.exe')}",
]
`);
expect(fs_mock.move.mock.calls[1]).toMatchInlineSnapshot(`
Array [
"homedir/bin/amplify-pkg-win.exe",
"homedir/bin/amplify.exe",
"${path.join('homedir', 'bin', 'amplify-pkg-win.exe')}",
"${path.join('homedir', 'bin', 'amplify.exe')}",
Object {
"overwrite": true,
},
]
`);
expect(fs_mock.chmod.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"homedir/bin/amplify.exe",
"${path.join('homedir', 'bin', 'amplify.exe')}",
"700",
]
`);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const originalPlatform = process.platform;

// converts inputs to toMatchInlineSnapshot() function into supported format
export const windowsPathSerializer = {
test(val) {
return typeof val === 'string' && originalPlatform === 'win32';
},
print(val) {
return `"${(val as string).replace(/\\/g, '\\')}"`;
}
};

test('validateWindowsPathSerializer', () => {
expect(windowsPathSerializer).toBeDefined();
});

0 comments on commit cbe850c

Please sign in to comment.