Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bboure committed Jan 24, 2024
1 parent ddd1380 commit 2f7ef55
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
24 changes: 14 additions & 10 deletions examples/__tests__/cognito.test.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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,
Expand All @@ -35,7 +39,7 @@ describe('Utils', () => {
const email = chance.email();
const password = chance.string({ length: 8 });

await cognitoSignUp({
await signUpCognitoUser({
clientId,
userPoolId,
username: email,
Expand All @@ -49,7 +53,7 @@ describe('Utils', () => {
});

await expect(
cognitoSignUp({
signUpCognitoUser({
clientId,
userPoolId,
username: email,
Expand All @@ -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,
Expand All @@ -83,7 +87,7 @@ describe('Utils', () => {
],
});

const credentials = await cognitoSignIn({
const credentials = await signInWithCognitoUser({
userPoolId,
clientId,
username: email,
Expand All @@ -101,7 +105,7 @@ describe('Utils', () => {
const password = chance.string({ length: 8 });

await expect(
cognitoSignIn({
signInWithCognitoUser({
clientId,
userPoolId,
username: email,
Expand All @@ -120,7 +124,7 @@ describe('Matchers', () => {
beforeAll(async () => {
existingUser = chance.email();

await cognitoSignUp({
await signUpCognitoUser({
clientId,
userPoolId,
username: existingUser,
Expand Down
18 changes: 9 additions & 9 deletions src/utils/cognito.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type CognitoInput = {
/**
* Cognito Sign In input
*/
export type CognitoSignInInput = {
export type SignInWithCognitoUserInput = {
/**
* The Cognito user pool id.
*/
Expand All @@ -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<AuthenticationResultType> => {
const { clientId, userPoolId, username, password, clientConfig } = input;
const client = getCognitoClient(clientConfig);
Expand All @@ -71,7 +71,7 @@ export const CognitoSignIn = async (
/**
* Cognito Sign Up input
*/
export type CognitoSignUpInput = CognitoSignInInput & {
export type SignUpCognitoUserInput = SignInWithCognitoUserInput & {
/**
* The Cognito user attributes.
*/
Expand All @@ -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<AuthenticationResultType> => {
const { clientId, userPoolId, username, password, attributes, clientConfig } =
input;
Expand All @@ -108,7 +108,7 @@ export const CognitoSignUp = async (
}),
);

return CognitoSignIn({
return signInWithCognitoUser({
clientId,
userPoolId,
password,
Expand Down

0 comments on commit 2f7ef55

Please sign in to comment.