server/api/api/v1/accounts/:id/pin.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

49 lines
1.4 KiB
TypeScript

import { afterAll, describe, expect, test } from "bun:test";
import { generateClient, getTestUsers } from "~/tests/utils";
const { users, deleteUsers } = await getTestUsers(2);
afterAll(async () => {
await deleteUsers();
});
describe("/api/v1/accounts/:id/pin", () => {
test("should return 401 if not authenticated", async () => {
await using client = await generateClient();
const { ok, raw } = await client.pinAccount(users[1].id);
expect(ok).toBe(false);
expect(raw.status).toBe(401);
});
test("should return 404 if user not found", async () => {
await using client = await generateClient(users[0]);
const { ok, raw } = await client.pinAccount(
"00000000-0000-0000-0000-000000000000",
);
expect(ok).toBe(false);
expect(raw.status).toBe(404);
});
test("should pin account", async () => {
await using client = await generateClient(users[0]);
const { ok, data } = await client.pinAccount(users[1].id);
expect(ok).toBe(true);
expect(data.endorsed).toBe(true);
});
test("should return 200 if account already pinned", async () => {
await using client = await generateClient(users[0]);
const { ok, data } = await client.pinAccount(users[1].id);
expect(ok).toBe(true);
expect(data.endorsed).toBe(true);
});
});