From 39c80352b33138f25e5c3c00db7c67e3f45c0f35 Mon Sep 17 00:00:00 2001 From: Stahsf <30379566+50431040@users.noreply.github.com> Date: Fri, 6 Sep 2024 15:37:03 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E5=AF=86=E7=A0=81=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=20(#411)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 密码复杂度检测 * chore: 改为服务端校验 * test: 修改用例 * test: 添加getPasswordStrength测试用例 --- .../auth/__test/auth.controller.spec.ts | 30 ++++++++++++++++++- .../_test/workspace.controller.spec.ts | 7 ++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/server/src/modules/auth/__test/auth.controller.spec.ts b/server/src/modules/auth/__test/auth.controller.spec.ts index eb7e0ca7..2aed3d04 100644 --- a/server/src/modules/auth/__test/auth.controller.spec.ts +++ b/server/src/modules/auth/__test/auth.controller.spec.ts @@ -92,7 +92,10 @@ describe('AuthController', () => { }; await expect(controller.register(mockUserInfo)).rejects.toThrow( - new HttpException('密码无效', EXCEPTION_CODE.PASSWORD_INVALID), + new HttpException( + '密码只能输入数字、字母、特殊字符', + EXCEPTION_CODE.PASSWORD_INVALID, + ), ); }); }); @@ -217,4 +220,29 @@ describe('AuthController', () => { expect(typeof result.data.img).toBe('string'); }); }); + + describe('password strength', () => { + it('it should return strong', async () => { + await expect( + controller.getPasswordStrength('abcd&1234'), + ).resolves.toEqual({ + code: 200, + data: 'Strong', + }); + }); + + it('it should return medium', async () => { + await expect(controller.getPasswordStrength('abc123')).resolves.toEqual({ + code: 200, + data: 'Medium', + }); + }); + + it('it should return weak', async () => { + await expect(controller.getPasswordStrength('123456')).resolves.toEqual({ + code: 200, + data: 'Weak', + }); + }); + }); }); diff --git a/server/src/modules/workspace/_test/workspace.controller.spec.ts b/server/src/modules/workspace/_test/workspace.controller.spec.ts index 73d84ab3..9431b6ce 100644 --- a/server/src/modules/workspace/_test/workspace.controller.spec.ts +++ b/server/src/modules/workspace/_test/workspace.controller.spec.ts @@ -245,8 +245,10 @@ describe('WorkspaceController', () => { const req = { user: { _id: new ObjectId() } }; const workspaceId = new ObjectId(); - const memberList = [{ workspaceId, userId: new ObjectId() }]; + const userId = new ObjectId(); + const memberList = [{ workspaceId, userId: userId }]; const workspaces = [{ _id: workspaceId, name: 'Test Workspace' }]; + const userList = [{ _id: userId, username: 'Test User' }]; jest .spyOn(workspaceService, 'findAllByUserId') @@ -254,6 +256,9 @@ describe('WorkspaceController', () => { jest .spyOn(workspaceMemberService, 'batchSearchByWorkspace') .mockResolvedValue(memberList as unknown as Array); + jest + .spyOn(userService, 'getUserListByIds') + .mockResolvedValue(userList as User[]); const result = await controller.getWorkspaceAndMember(req);