|
1 | 1 | import { expect, test, describe } from "vitest"; |
2 | 2 | import { createJwt, getBaseEndpoint } from "./utils.js"; |
| 3 | +import { randomUUID } from "node:crypto"; |
3 | 4 |
|
4 | 5 | const baseEndpoint = getBaseEndpoint(); |
5 | 6 | const token = await createJwt(); |
@@ -232,3 +233,77 @@ describe("Membership API basic checks", async () => { |
232 | 233 | }, |
233 | 234 | ); |
234 | 235 | }); |
| 236 | + |
| 237 | +test("External Membership List lifecycle test", async () => { |
| 238 | + const unixTimestampSeconds = Math.floor(Date.now() / 1000); |
| 239 | + 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", |
| 247 | + }, |
| 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", |
| 262 | + }, |
| 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", |
| 274 | + }, |
| 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", |
| 289 | + }, |
| 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 | + body: JSON.stringify({ |
| 303 | + remove: ["acmtest3"], |
| 304 | + add: [], |
| 305 | + }), |
| 306 | + }, |
| 307 | + ); |
| 308 | + expect(response.status).toEqual(201); |
| 309 | +}); |
0 commit comments