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 182991a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
18 changes: 9 additions & 9 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 @@ -122,15 +123,14 @@ export const createUserLibrary = (queries: Queries) => {
set: Partial<OmitAutoSetFields<CreateUser>>,
jsonbMode?: 'replace' | 'merge'
) => {
const { primaryPhone, ...rest } = set;
const validPhoneNumber = conditional(
'primaryPhone' in set &&
typeof set.primaryPhone === 'string' &&
getValidPhoneNumber(set.primaryPhone)
typeof primaryPhone === 'string' && getValidPhoneNumber(primaryPhone)
);

return updateUserByIdQuery(
id,
{ ...set, ...conditional(validPhoneNumber && { primaryPhone: validPhoneNumber }) },
{ ...rest, ...conditional(validPhoneNumber && { primaryPhone: validPhoneNumber }) },
jsonbMode
);
};
Expand All @@ -147,10 +147,9 @@ export const createUserLibrary = (queries: Queries) => {

assertThat(parameterRoles.length === roleNames.length, 'role.default_role_missing');

const { primaryPhone, ...rest } = data;
const validPhoneNumber = conditional(
'primaryPhone' in data &&
typeof data.primaryPhone === 'string' &&
getValidPhoneNumber(data.primaryPhone)
typeof primaryPhone === 'string' && getValidPhoneNumber(primaryPhone)
);

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

View check run for this annotation

Codecov / codecov/patch

packages/core/src/libraries/user.ts#L150-L154

Added lines #L150 - L154 were not covered by tests
return pool.transaction(async (connection) => {
Expand All @@ -159,7 +158,7 @@ export const createUserLibrary = (queries: Queries) => {
});

const user = await insertUserQuery({
...data,
...rest,
...conditional(validPhoneNumber && { primaryPhone: validPhoneNumber }),
});

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

View check run for this annotation

Codecov / codecov/patch

packages/core/src/libraries/user.ts#L160-L163

Added lines #L160 - L163 were not covered by tests
const roles = deduplicateByKey([...parameterRoles, ...defaultRoles], 'id');
Expand All @@ -173,7 +172,7 @@ export const createUserLibrary = (queries: Queries) => {

const provisionOrganizations = async (): Promise<readonly string[]> => {
// Just-in-time organization provisioning
const userEmailDomain = data.primaryEmail?.split('@')[1];
const userEmailDomain = rest.primaryEmail?.split('@')[1];

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

View check run for this annotation

Codecov / codecov/patch

packages/core/src/libraries/user.ts#L175

Added line #L175 was not covered by tests
// TODO: Remove this check when launching

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/core/src/libraries/user.ts#L176

[no-warning-comments] Unexpected 'todo' comment: 'TODO: Remove this check when launching'.
if (EnvSet.values.isDevFeaturesEnabled && userEmailDomain) {
const organizationQueries = new OrganizationQueries(connection);
Expand Down Expand Up @@ -368,3 +367,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 182991a

Please sign in to comment.