Skip to content

Commit

Permalink
refactor: rebase master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
darcyYe committed Jun 12, 2024
1 parent 1ed8c0a commit c03b7a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
19 changes: 12 additions & 7 deletions packages/core/src/libraries/user.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
}

Check warning on line 137 in packages/core/src/libraries/user.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/libraries/user.ts#L136-L137

Added lines #L136 - L137 were not covered by tests
),
},
jsonbMode
);
};
Expand All @@ -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)
);

Check warning on line 159 in packages/core/src/libraries/user.ts

View check run for this annotation

Codecov / codecov/patch

packages/core/src/libraries/user.ts#L156-L159

Added lines #L156 - L159 were not covered by tests
return pool.transaction(async (connection) => {
Expand Down Expand Up @@ -368,3 +372,4 @@ export const createUserLibrary = (queries: Queries) => {
updateUserById,
};
};
/* eslint-enable max-lines */
12 changes: 8 additions & 4 deletions packages/core/src/routes/admin-user/mfa-verifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -44,10 +45,13 @@ const mockLibraries = {
users: {
generateUserId: jest.fn(async () => 'fooId'),
insertUser: jest.fn(
async (user: CreateUser): Promise<User> => ({
...mockUser,
...removeUndefinedKeys(user), // No undefined values will be returned from database
})
async (user: CreateUser): Promise<InsertUserResult> => [
{
...mockUser,
...removeUndefinedKeys(user), // No undefined values will be returned from database
},
{ organizationIds: [] },
]
),
updateUserById: jest.fn(
async (_, data: Partial<CreateUser>): Promise<User> => ({
Expand Down

0 comments on commit c03b7a3

Please sign in to comment.