2024-04-17 08:36:01 +02:00
|
|
|
import { afterAll, describe, expect, test } from "bun:test";
|
2024-08-26 19:40:15 +02:00
|
|
|
import type { Relationship as ApiRelationship } from "@versia/client/types";
|
2024-08-27 21:25:26 +02:00
|
|
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
2024-04-17 08:36:01 +02:00
|
|
|
|
|
|
|
|
const { users, tokens, deleteUsers } = await getTestUsers(2);
|
|
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
|
await deleteUsers();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// /api/v1/accounts/:id/follow
|
2024-12-30 20:18:48 +01:00
|
|
|
describe("/api/v1/accounts/:id/follow", () => {
|
2024-04-17 08:36:01 +02:00
|
|
|
test("should return 401 if not authenticated", async () => {
|
2024-08-27 21:25:26 +02:00
|
|
|
const response = await fakeRequest(
|
2024-12-30 20:18:48 +01:00
|
|
|
`/api/v1/accounts/${users[1].id}/follow`,
|
2024-08-27 21:25:26 +02:00
|
|
|
{
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
2024-04-17 08:36:01 +02:00
|
|
|
},
|
2024-08-27 21:25:26 +02:00
|
|
|
body: JSON.stringify({}),
|
|
|
|
|
},
|
2024-04-17 08:36:01 +02:00
|
|
|
);
|
|
|
|
|
expect(response.status).toBe(401);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("should return 404 if user not found", async () => {
|
2024-08-27 21:25:26 +02:00
|
|
|
const response = await fakeRequest(
|
2024-12-30 20:18:48 +01:00
|
|
|
"/api/v1/accounts/00000000-0000-0000-0000-000000000000/follow",
|
2024-08-27 21:25:26 +02:00
|
|
|
{
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
2024-11-03 17:45:21 +01:00
|
|
|
Authorization: `Bearer ${tokens[0].data.accessToken}`,
|
2024-08-27 21:25:26 +02:00
|
|
|
"Content-Type": "application/json",
|
2024-04-17 08:36:01 +02:00
|
|
|
},
|
2024-08-27 21:25:26 +02:00
|
|
|
body: JSON.stringify({}),
|
|
|
|
|
},
|
2024-04-17 08:36:01 +02:00
|
|
|
);
|
|
|
|
|
expect(response.status).toBe(404);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("should follow user", async () => {
|
2024-08-27 21:25:26 +02:00
|
|
|
const response = await fakeRequest(
|
2024-12-30 20:18:48 +01:00
|
|
|
`/api/v1/accounts/${users[1].id}/follow`,
|
2024-08-27 21:25:26 +02:00
|
|
|
{
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
2024-11-03 17:45:21 +01:00
|
|
|
Authorization: `Bearer ${tokens[0].data.accessToken}`,
|
2024-08-27 21:25:26 +02:00
|
|
|
"Content-Type": "application/json",
|
2024-04-17 08:36:01 +02:00
|
|
|
},
|
2024-08-27 21:25:26 +02:00
|
|
|
body: JSON.stringify({}),
|
|
|
|
|
},
|
2024-04-17 08:36:01 +02:00
|
|
|
);
|
|
|
|
|
expect(response.status).toBe(200);
|
|
|
|
|
|
2024-06-29 08:36:15 +02:00
|
|
|
const relationship = (await response.json()) as ApiRelationship;
|
2024-04-17 08:36:01 +02:00
|
|
|
expect(relationship.following).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("should return 200 if user already followed", async () => {
|
2024-08-27 21:25:26 +02:00
|
|
|
const response = await fakeRequest(
|
2024-12-30 20:18:48 +01:00
|
|
|
`/api/v1/accounts/${users[1].id}/follow`,
|
2024-08-27 21:25:26 +02:00
|
|
|
{
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
2024-11-03 17:45:21 +01:00
|
|
|
Authorization: `Bearer ${tokens[0].data.accessToken}`,
|
2024-08-27 21:25:26 +02:00
|
|
|
"Content-Type": "application/json",
|
2024-04-17 08:36:01 +02:00
|
|
|
},
|
2024-08-27 21:25:26 +02:00
|
|
|
body: JSON.stringify({}),
|
|
|
|
|
},
|
2024-04-17 08:36:01 +02:00
|
|
|
);
|
|
|
|
|
expect(response.status).toBe(200);
|
|
|
|
|
|
2024-06-29 08:36:15 +02:00
|
|
|
const relationship = (await response.json()) as ApiRelationship;
|
2024-04-17 08:36:01 +02:00
|
|
|
expect(relationship.following).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
});
|