Skip to content

Commit

Permalink
fix(@aws-amplify/auth): define validationData type as object literal (#…
Browse files Browse the repository at this point in the history
…8045)

* fix(@aws-amplify/auth): redefine validationData as an object literal in SignUpParams type

* chore(@aws-amplify/auth): fix linting errors for type-checking

* test(@aws-amplify/auth): unit test for validationData

* fix(@aws-amplify/auth): redefine validationData as an object literal in SignUpParams type

* chore(@aws-amplify/auth): fix linting errors for type-checking

* test(@aws-amplify/auth): unit test for validationData

* test(@aws-amplify/auth): specify type of SignUpParams

* test(@aws-amplify/auth): DIRTY - modify package.json to catch TS mismatches

* fix(@aws-amplify/auth): redefine validationData as an object literal in SignUpParams type

* chore(@aws-amplify/auth): fix linting errors for type-checking

* test(@aws-amplify/auth): unit test for validationData

* test(@aws-amplify/auth): specify type of SignUpParams

* test(@aws-amplify/auth): DIRTY - modify package.json to catch TS mismatches

* test(@aws-amplify/auth): modify happy case test to check Types correctly

Co-authored-by: Nick Arocho <[email protected]>
Co-authored-by: Ivan Artemiev <[email protected]>
  • Loading branch information
3 people authored Apr 13, 2021
1 parent c4ccc17 commit 6d0b67c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 18 deletions.
58 changes: 49 additions & 9 deletions packages/auth/__tests__/auth-unit-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import OAuth from '../src/OAuth/OAuth';
import * as oauthStorage from '../src/OAuth/oauthStorage';
import { NodeCallback } from 'amazon-cognito-identity-js';
import {
CookieStorage,
CognitoUserPool,
CognitoUser,
CognitoUserSession,
CognitoIdToken,
CognitoAccessToken,
NodeCallback,
} from 'amazon-cognito-identity-js';

jest.mock('crypto-js/sha256', () => {
return {
Expand Down Expand Up @@ -222,14 +230,6 @@ jest.mock('amazon-cognito-identity-js/lib/CognitoUser', () => {
import { AuthOptions, SignUpParams, AwsCognitoOAuthOpts } from '../src/types';
import { AuthClass as Auth } from '../src/Auth';
import Cache from '@aws-amplify/cache';
import {
CookieStorage,
CognitoUserPool,
CognitoUser,
CognitoUserSession,
CognitoIdToken,
CognitoAccessToken,
} from 'amazon-cognito-identity-js';
import {
Credentials,
GoogleOAuth,
Expand Down Expand Up @@ -814,6 +814,46 @@ describe('auth unit test', () => {
spyon.mockClear();
});

test('happy case validationData parameter', async () => {
const spyon = jest.spyOn(CognitoUserPool.prototype, 'signUp');
const auth = new Auth(authOptionsWithClientMetadata);

const attrs: SignUpParams = {
username: 'username',
password: 'password',
attributes: {
email: 'email',
phone_number: 'phone_number',
otherAttrs: 'otherAttrs',
},
clientMetadata: {
custom: 'value',
},
validationData: {
foo: 'bar',
test: '123',
},
};
await auth.signUp(attrs);

expect(await spyon).toBeCalledWith(
attrs.username,
attrs.password,
[
{ Name: 'email', Value: 'email' },
{ Name: 'phone_number', Value: 'phone_number' },
{ Name: 'otherAttrs', Value: 'otherAttrs' },
],
[
{ Name: 'foo', Value: 'bar' },
{ Name: 'test', Value: '123' },
],
jasmine.any(Function),
{ custom: 'value' }
);
spyon.mockClear();
});

test('throw error if failed to call currentUserPoolUser after signing in', async () => {
const spyon = jest
.spyOn(CognitoUser.prototype, 'authenticateUser')
Expand Down
8 changes: 4 additions & 4 deletions packages/auth/__tests__/oauth-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('OAuth', () => {
};
const oAuth = new OAuth({
scopes: [],
config: config,
config,
cognitoClientId: '',
});

Expand All @@ -71,7 +71,7 @@ describe('OAuth', () => {
};
const oAuth = new OAuth({
scopes: [],
config: config,
config,
cognitoClientId: '',
});
const mockAccessToken = 'mockAccessToken';
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('OAuth', () => {
};
const oAuth = new OAuth({
scopes: [],
config: config,
config,
cognitoClientId: '',
});

Expand All @@ -130,7 +130,7 @@ describe('OAuth', () => {
};
const oAuth = new OAuth({
scopes: [],
config: config,
config,
cognitoClientId: '',
});
const mockError = 'mock error';
Expand Down
1 change: 0 additions & 1 deletion packages/auth/__tests__/totp-unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ jest.mock('amazon-cognito-identity-js/lib/CognitoUser', () => {

CognitoUser.prototype.associateSoftwareToken = callback => {
callback.associateSecretCode('secretCode');
//callback.onFailure()
};

CognitoUser.prototype.verifySoftwareToken = (
Expand Down
4 changes: 2 additions & 2 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"access": "public"
},
"scripts": {
"test": "tslint 'src/**/*.ts' && jest -w 1 --coverage",
"test": "yarn lint && jest -w 1 --coverage",
"build-with-test": "npm test && npm run build",
"build:cjs": "node ./build es5 && webpack && webpack --config ./webpack.config.dev.js",
"build:esm": "node ./build es6",
Expand All @@ -28,7 +28,7 @@
"build": "npm run clean && npm run build:esm && npm run build:cjs",
"clean": "rimraf lib-esm lib dist",
"format": "echo \"Not implemented\"",
"lint": "tslint 'src/**/*.ts'"
"lint": "tslint '{__tests__,src}/**/*.ts'"
},
"repository": {
"type": "git",
Expand Down
3 changes: 1 addition & 2 deletions packages/auth/src/types/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import {
ICookieStorageData,
ICognitoStorage,
ICognitoUserAttributeData,
} from 'amazon-cognito-identity-js';

/**
Expand All @@ -24,7 +23,7 @@ export interface SignUpParams {
username: string;
password: string;
attributes?: object;
validationData?: ICognitoUserAttributeData[];
validationData?: { [key: string]: any };
clientMetadata?: { [key: string]: string };
}

Expand Down

0 comments on commit 6d0b67c

Please sign in to comment.