-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: auth controller 單元測試-創建本地使用者資料重覆失敗409回應
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { | ||
ArgumentMetadata, | ||
BadRequestException, | ||
ConflictException, | ||
HttpStatus, | ||
ValidationPipe, | ||
} from "@nestjs/common"; | ||
|
@@ -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(); | ||
} | ||
}); | ||
}); | ||
}); |