From 68ab8cc60c305ef35aedfd5ed6e624d476e849ad Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 10 Apr 2023 08:07:57 +0100 Subject: [PATCH] feature(#7787) - Fix linting issues --- .../dbAuth/api/src/DbAuthHandler.ts | 19 +++++++++---------- .../api/src/__tests__/DbAuthHandler.test.js | 8 +++++++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/auth-providers/dbAuth/api/src/DbAuthHandler.ts b/packages/auth-providers/dbAuth/api/src/DbAuthHandler.ts index 3129d739c909..0699ab24a45b 100644 --- a/packages/auth-providers/dbAuth/api/src/DbAuthHandler.ts +++ b/packages/auth-providers/dbAuth/api/src/DbAuthHandler.ts @@ -1287,20 +1287,19 @@ export class DbAuthHandler< this._validateField('username', username) && this._validateField('password', password) ) { - // Each db provider has it owns rules for case insensitive comparison. // We are checking if you have defined one for your db choice here // https://www.prisma.io/docs/concepts/components/prisma-client/case-sensitivity - const usernameMatchFlowOption = (this.options.signup as SignupFlowOptions)?.usernameMatch; - const findUniqueUserMatchCriteriaOptions = !usernameMatchFlowOption ? - { [this.options.authFields.username]: username } - : - { - [this.options.authFields.username]: { - equals: username, - mode: usernameMatchFlowOption + const usernameMatchFlowOption = (this.options.signup as SignupFlowOptions) + ?.usernameMatch + const findUniqueUserMatchCriteriaOptions = !usernameMatchFlowOption + ? { [this.options.authFields.username]: username } + : { + [this.options.authFields.username]: { + equals: username, + mode: usernameMatchFlowOption, + }, } - } const user = await this.dbAccessor.findUnique({ where: findUniqueUserMatchCriteriaOptions, diff --git a/packages/auth-providers/dbAuth/api/src/__tests__/DbAuthHandler.test.js b/packages/auth-providers/dbAuth/api/src/__tests__/DbAuthHandler.test.js index 06d543345de6..a570a53f3115 100644 --- a/packages/auth-providers/dbAuth/api/src/__tests__/DbAuthHandler.test.js +++ b/packages/auth-providers/dbAuth/api/src/__tests__/DbAuthHandler.test.js @@ -2364,6 +2364,7 @@ describe('dbAuth', () => { jest.resetAllMocks() jest.clearAllMocks() + const defaultMessage = options.signup.errors.usernameTaken const spy = jest.spyOn(db.user, 'findUnique') delete options.signup.usernameMatch @@ -2373,7 +2374,12 @@ describe('dbAuth', () => { password: 'password', }) const dbAuth = new DbAuthHandler(event, context, options) - await dbAuth._createUser().catch((e) => {}) + await dbAuth._createUser().catch((e) => { + expect(e).toBeInstanceOf(dbAuthError.DuplicateUsernameError) + expect(e.message).toEqual( + defaultMessage.replace(/\$\{username\}/, dbUser.email) + ) + }) expect(spy).toHaveBeenCalled() return expect(spy).not.toHaveBeenCalledWith({