|
1 | 1 | import { expect, test, describe } from "vitest"; |
2 | 2 | import { createJwt, getBaseEndpoint } from "./utils.js"; |
3 | | -import { randomUUID } from "node:crypto"; |
4 | 3 |
|
5 | 4 | const baseEndpoint = getBaseEndpoint(); |
6 | 5 | const token = await createJwt(); |
@@ -234,76 +233,91 @@ describe("Membership API basic checks", async () => { |
234 | 233 | ); |
235 | 234 | }); |
236 | 235 |
|
237 | | -test("External Membership List lifecycle test", async () => { |
| 236 | +describe("External Membership List lifecycle", { sequential: true }, () => { |
238 | 237 | const unixTimestampSeconds = Math.floor(Date.now() / 1000); |
239 | 238 | const listId = `livetest-${unixTimestampSeconds}`; |
240 | | - let response = await fetch( |
241 | | - `${baseEndpoint}/api/v1/membership/externalList/${listId}`, |
242 | | - { |
243 | | - method: "PATCH", |
244 | | - headers: { |
245 | | - authorization: `Bearer ${token}`, |
246 | | - "content-type": "application/json", |
| 239 | + |
| 240 | + test("should create list and add initial member", async () => { |
| 241 | + const response = await fetch( |
| 242 | + `${baseEndpoint}/api/v1/membership/externalList/${listId}`, |
| 243 | + { |
| 244 | + method: "PATCH", |
| 245 | + headers: { |
| 246 | + authorization: `Bearer ${token}`, |
| 247 | + "content-type": "application/json", |
| 248 | + }, |
| 249 | + body: JSON.stringify({ |
| 250 | + add: ["acmtest2"], |
| 251 | + remove: [], |
| 252 | + }), |
247 | 253 | }, |
248 | | - body: JSON.stringify({ |
249 | | - add: ["acmtest2"], |
250 | | - remove: [], |
251 | | - }), |
252 | | - }, |
253 | | - ); |
254 | | - expect(response.status).toBe(201); |
255 | | - response = await fetch( |
256 | | - `${baseEndpoint}/api/v1/membership/externalList/${listId}`, |
257 | | - { |
258 | | - method: "GET", |
259 | | - headers: { |
260 | | - authorization: `Bearer ${token}`, |
261 | | - "content-type": "application/json", |
| 254 | + ); |
| 255 | + expect(response.status).toBe(201); |
| 256 | + }); |
| 257 | + |
| 258 | + test("should retrieve list with initial member", async () => { |
| 259 | + const response = await fetch( |
| 260 | + `${baseEndpoint}/api/v1/membership/externalList/${listId}`, |
| 261 | + { |
| 262 | + method: "GET", |
| 263 | + headers: { |
| 264 | + authorization: `Bearer ${token}`, |
| 265 | + "content-type": "application/json", |
| 266 | + }, |
262 | 267 | }, |
263 | | - }, |
264 | | - ); |
265 | | - let responseJson = await response.json(); |
266 | | - expect(responseJson).toStrictEqual(["acmtest2"]); |
267 | | - response = await fetch( |
268 | | - `${baseEndpoint}/api/v1/membership/externalList/${listId}`, |
269 | | - { |
270 | | - method: "PATCH", |
271 | | - headers: { |
272 | | - authorization: `Bearer ${token}`, |
273 | | - "content-type": "application/json", |
| 268 | + ); |
| 269 | + const responseJson = await response.json(); |
| 270 | + expect(responseJson).toStrictEqual(["acmtest2"]); |
| 271 | + }); |
| 272 | + |
| 273 | + test("should add new member and remove existing member", async () => { |
| 274 | + const response = await fetch( |
| 275 | + `${baseEndpoint}/api/v1/membership/externalList/${listId}`, |
| 276 | + { |
| 277 | + method: "PATCH", |
| 278 | + headers: { |
| 279 | + authorization: `Bearer ${token}`, |
| 280 | + "content-type": "application/json", |
| 281 | + }, |
| 282 | + body: JSON.stringify({ |
| 283 | + add: ["acmtest3"], |
| 284 | + remove: ["acmtest2"], |
| 285 | + }), |
274 | 286 | }, |
275 | | - body: JSON.stringify({ |
276 | | - add: ["acmtest3"], |
277 | | - remove: ["acmtest2"], |
278 | | - }), |
279 | | - }, |
280 | | - ); |
281 | | - expect(response.status).toEqual(201); |
282 | | - response = await fetch( |
283 | | - `${baseEndpoint}/api/v1/membership/externalList/${listId}`, |
284 | | - { |
285 | | - method: "GET", |
286 | | - headers: { |
287 | | - authorization: `Bearer ${token}`, |
288 | | - "content-type": "application/json", |
| 287 | + ); |
| 288 | + expect(response.status).toEqual(201); |
| 289 | + }); |
| 290 | + |
| 291 | + test("should retrieve list with updated member", async () => { |
| 292 | + const response = await fetch( |
| 293 | + `${baseEndpoint}/api/v1/membership/externalList/${listId}`, |
| 294 | + { |
| 295 | + method: "GET", |
| 296 | + headers: { |
| 297 | + authorization: `Bearer ${token}`, |
| 298 | + "content-type": "application/json", |
| 299 | + }, |
289 | 300 | }, |
290 | | - }, |
291 | | - ); |
292 | | - responseJson = await response.json(); |
293 | | - expect(responseJson).toStrictEqual(["acmtest3"]); |
294 | | - response = await fetch( |
295 | | - `${baseEndpoint}/api/v1/membership/externalList/${listId}`, |
296 | | - { |
297 | | - method: "PATCH", |
298 | | - headers: { |
299 | | - authorization: `Bearer ${token}`, |
300 | | - "content-type": "application/json", |
| 301 | + ); |
| 302 | + const responseJson = await response.json(); |
| 303 | + expect(responseJson).toStrictEqual(["acmtest3"]); |
| 304 | + }); |
| 305 | + |
| 306 | + test("should remove final member", async () => { |
| 307 | + const response = await fetch( |
| 308 | + `${baseEndpoint}/api/v1/membership/externalList/${listId}`, |
| 309 | + { |
| 310 | + method: "PATCH", |
| 311 | + headers: { |
| 312 | + authorization: `Bearer ${token}`, |
| 313 | + "content-type": "application/json", |
| 314 | + }, |
| 315 | + body: JSON.stringify({ |
| 316 | + remove: ["acmtest3"], |
| 317 | + add: [], |
| 318 | + }), |
301 | 319 | }, |
302 | | - body: JSON.stringify({ |
303 | | - remove: ["acmtest3"], |
304 | | - add: [], |
305 | | - }), |
306 | | - }, |
307 | | - ); |
308 | | - expect(response.status).toEqual(201); |
| 320 | + ); |
| 321 | + expect(response.status).toEqual(201); |
| 322 | + }); |
309 | 323 | }); |
0 commit comments