1
+ ### Defaults
2
+
3
+ [Header]
4
+ Content-Type: application/json
5
+
6
+
7
+
8
+ ### Teardown
9
+
10
+ // Clean up object 1.
11
+
12
+ DELETE {{.instance}}/api/collections/{{.collection.id}}/objects/{{.object1.id}}
13
+
14
+ [Options]
15
+ condition = {{ isset . "object1" }}
16
+
17
+ [Script]
18
+ assert(response.StatusCode == 204, `invalid status code: ${response.StatusCode}`);
19
+
20
+ ---
21
+
22
+ // Clean up object 2.
23
+
24
+ DELETE {{.instance}}/api/collections/{{.collection.id}}/objects/{{.object2.id}}
25
+
26
+ [Options]
27
+ condition = {{ isset . "object2" }}
28
+
29
+ [Script]
30
+ assert(response.StatusCode == 204, `invalid status code: ${response.StatusCode}`);
31
+
32
+ ---
33
+
34
+ // Clean up collection.
35
+
36
+ DELETE {{.instance}}/api/collections/{{.collection.id}}
37
+
38
+ [Options]
39
+ condition = {{ isset . "collection" }}
40
+
41
+ [Script]
42
+ assert(response.StatusCode == 204, `invalid status code: ${response.StatusCode}`);
43
+
44
+ ---
45
+
46
+ ### Tests
47
+
48
+ // Create a collection.
49
+
50
+ POST {{.instance}}/api/collections
51
+
52
+ [Body]
53
+ {
54
+ "name": "my games"
55
+ }
56
+
57
+ [Script]
58
+ debug(response);
59
+ assert(response.StatusCode == 201, `invalid status code: ${response.StatusCode}`);
60
+ var collection = response.Body;
61
+ assert(collection.name === "my games", "Invalid collection name");
62
+
63
+ ---
64
+
65
+ // Get created collection.
66
+
67
+ GET {{.instance}}/api/collections/{{.collection.id}}
68
+
69
+ [Script]
70
+ debug(response);
71
+ assert(response.StatusCode == 200, `invalid status code: ${response.StatusCode}`);
72
+ assert(response.Body.id === collection.id, "Invalid id");
73
+ assert(response.Body.created_at === collection.created_at, "Invalid created_at");
74
+ assert(response.Body.name === collection.name, "Invalid name");
75
+
76
+ ---
77
+
78
+ // Update the collection.
79
+
80
+ PUT {{.instance}}/api/collections/{{.collection.id}}
81
+
82
+ [PreScript]
83
+ var newCollection = {
84
+ ...collection,
85
+ name: "My Games"
86
+ }
87
+
88
+ [Body]
89
+ {{json .newCollection}}
90
+
91
+ [Script]
92
+ debug(response);
93
+ assert(response.StatusCode == 200, `invalid status code: ${response.StatusCode}`);
94
+ collection = newCollection;
95
+
96
+ ---
97
+
98
+ // Get created collection.
99
+
100
+ GET {{.instance}}/api/collections/{{.collection.id}}
101
+
102
+ [Script]
103
+ debug(response);
104
+ assert(response.StatusCode == 200, `invalid status code: ${response.StatusCode}`);
105
+ assert(response.Body.id === collection.id, "Invalid id");
106
+ assert(response.Body.created_at === collection.created_at, "Invalid created_at");
107
+ assert(response.Body.name === collection.name, "Invalid name");
108
+
109
+ ---
110
+
111
+ // Create object in collection
112
+
113
+ POST {{.instance}}/api/collections/{{.collection.id}}/objects
114
+
115
+ [Body]
116
+ {
117
+ "name": "Cyberpunk 2077",
118
+ "data": {
119
+ "publisher": "CD PROJECT RED",
120
+ "developer": "CD PROJECT RED",
121
+ "released": "2020-12-10T00:00:00Z",
122
+ "tags": ["Cyberpunk", "Open World"],
123
+ "age_rating": "18"
124
+ }
125
+ }
126
+
127
+ [Script]
128
+ assert(response.StatusCode == 201, `invalid status code: ${response.StatusCode}`);
129
+ var object1 = response.Body;
130
+
131
+ ---
132
+
133
+ // Create another object in collection
134
+
135
+ POST {{.instance}}/api/collections/{{.collection.id}}/objects
136
+
137
+ [Body]
138
+ {
139
+ "name": "Cult of the Lamb",
140
+ "data": {
141
+ "publisher": "Devolver Digital",
142
+ "developer": "Massive Monster",
143
+ "released": "2022-08-11T00:00:00Z",
144
+ "tags": ["Action", "Adventure", "Indie", "Strategy"],
145
+ "age_rating": "12"
146
+ }
147
+ }
148
+
149
+ [Script]
150
+ assert(response.StatusCode == 201, `invalid status code: ${response.StatusCode}`);
151
+ var object2 = response.Body;
152
+
153
+ ---
154
+
155
+ // Get first object
156
+
157
+ GET {{.instance}}/api/collections/{{.collection.id}}/objects/{{.object1.id}}
158
+
159
+ [Script]
160
+ assert(response.StatusCode == 200, `invalid status code: ${response.StatusCode}`);
161
+ assert(response.Body.id === object1.id, "invalid id");
162
+ assert(response.Body.created_at === object1.created_at, "invalid created_at");
163
+ assert(response.Body.name === object1.name, "invalid name");
164
+ assert(response.Body.data.publisher === object1.data.publisher, "invalid data.publisher");
165
+ assert(response.Body.data.released === object1.data.released, "invalid data.released");
166
+
167
+ ---
168
+
169
+ // Get second object
170
+
171
+ GET {{.instance}}/api/collections/{{.collection.id}}/objects/{{.object2.id}}
172
+
173
+ [Script]
174
+ assert(response.StatusCode == 200, `invalid status code: ${response.StatusCode}`);
175
+ assert(response.Body.id === object2.id, "invalid id");
176
+ assert(response.Body.created_at === object2.created_at, "invalid created_at");
177
+ assert(response.Body.name === object2.name, "invalid name");
178
+ assert(response.Body.data.publisher === object2.data.publisher, "invalid data.publisher");
179
+ assert(response.Body.data.released === object2.data.released, "invalid data.released");
180
+
181
+ ---
182
+
183
+ // Update first object in collection
184
+
185
+ PUT {{.instance}}/api/collections/{{.collection.id}}/objects/{{.object1.id}}
186
+
187
+ [PreScript]
188
+ var newObject1 = {
189
+ ...object1,
190
+ data: {
191
+ ...object1.data,
192
+ tags: [...object1.data.tags, "RPG", "Sci-fi"]
193
+ }
194
+ };
195
+
196
+ [Body]
197
+ {{json .newObject1}}
198
+
199
+ [Script]
200
+ assert(response.StatusCode == 200, `invalid status code: ${response.StatusCode}`);
201
+
202
+ ---
203
+
204
+ // Get updated first object
205
+
206
+ GET {{.instance}}/api/collections/{{.collection.id}}/objects/{{.object1.id}}
207
+
208
+ [Script]
209
+ assert(response.StatusCode == 200, `invalid status code: ${response.StatusCode}`);
210
+ assert(response.Body.id === object1.id, "invalid id");
211
+ assert(response.Body.created_at === object1.created_at, "invalid created_at");
212
+ assert(response.Body.name === object1.name, "invalid name");
213
+ assert(response.Body.data.publisher === object1.data.publisher, "invalid data.publisher");
214
+ assert(response.Body.data.released === object1.data.released, "invalid data.released");
215
+ assert(JSON.stringify(response.Body.data.tags) === JSON.stringify(newObject1.data.tags), "invalid updated data.tags");
0 commit comments