From 2f7ef55325170911fc2012aebc5a1f3a2503f79f Mon Sep 17 00:00:00 2001 From: bboure Date: Wed, 24 Jan 2024 13:27:30 +0100 Subject: [PATCH] fixes --- examples/__tests__/cognito.test.ts | 24 ++++++++++++++---------- src/utils/cognito.ts | 18 +++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/examples/__tests__/cognito.test.ts b/examples/__tests__/cognito.test.ts index d1ab708..c5c6d02 100644 --- a/examples/__tests__/cognito.test.ts +++ b/examples/__tests__/cognito.test.ts @@ -1,5 +1,9 @@ import { Chance } from 'chance'; -import { cognitoSignIn, cognitoSignUp, cognitoUser } from 'sls-jest'; +import { + signInWithCognitoUser, + signUpCognitoUser, + cognitoUser, +} from 'sls-jest'; const chance = new Chance(); @@ -8,11 +12,11 @@ const clientId = '3oed3rv2h43sleqojqtt2bb43a'; const userPoolId = 'us-east-1_2KFDP3x2n'; describe('Utils', () => { - describe('cognitoSignUp', () => { + describe('signUpCognitoUser', () => { it('should sign up a user and return its credentials, when user does not exist', async () => { const email = chance.email(); const password = chance.string({ length: 8 }); - const credentials = await cognitoSignUp({ + const credentials = await signUpCognitoUser({ clientId, userPoolId, username: email, @@ -35,7 +39,7 @@ describe('Utils', () => { const email = chance.email(); const password = chance.string({ length: 8 }); - await cognitoSignUp({ + await signUpCognitoUser({ clientId, userPoolId, username: email, @@ -49,7 +53,7 @@ describe('Utils', () => { }); await expect( - cognitoSignUp({ + signUpCognitoUser({ clientId, userPoolId, username: email, @@ -65,12 +69,12 @@ describe('Utils', () => { }); }); - describe('cognitoSignIn', () => { + describe('signInWithCognitoUser', () => { it('should sign in a user and return its credentials, when user exists', async () => { const email = chance.email(); const password = chance.string({ length: 8 }); - await cognitoSignUp({ + await signUpCognitoUser({ clientId, userPoolId, username: email, @@ -83,7 +87,7 @@ describe('Utils', () => { ], }); - const credentials = await cognitoSignIn({ + const credentials = await signInWithCognitoUser({ userPoolId, clientId, username: email, @@ -101,7 +105,7 @@ describe('Utils', () => { const password = chance.string({ length: 8 }); await expect( - cognitoSignIn({ + signInWithCognitoUser({ clientId, userPoolId, username: email, @@ -120,7 +124,7 @@ describe('Matchers', () => { beforeAll(async () => { existingUser = chance.email(); - await cognitoSignUp({ + await signUpCognitoUser({ clientId, userPoolId, username: existingUser, diff --git a/src/utils/cognito.ts b/src/utils/cognito.ts index 74271eb..2953e91 100644 --- a/src/utils/cognito.ts +++ b/src/utils/cognito.ts @@ -19,7 +19,7 @@ type CognitoInput = { /** * Cognito Sign In input */ -export type CognitoSignInInput = { +export type SignInWithCognitoUserInput = { /** * The Cognito user pool id. */ @@ -41,10 +41,10 @@ export type CognitoSignInInput = { /** * Sign in a user in Cognito and return its credentials. * - * @param input {@link CognitoSignInInput} + * @param input {@link SignInWithCognitoUserInput} */ -export const CognitoSignIn = async ( - input: CognitoSignInInput, +export const signInWithCognitoUser = async ( + input: SignInWithCognitoUserInput, ): Promise => { const { clientId, userPoolId, username, password, clientConfig } = input; const client = getCognitoClient(clientConfig); @@ -71,7 +71,7 @@ export const CognitoSignIn = async ( /** * Cognito Sign Up input */ -export type CognitoSignUpInput = CognitoSignInInput & { +export type SignUpCognitoUserInput = SignInWithCognitoUserInput & { /** * The Cognito user attributes. */ @@ -81,10 +81,10 @@ export type CognitoSignUpInput = CognitoSignInInput & { /** * Create a new user in Cognito, auto confirm it and return its credentials. * - * @param input {@link CognitoSignUpInput} + * @param input {@link SignUpCognitoUserInput} */ -export const CognitoSignUp = async ( - input: CognitoSignUpInput, +export const signUpCognitoUser = async ( + input: SignUpCognitoUserInput, ): Promise => { const { clientId, userPoolId, username, password, attributes, clientConfig } = input; @@ -108,7 +108,7 @@ export const CognitoSignUp = async ( }), ); - return CognitoSignIn({ + return signInWithCognitoUser({ clientId, userPoolId, password,