Skip to content

Commit 989ea15

Browse files
committed
test: add API tests for auth, users, and resource + setup Postman collection
1 parent 6c2c06e commit 989ea15

12 files changed

+162
-15
lines changed

playwright.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export default defineConfig({
1818
use: {
1919
baseURL: ENV.baseUrl,
2020
trace: "on-first-retry",
21+
extraHTTPHeaders: {
22+
"x-api-key": "reqres-free-v1",
23+
"Content-Type": "application/json",
24+
},
2125
},
2226
projects: [
2327
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test("Login User", async ({ request }) => {
4+
const loginUserRes = await request.post("https://reqres.in/api/login", {
5+
data: {
6+
7+
password: "cityslicka",
8+
},
9+
});
10+
11+
const loginUserResJSON = await loginUserRes.json();
12+
13+
console.log(loginUserResJSON);
14+
15+
expect(loginUserRes.status()).toBe(200);
16+
17+
expect(loginUserResJSON).toHaveProperty("token", "QpwL5tke4Pnpja7X4");
18+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test("Logout User", async ({ request }) => {
4+
const logoutUserRes = await request.post("https://reqres.in/api/logout", {
5+
data: {},
6+
});
7+
8+
const logoutUserResJSON = await logoutUserRes.json();
9+
10+
console.log("Response status:", logoutUserRes.status());
11+
console.log("Response body:", logoutUserResJSON);
12+
13+
expect(logoutUserRes.status()).toBe(200);
14+
15+
expect(logoutUserResJSON).toEqual({});
16+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test("Register User", async ({ request }) => {
4+
const registerUserRes = await request.post("https://reqres.in/api/register", {
5+
data: {
6+
7+
password: "pistol",
8+
},
9+
});
10+
11+
const registerUserResJSON = await registerUserRes.json();
12+
13+
console.log(registerUserResJSON);
14+
15+
expect(registerUserRes.status()).toBe(200);
16+
17+
expect(registerUserResJSON).toHaveProperty("id", 4);
18+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test("Delete resource", async ({ request }) => {
4+
const deleteRes = await request.delete("https://reqres.in/api/resource/1");
5+
6+
expect(deleteRes.status()).toBe(204);
7+
});

tests/api/reqres/resource/getResource.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { test, expect } from "@playwright/test";
22

3-
test("GET resource", async ({ request }) => {
3+
test("GET resource list", async ({ request }) => {
44
const resourceResponse = await request.get("https://reqres.in/api/resource", {
55
params: {
66
page: 2,
77
per_page: 3,
88
},
9-
headers: {
10-
"x-api-key": "reqres-free-v1",
11-
},
129
});
1310

1411
const resourceResponseJSON = await resourceResponse.json();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test("GET resource list", async ({ request }) => {
4+
const resourceResponse = await request.get(
5+
"https://reqres.in/api/resource/1",
6+
{
7+
params: {
8+
page: 2,
9+
per_page: 3,
10+
},
11+
}
12+
);
13+
14+
const resourceResponseJSON = await resourceResponse.json();
15+
16+
console.log(resourceResponseJSON);
17+
18+
expect(resourceResponse.status()).toBe(200);
19+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test.describe("Update Resource API", () => {
4+
test("Should update resource with PUT", async ({ request }) => {
5+
const response = await request.put("https://reqres.in/api/resource/2", {
6+
data: {
7+
name: "Kamran",
8+
year: 2008,
9+
},
10+
});
11+
12+
expect(response.status()).toBe(200);
13+
const body = await response.json();
14+
15+
console.log(body);
16+
17+
expect(body).toHaveProperty("year", 2008);
18+
});
19+
20+
test("Should update resource with PATCH", async ({ request }) => {
21+
const response = await request.patch("https://reqres.in/api/resource/2", {
22+
data: {
23+
color: "#FFF231",
24+
},
25+
});
26+
27+
expect(response.status()).toBe(200);
28+
const body = await response.json();
29+
30+
console.log(body);
31+
32+
expect(body).toHaveProperty("color", "#FFF231");
33+
});
34+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test("Delete user", async ({ request }) => {
4+
const deleteUserRes = await request.delete("https://reqres.in/api/users/8");
5+
6+
expect(deleteUserRes.status()).toBe(204);
7+
});

tests/api/reqres/users/getUserById.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { test, expect } from "@playwright/test";
22

33
test("Get user by id", async ({ request }) => {
4-
const userByIdRepsonse = await request.get("https://reqres.in/api/users/1", {
5-
headers: {
6-
"x-api-key": "reqres-free-v1",
7-
},
8-
});
4+
const userByIdRepsonse = await request.get("https://reqres.in/api/users/1");
95

106
const userByIdRepsonseJSON = await userByIdRepsonse.json();
117

0 commit comments

Comments
 (0)