From c03844f12e018505e4c0df3d185c36384dcef2d3 Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Thu, 10 Nov 2022 16:37:12 +0800 Subject: [PATCH] chore: fix tests and add changeset --- packages/core/src/queries/user.test.ts | 4 ++-- packages/core/src/routes/admin-user.test.ts | 20 ++++--------------- packages/core/src/routes/admin-user.ts | 2 +- .../tests/api/dashboard.test.ts | 2 +- .../tests/api/session.test.ts | 14 +++++++++++++ 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/packages/core/src/queries/user.test.ts b/packages/core/src/queries/user.test.ts index 6eb556874..c2d925c9a 100644 --- a/packages/core/src/queries/user.test.ts +++ b/packages/core/src/queries/user.test.ts @@ -67,7 +67,7 @@ describe('user query', () => { const expectSql = sql` select ${sql.join(Object.values(fields), sql`,`)} from ${table} - where ${fields.primaryEmail}=$1 + where lower(${fields.primaryEmail})=lower($1) `; mockQuery.mockImplementationOnce(async (sql, values) => { @@ -179,7 +179,7 @@ describe('user query', () => { SELECT EXISTS( select ${fields.primaryEmail} from ${table} - where ${fields.primaryEmail}=$1 + where lower(${fields.primaryEmail})=lower($1) ) `; diff --git a/packages/core/src/routes/admin-user.test.ts b/packages/core/src/routes/admin-user.test.ts index c155fc7e9..28667237c 100644 --- a/packages/core/src/routes/admin-user.test.ts +++ b/packages/core/src/routes/admin-user.test.ts @@ -117,8 +117,11 @@ describe('adminUserRoutes', () => { const username = 'MJAtLogto'; const password = 'PASSWORD'; const name = 'Michael'; + const primaryEmail = 'foo@logto.io'; - const response = await userRequest.post('/users').send({ username, password, name }); + const response = await userRequest + .post('/users') + .send({ primaryEmail, username, password, name }); expect(response.status).toEqual(200); expect(response.body).toEqual({ ...mockUserResponse, @@ -133,21 +136,6 @@ describe('adminUserRoutes', () => { const password = 'PASSWORD'; const name = 'Michael'; - // Missing input - await expect(userRequest.post('/users').send({})).resolves.toHaveProperty('status', 400); - await expect(userRequest.post('/users').send({ username, password })).resolves.toHaveProperty( - 'status', - 400 - ); - await expect(userRequest.post('/users').send({ username, name })).resolves.toHaveProperty( - 'status', - 400 - ); - await expect(userRequest.post('/users').send({ password, name })).resolves.toHaveProperty( - 'status', - 400 - ); - // Invalid input format await expect( userRequest.post('/users').send({ username, password: 'abc', name }) diff --git a/packages/core/src/routes/admin-user.ts b/packages/core/src/routes/admin-user.ts index 868da92c8..5fda0a90b 100644 --- a/packages/core/src/routes/admin-user.ts +++ b/packages/core/src/routes/admin-user.ts @@ -125,7 +125,7 @@ export default function adminUserRoutes(router: T) { primaryEmail: string().regex(emailRegEx).optional(), username: string().regex(usernameRegEx).optional(), password: string().regex(passwordRegEx), - name: string(), + name: string().optional(), }), }), async (ctx, next) => { diff --git a/packages/integration-tests/tests/api/dashboard.test.ts b/packages/integration-tests/tests/api/dashboard.test.ts index cb93b330b..e0c324308 100644 --- a/packages/integration-tests/tests/api/dashboard.test.ts +++ b/packages/integration-tests/tests/api/dashboard.test.ts @@ -44,7 +44,7 @@ describe('admin console dashboard', () => { const username = generateUsername(); await createUserByAdmin(username, password); - await signIn(username, password); + await signIn({ username, password }); const newActiveUserStatistics = await getActiveUsersData(); diff --git a/packages/integration-tests/tests/api/session.test.ts b/packages/integration-tests/tests/api/session.test.ts index 2c9540a43..4e0c0cfee 100644 --- a/packages/integration-tests/tests/api/session.test.ts +++ b/packages/integration-tests/tests/api/session.test.ts @@ -37,6 +37,18 @@ describe('username and password flow', () => { const username = generateUsername(); const password = generatePassword(); + beforeAll(async () => { + await setSignUpIdentifier(SignUpIdentifier.Username, true); + await setSignInMethod([ + { + identifier: SignInIdentifier.Username, + password: true, + verificationCode: false, + isPasswordPrimary: false, + }, + ]); + }); + it('register and sign in with username & password', async () => { await expect(registerNewUser(username, password)).resolves.not.toThrow(); await expect(signIn({ username, password })).resolves.not.toThrow(); @@ -51,6 +63,8 @@ describe('email and password flow', () => { assert(localPart && domain, new Error('Email address local part or domain is empty')); beforeAll(async () => { + await setUpConnector(mockEmailConnectorId, mockEmailConnectorConfig); + await setSignUpIdentifier(SignUpIdentifier.Email, true); await setSignInMethod([ { identifier: SignInIdentifier.Email,