2024-04-25 05:40:27 +02:00
|
|
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
2024-08-26 19:40:15 +02:00
|
|
|
import type { Account as ApiAccount } from "@versia/client/types";
|
2024-08-27 21:25:26 +02:00
|
|
|
import { fakeRequest, getTestUsers } from "~/tests/utils";
|
2024-10-04 15:22:48 +02:00
|
|
|
import { meta } from "./followers.ts";
|
2024-04-25 05:40:27 +02:00
|
|
|
|
|
|
|
|
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
|
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
|
await deleteUsers();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
|
// Follow user
|
2024-08-27 21:25:26 +02:00
|
|
|
const response = await fakeRequest(
|
|
|
|
|
`/api/v1/accounts/${users[1].id}/follow`,
|
|
|
|
|
{
|
|
|
|
|
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-25 05:40:27 +02:00
|
|
|
},
|
2024-08-27 21:25:26 +02:00
|
|
|
body: JSON.stringify({}),
|
|
|
|
|
},
|
2024-04-25 05:40:27 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(response.status).toBe(200);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// /api/v1/accounts/:id/followers
|
|
|
|
|
describe(meta.route, () => {
|
|
|
|
|
test("should return 200 with followers", async () => {
|
2024-08-27 21:25:26 +02:00
|
|
|
const response = await fakeRequest(
|
|
|
|
|
meta.route.replace(":id", users[1].id),
|
|
|
|
|
{
|
|
|
|
|
headers: {
|
2024-11-03 17:45:21 +01:00
|
|
|
Authorization: `Bearer ${tokens[0].data.accessToken}`,
|
2024-04-25 05:40:27 +02:00
|
|
|
},
|
2024-08-27 21:25:26 +02:00
|
|
|
},
|
2024-04-25 05:40:27 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(response.status).toBe(200);
|
|
|
|
|
|
2024-06-29 08:36:15 +02:00
|
|
|
const data = (await response.json()) as ApiAccount[];
|
2024-04-25 05:40:27 +02:00
|
|
|
|
|
|
|
|
expect(data).toBeInstanceOf(Array);
|
|
|
|
|
expect(data.length).toBe(1);
|
|
|
|
|
expect(data[0].id).toBe(users[0].id);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("should return no followers after unfollowing", async () => {
|
|
|
|
|
// Unfollow user
|
2024-08-27 21:25:26 +02:00
|
|
|
const response = await fakeRequest(
|
|
|
|
|
`/api/v1/accounts/${users[1].id}/unfollow`,
|
|
|
|
|
{
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
2024-11-03 17:45:21 +01:00
|
|
|
Authorization: `Bearer ${tokens[0].data.accessToken}`,
|
2024-04-25 05:40:27 +02:00
|
|
|
},
|
2024-08-27 21:25:26 +02:00
|
|
|
},
|
2024-04-25 05:40:27 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(response.status).toBe(200);
|
|
|
|
|
|
2024-08-27 21:25:26 +02:00
|
|
|
const response2 = await fakeRequest(
|
|
|
|
|
meta.route.replace(":id", users[1].id),
|
|
|
|
|
{
|
|
|
|
|
headers: {
|
2024-11-03 17:45:21 +01:00
|
|
|
Authorization: `Bearer ${tokens[0].data.accessToken}`,
|
2024-04-25 05:40:27 +02:00
|
|
|
},
|
2024-08-27 21:25:26 +02:00
|
|
|
},
|
2024-04-25 05:40:27 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(response2.status).toBe(200);
|
|
|
|
|
|
2024-06-29 08:36:15 +02:00
|
|
|
const data = (await response2.json()) as ApiAccount[];
|
2024-04-25 05:40:27 +02:00
|
|
|
|
|
|
|
|
expect(data).toBeInstanceOf(Array);
|
|
|
|
|
expect(data.length).toBe(0);
|
|
|
|
|
});
|
|
|
|
|
});
|