|
| 1 | +import { PageEntity } from "@liexp/backend/lib/entities/Page.entity.js"; |
| 2 | +import { saveUser } from "@liexp/backend/lib/test/utils/user.utils.js"; |
| 3 | +import { AdminDelete, AdminRead } from "@liexp/shared/lib/io/http/User.js"; |
| 4 | +import { throwTE } from "@liexp/shared/lib/utils/task.utils.js"; |
| 5 | +import { PageArb } from "@liexp/test/lib/arbitrary/Page.arbitrary.js"; |
| 6 | +import fc from "fast-check"; |
| 7 | +import { pipe } from "fp-ts/lib/function.js"; |
| 8 | +import { type AppTest, GetAppTest } from "../../../../test/AppTest.js"; |
| 9 | +import { loginUser } from "../../../../test/utils/user.utils.js"; |
| 10 | + |
| 11 | +describe("DeletePage route", () => { |
| 12 | + let Test: AppTest; |
| 13 | + |
| 14 | + beforeAll(async () => { |
| 15 | + Test = await GetAppTest(); |
| 16 | + }); |
| 17 | + |
| 18 | + test("admin with read permissions should not delete page", async () => { |
| 19 | + const user = await saveUser(Test.ctx, [AdminRead.literals[0]]); |
| 20 | + const { authorization } = await loginUser(Test)(user); |
| 21 | + |
| 22 | + const [payload] = fc.sample(PageArb, 1); |
| 23 | + |
| 24 | + await Test.req |
| 25 | + .post("/v1/pages") |
| 26 | + .set("Authorization", authorization) |
| 27 | + .send(payload) |
| 28 | + .expect(401); |
| 29 | + }); |
| 30 | + |
| 31 | + test("delete page happy path", async () => { |
| 32 | + const user = await saveUser(Test.ctx, [AdminDelete.literals[0]]); |
| 33 | + const { authorization } = await loginUser(Test)(user); |
| 34 | + |
| 35 | + const [payload] = fc.sample(PageArb, 1); |
| 36 | + |
| 37 | + await pipe( |
| 38 | + Test.ctx.db.save(PageEntity, [ |
| 39 | + { ...payload, createdAt: new Date(), updatedAt: new Date() }, |
| 40 | + ]), |
| 41 | + throwTE, |
| 42 | + ); |
| 43 | + |
| 44 | + const delRes = await Test.req |
| 45 | + .delete(`/v1/pages/${payload.id}`) |
| 46 | + .set("Authorization", authorization); |
| 47 | + |
| 48 | + expect(delRes.status).toEqual(200); |
| 49 | + }); |
| 50 | +}); |
0 commit comments