-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-and-fetch-todo-http-request.js
57 lines (52 loc) · 1.71 KB
/
create-and-fetch-todo-http-request.js
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
import http from "k6/http";
import { check, group } from "k6";
export let options = {
stages: [
{ duration: "0.5m", target: 3 }, // simulate ramp-up of traffic from 1 to 100 users over 5 minutes.
// { duration: '0.5m', target: 4 }, // stay at 100 users for 10 minutes
// { duration: '0.5m', target: 0 }, // ramp-down to 0 users
],
ext: {
loadimpact: {
projectID: 3737535,
// Test runs with the same name groups test runs together
name: "CircleCI Todo Load Test",
},
},
};
export default function () {
group("API uptime check", () => {
const response = http.get("https://todo-barkend-api-f523e469c18a.herokuapp.com/todos/");
check(response, {
"status code should be 200": (res) => res.status === 200,
});
});
let todoID;
group("Create a Todo", () => {
const response = http.post("https://todo-barkend-api-f523e469c18a.herokuapp.com/todos/", {
task: "write k6 tests",
});
todoID = response.json()._id;
check(response, {
"status code should be 200": (res) => res.status === 200,
});
check(response, {
"response should have created todo": (res) => res.json().completed === false,
});
});
group("get a todo item", () => {
const response = http.get(
`https://todo-barkend-api-f523e469c18a.herokuapp.com/todos/${todoID}`
);
check(response, {
"status code should be 200": (res) => res.status === 200,
});
check(response, {
"response should have the created todo": (res) => res.json()[0]._id === todoID,
});
console.log(JSON.stringify(response.json()[0]));
check(response, {
"response should have the correct state": (res) => res.json()[0].completed === false,
});
});
}