Skip to content

Commit

Permalink
feat: auth controller 單元測試-創建本地使用者資料重覆失敗409回應
Browse files Browse the repository at this point in the history
  • Loading branch information
a20688392 committed Jun 4, 2023
1 parent 6caf0dc commit 43664ea
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/auth/auth.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
ArgumentMetadata,
BadRequestException,
ConflictException,
HttpStatus,
ValidationPipe,
} from "@nestjs/common";
Expand Down Expand Up @@ -200,5 +201,29 @@ describe("AuthController", () => {
await userRepository.clear();
}
});
it("應該會發生資料使用者重覆,並返回 409 狀態碼", async () => {
const createUserDto1: CreateUserDto = {
email: "[email protected]",
name: "displayname",
account: "account1",
password: "Password@123",
};
try {
await authService.register(createUserDto1);
await authService.register(createUserDto1);
} catch (error) {
expect(error).toBeInstanceOf(ConflictException);
expect(error.response).toEqual({
statusCode: 409,
message: ["email 已被註冊。", "account 已被註冊。"],
error: "Conflict",
});
}
});
afterEach(async () => {
if (userRepository && userRepository.clear) {
await userRepository.clear();
}
});
});
});

0 comments on commit 43664ea

Please sign in to comment.