test: 密码检测用例 (#411)

* feat: 密码复杂度检测

* chore: 改为服务端校验

* test: 修改用例

* test: 添加getPasswordStrength测试用例
This commit is contained in:
Stahsf 2024-09-06 15:37:03 +08:00 committed by GitHub
parent 63e16e1694
commit d3c2180ac8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 2 deletions

View File

@ -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',
});
});
});
});

View File

@ -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<WorkspaceMember>);
jest
.spyOn(userService, 'getUserListByIds')
.mockResolvedValue(userList as User[]);
const result = await controller.getWorkspaceAndMember(req);