server/api/api/v1/blocks/index.test.ts
Jesse Wierzbinski ec506241f0
Some checks failed
CodeQL Scan / Analyze (javascript-typescript) (push) Failing after 6s
Build Docker Images / lint (push) Successful in 50s
Build Docker Images / check (push) Successful in 1m24s
Build Docker Images / tests (push) Failing after 8s
Build Docker Images / build (server, Dockerfile, ${{ github.repository_owner }}/server) (push) Has been skipped
Build Docker Images / build (worker, Worker.Dockerfile, ${{ github.repository_owner }}/worker) (push) Has been skipped
Deploy Docs to GitHub Pages / build (push) Failing after 15s
Mirror to Codeberg / Mirror (push) Failing after 0s
Deploy Docs to GitHub Pages / Deploy (push) Has been skipped
Nix Build / check (push) Failing after 33m5s
test(api): Remove old tests and introduce new, better ones
2025-03-23 03:34:17 +01:00

53 lines
1.5 KiB
TypeScript

import { afterAll, describe, expect, test } from "bun:test";
import { generateClient, getTestUsers } from "~/tests/utils";
const { users, deleteUsers } = await getTestUsers(3);
afterAll(async () => {
await deleteUsers();
});
describe("/api/v1/blocks", () => {
test("should return 401 when not authenticated", async () => {
await using client = await generateClient();
const { ok, raw } = await client.getBlocks();
expect(ok).toBe(false);
expect(raw.status).toBe(401);
});
test("should return empty array when no blocks", async () => {
await using client = await generateClient(users[0]);
const { ok, data } = await client.getBlocks();
expect(ok).toBe(true);
expect(data).toBeArrayOfSize(0);
});
test("should return blocked users", async () => {
await using client = await generateClient(users[0]);
// Block users[1] and users[2]
await client.blockAccount(users[1].id);
await client.blockAccount(users[2].id);
const { ok, data } = await client.getBlocks();
expect(ok).toBe(true);
expect(data).toBeArrayOfSize(2);
expect(data.map((u) => u.id)).toContain(users[1].id);
expect(data.map((u) => u.id)).toContain(users[2].id);
});
test("should respect limit parameter", async () => {
await using client = await generateClient(users[0]);
const { ok, data } = await client.getBlocks({ limit: 1 });
expect(ok).toBe(true);
expect(data).toBeArrayOfSize(1);
});
});