From c03b7a3b2c5faaef88d5ee9e7c3f4e611c3dca5f Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Wed, 12 Jun 2024 15:07:05 +0800 Subject: [PATCH] refactor: rebase master branch --- packages/core/src/libraries/user.ts | 19 ++++++++++++------- .../admin-user/mfa-verifications.test.ts | 12 ++++++++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/core/src/libraries/user.ts b/packages/core/src/libraries/user.ts index 781ef6af6..09c63ac8f 100644 --- a/packages/core/src/libraries/user.ts +++ b/packages/core/src/libraries/user.ts @@ -1,3 +1,4 @@ +/* eslint-disable max-lines */ import type { BindMfa, CreateUser, MfaVerification, Scope, User } from '@logto/schemas'; import { MfaFactor, RoleType, Users, UsersPasswordEncryptionMethod } from '@logto/schemas'; import { generateStandardShortId, generateStandardId } from '@logto/shared'; @@ -123,14 +124,19 @@ export const createUserLibrary = (queries: Queries) => { jsonbMode?: 'replace' | 'merge' ) => { const validPhoneNumber = conditional( - 'primaryPhone' in set && - typeof set.primaryPhone === 'string' && - getValidPhoneNumber(set.primaryPhone) + typeof set.primaryPhone === 'string' && getValidPhoneNumber(set.primaryPhone) ); return updateUserByIdQuery( id, - { ...set, ...conditional(validPhoneNumber && { primaryPhone: validPhoneNumber }) }, + { + ...set, + ...conditional( + validPhoneNumber && { + primaryPhone: validPhoneNumber, + } + ), + }, jsonbMode ); }; @@ -148,9 +154,7 @@ export const createUserLibrary = (queries: Queries) => { assertThat(parameterRoles.length === roleNames.length, 'role.default_role_missing'); const validPhoneNumber = conditional( - 'primaryPhone' in data && - typeof data.primaryPhone === 'string' && - getValidPhoneNumber(data.primaryPhone) + typeof data.primaryPhone === 'string' && getValidPhoneNumber(data.primaryPhone) ); return pool.transaction(async (connection) => { @@ -368,3 +372,4 @@ export const createUserLibrary = (queries: Queries) => { updateUserById, }; }; +/* eslint-enable max-lines */ diff --git a/packages/core/src/routes/admin-user/mfa-verifications.test.ts b/packages/core/src/routes/admin-user/mfa-verifications.test.ts index 3439504dd..5e1dc4a4d 100644 --- a/packages/core/src/routes/admin-user/mfa-verifications.test.ts +++ b/packages/core/src/routes/admin-user/mfa-verifications.test.ts @@ -8,6 +8,7 @@ import { mockUserTotpMfaVerification, mockUserWithMfaVerifications, } from '#src/__mocks__/index.js'; +import { type InsertUserResult } from '#src/libraries/user.js'; import type Libraries from '#src/tenants/Libraries.js'; import type Queries from '#src/tenants/Queries.js'; import { MockTenant, type Partial2 } from '#src/test-utils/tenant.js'; @@ -44,10 +45,13 @@ const mockLibraries = { users: { generateUserId: jest.fn(async () => 'fooId'), insertUser: jest.fn( - async (user: CreateUser): Promise => ({ - ...mockUser, - ...removeUndefinedKeys(user), // No undefined values will be returned from database - }) + async (user: CreateUser): Promise => [ + { + ...mockUser, + ...removeUndefinedKeys(user), // No undefined values will be returned from database + }, + { organizationIds: [] }, + ] ), updateUserById: jest.fn( async (_, data: Partial): Promise => ({