-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_functionality.js
More file actions
73 lines (67 loc) · 2.1 KB
/
Copy pathtest_functionality.js
File metadata and controls
73 lines (67 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const BASE_URL = "http://localhost:3000/api";
async function testCreateTodo() {
console.log("\n--- Testing POST /todos ---");
// 1. Valid Request
try {
const response = await fetch(`${BASE_URL}/todos`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
title: "Test Todo via Script",
description: "Testing if the endpoint works",
status: "TODO",
}),
});
const data = await response.json();
console.log(
`[1] Create Valid Todo: ${
response.status === 201 ? "PASSED ✅" : "FAILED ❌"
}`
);
if (response.status !== 201) console.log("Response:", data);
} catch (error) {
console.error("Error connecting to server:", error.message);
}
// 2. Invalid Status
try {
const response = await fetch(`${BASE_URL}/todos`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
title: "Invalid Status Todo",
status: "INVALID_STATUS",
}),
});
const data = await response.json();
console.log(
`[2] Validate Invalid Status: ${
response.status === 400 ? "PASSED ✅" : "FAILED ❌"
}`
);
if (response.status !== 400) console.log("Response:", data);
} catch (error) {
console.error("Error:", error.message);
}
// 3. Rate Limit Test Header Check
console.log("\n--- Checking Headers for Rate Limit ---");
try {
const response = await fetch(`${BASE_URL}/todos`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ title: "Rate Test Header", status: "TODO" }),
});
console.log("Rate Limit Limit:", response.headers.get("x-ratelimit-limit"));
console.log(
"Rate Limit Remaining:",
response.headers.get("x-ratelimit-remaining")
);
if (response.headers.get("x-ratelimit-limit")) {
console.log("[3] Rate Limit Headers Present: PASSED ✅");
} else {
console.log("[3] Rate Limit Headers Missing: FAILED ❌");
}
} catch (error) {
console.error(error);
}
}
testCreateTodo();