Created
April 13, 2026 15:33
-
-
Save minhphong306/1c12205d76197c42e2d2bcb6d1ebba34 to your computer and use it in GitHub Desktop.
test.spec.ts
This file contains hidden or 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
| test("Test api create todo - multile validation", async ({ request }) => { | |
| const body = { | |
| "title": "Todo - Minh Phong [K22 - Multiple validation]", | |
| "description": "Write comprehensive docs for the API", | |
| "status": "pending", | |
| "priority": "high", | |
| "due_date": "2025-10-25T17:00:00", | |
| "user_id": 1 | |
| } | |
| // Gọi API create todo | |
| let response = await request.post(`https://material.playwrightvn.com/api/todo-app/v1/todo.php`, { | |
| data: body | |
| }); | |
| // Lấy ra status code -> assert status code = 200 | |
| let statusCode = response.status(); | |
| expect(statusCode).toEqual(201); | |
| // lấy ra body, assert body bao gồm 3 phần tử | |
| let responseBody = await response.json(); | |
| const createdId = responseBody.todo.id; | |
| expect(responseBody.success).toBeTruthy(); | |
| expect(createdId).toBeGreaterThan(3); // sao id phai >3 a? | |
| expect(responseBody.todo.title).toEqual(body.title); | |
| // 2. Gọi API Get single by id (id đã tạo ở bước 1) | |
| // --> verify: code = 200, title đúng, id đúng | |
| response = await request.get(`https://material.playwrightvn.com/api/todo-app/v1/todo.php?id=${createdId}`); | |
| // Lấy ra status code -> assert status code = 200 | |
| statusCode = response.status(); | |
| expect(statusCode).toEqual(200); | |
| // lấy ra body, assert body có chứa todo với id và title chính xác | |
| responseBody = await response.json(); | |
| expect(responseBody.success).toBe(true); | |
| expect(responseBody.todo.id).toEqual(createdId); | |
| expect(responseBody.todo.title).toEqual(body.title); | |
| // .toBe(true) với toBeTruthy dùng như nhau đúng không anh | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment