-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubscription-wrong.http
84 lines (71 loc) · 2.97 KB
/
subscription-wrong.http
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
74
75
76
77
78
79
80
81
82
83
84
### Get all courses
GET http://localhost:8091/courses
> {%
client.test("Request executed successfully", function () {
client.assert(response.status === 200, `Response status is not 200, but ${response.status}`);
});
client.test("Content-Type is application/json", () => {
const contentType = response.headers.valueOf("content-type");
client.assert(contentType == "application/json",
`Expected Content-Type is application/json, but actual is ${contentType}`)
})
const courses = response.body;
const course = jsonPath(courses, "$[?(@.name == 'Nuclear Power I' && @.start == '2028-02-01')]");
const courseId = jsonPath(course, "$[0].id")
console.log("Course id is", courseId, "of", jsonPath(course, "$[0].name"));
client.global.set("courseId", courseId);
%}
### Retrieve students
// @no-log
GET http://localhost:8091/students
> {%
client.test("Request executed successfully", function () {
client.assert(response.status === 200, `Response status is not 200, but ${response.status}`);
});
client.test("Content-Type is application/json", () => {
const contentType = response.headers.valueOf("content-type");
client.assert(contentType == "application/json",
`Expected Content-Type is application/json, but actual is ${contentType}`)
})
const students = response.body;
const kermitMatriculationNumbers = jsonPath(students, "$[?(@.firstName == 'Kermit')].matriculationNumber");
const kermitMatriculationNumber = jsonPath(kermitMatriculationNumbers, "$[0]");
console.log("Kermit matriculation number is", kermitMatriculationNumber);
client.global.set("kermitMatriculationNumber", kermitMatriculationNumber);
%}
### Register Kermit for Course
PUT http://localhost:8091/course-subscriptions
Content-Type: application/json
{
"courseId": "{{ courseId }}",
"matriculationNumber": "{{ kermitMatriculationNumber }}"
}
> {%
client.test("Request executed successfully", function () {
client.assert(response.status === 204, `Response status is not 204, but ${response.status}`);
});
%}
### Retrieve Kermits Timetable
< {%
import {wait} from "wait";
console.log("waiting 5 secs");
wait(5);
%}
// @no-log
GET http://localhost:8091/timetables/{{ kermitMatriculationNumber }}
> {%
client.test("Request executed successfully", function () {
client.assert(response.status === 200, `Response status is not 200, but ${response.status}`);
});
client.test("Content-Type is application/json", () => {
const contentType = response.headers.valueOf("content-type");
client.assert(contentType == "application/json",
`Expected Content-Type is application/json, but actual is ${contentType}`)
});
client.test("Kermit is not subscribed", () => {
const timetable = response.body;
const kermitNuclearPower = jsonPath(timetable, "$.courses[?(@.courseName == 'Nuclear Power I')]");
const amount = jsonPath(kermitNuclearPower, "$.length()")
client.assert(amount == 0, "Kermit should not be subscribed to Nuclear Power I");
});
%}