mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
79 lines
2.5 KiB
TypeScript
79 lines
2.5 KiB
TypeScript
import { afterAll, describe, expect, test } from "bun:test";
|
|
import type { Relationship as ApiRelationship } from "@versia/client/types";
|
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
|
import { meta } from "./follow.ts";
|
|
|
|
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
|
|
|
afterAll(async () => {
|
|
await deleteUsers();
|
|
});
|
|
|
|
// /api/v1/accounts/:id/follow
|
|
describe(meta.route, () => {
|
|
test("should return 401 if not authenticated", async () => {
|
|
const response = await fakeRequest(
|
|
meta.route.replace(":id", users[1].id),
|
|
{
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({}),
|
|
},
|
|
);
|
|
expect(response.status).toBe(401);
|
|
});
|
|
|
|
test("should return 404 if user not found", async () => {
|
|
const response = await fakeRequest(
|
|
meta.route.replace(":id", "00000000-0000-0000-0000-000000000000"),
|
|
{
|
|
method: "POST",
|
|
headers: {
|
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({}),
|
|
},
|
|
);
|
|
expect(response.status).toBe(404);
|
|
});
|
|
|
|
test("should follow user", async () => {
|
|
const response = await fakeRequest(
|
|
meta.route.replace(":id", users[1].id),
|
|
{
|
|
method: "POST",
|
|
headers: {
|
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({}),
|
|
},
|
|
);
|
|
expect(response.status).toBe(200);
|
|
|
|
const relationship = (await response.json()) as ApiRelationship;
|
|
expect(relationship.following).toBe(true);
|
|
});
|
|
|
|
test("should return 200 if user already followed", async () => {
|
|
const response = await fakeRequest(
|
|
meta.route.replace(":id", users[1].id),
|
|
{
|
|
method: "POST",
|
|
headers: {
|
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({}),
|
|
},
|
|
);
|
|
expect(response.status).toBe(200);
|
|
|
|
const relationship = (await response.json()) as ApiRelationship;
|
|
expect(relationship.following).toBe(true);
|
|
});
|
|
});
|