mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
perf(api): ⚡ Store user and post metrics directly in database instead of recalculating them on-the-fly
Some checks failed
CodeQL Scan / Analyze (javascript-typescript) (push) Failing after 0s
Build Docker Images / lint (push) Failing after 6s
Build Docker Images / check (push) Failing after 6s
Build Docker Images / tests (push) Failing after 6s
Deploy Docs to GitHub Pages / build (push) Failing after 1s
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 / Deploy (push) Has been skipped
Mirror to Codeberg / Mirror (push) Failing after 1s
Nix Build / check (push) Failing after 1s
Some checks failed
CodeQL Scan / Analyze (javascript-typescript) (push) Failing after 0s
Build Docker Images / lint (push) Failing after 6s
Build Docker Images / check (push) Failing after 6s
Build Docker Images / tests (push) Failing after 6s
Deploy Docs to GitHub Pages / build (push) Failing after 1s
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 / Deploy (push) Has been skipped
Mirror to Codeberg / Mirror (push) Failing after 1s
Nix Build / check (push) Failing after 1s
This commit is contained in:
parent
cd12ccd6c1
commit
ddb3cfc978
16 changed files with 2676 additions and 106 deletions
|
|
@ -1,13 +1,12 @@
|
|||
import { afterAll, describe, expect, test } from "bun:test";
|
||||
import { generateClient, getTestUsers } from "~/tests/utils";
|
||||
|
||||
const { users, deleteUsers } = await getTestUsers(2);
|
||||
const { users, deleteUsers } = await getTestUsers(3);
|
||||
|
||||
afterAll(async () => {
|
||||
await deleteUsers();
|
||||
});
|
||||
|
||||
// /api/v1/accounts/:id/follow
|
||||
describe("/api/v1/accounts/:id/follow", () => {
|
||||
test("should return 401 if not authenticated", async () => {
|
||||
await using client = await generateClient();
|
||||
|
|
@ -35,6 +34,16 @@ describe("/api/v1/accounts/:id/follow", () => {
|
|||
const { ok } = await client.followAccount(users[1].id);
|
||||
|
||||
expect(ok).toBe(true);
|
||||
|
||||
const { ok: ok2, data: data2 } = await client.getAccount(users[1].id);
|
||||
|
||||
expect(ok2).toBe(true);
|
||||
expect(data2.followers_count).toBe(1);
|
||||
|
||||
const { ok: ok3, data: data3 } = await client.getAccount(users[0].id);
|
||||
|
||||
expect(ok3).toBe(true);
|
||||
expect(data3.following_count).toBe(1);
|
||||
});
|
||||
|
||||
test("should return 200 if user already followed", async () => {
|
||||
|
|
|
|||
60
api/api/v1/accounts/[id]/unfollow.test.ts
Normal file
60
api/api/v1/accounts/[id]/unfollow.test.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
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/accounts/:id/unfollow", () => {
|
||||
test("should return 401 if not authenticated", async () => {
|
||||
await using client = await generateClient();
|
||||
|
||||
const { ok, raw } = await client.unfollowAccount(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.unfollowAccount(
|
||||
"00000000-0000-0000-0000-000000000000",
|
||||
);
|
||||
|
||||
expect(ok).toBe(false);
|
||||
expect(raw.status).toBe(404);
|
||||
});
|
||||
|
||||
test("should unfollow user", async () => {
|
||||
await using client = await generateClient(users[0]);
|
||||
|
||||
const { ok } = await client.followAccount(users[1].id);
|
||||
|
||||
expect(ok).toBe(true);
|
||||
|
||||
const { ok: ok2 } = await client.unfollowAccount(users[1].id);
|
||||
|
||||
expect(ok2).toBe(true);
|
||||
|
||||
const { ok: ok3, data } = await client.getAccount(users[1].id);
|
||||
|
||||
expect(ok3).toBe(true);
|
||||
expect(data.followers_count).toBe(0);
|
||||
|
||||
const { ok: ok4, data: data4 } = await client.getAccount(users[0].id);
|
||||
|
||||
expect(ok4).toBe(true);
|
||||
expect(data4.following_count).toBe(0);
|
||||
});
|
||||
|
||||
test("should return 200 if user already followed", async () => {
|
||||
await using client = await generateClient(users[0]);
|
||||
|
||||
const { ok } = await client.followAccount(users[1].id);
|
||||
|
||||
expect(ok).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
@ -46,4 +46,29 @@ describe("POST /api/v1/statuses/:id/reblog", () => {
|
|||
expect(ok).toBe(true);
|
||||
expect(data.reblog?.id).toBe(statuses[0].id);
|
||||
});
|
||||
|
||||
test("should update reblog count on original status", async () => {
|
||||
await using client = await generateClient(users[0]);
|
||||
|
||||
// Unreblog the status first
|
||||
await client.unreblogStatus(statuses[0].id);
|
||||
|
||||
// Check that the reblog count is 0
|
||||
const { ok: ok1, data: data1 } = await client.getStatus(statuses[0].id);
|
||||
|
||||
expect(ok1).toBe(true);
|
||||
expect(data1.reblogs_count).toBe(0);
|
||||
|
||||
const { ok: ok2, data: data2 } = await client.reblogStatus(
|
||||
statuses[0].id,
|
||||
);
|
||||
|
||||
expect(ok2).toBe(true);
|
||||
expect(data2.reblog?.reblogs_count).toBe(1);
|
||||
|
||||
const { ok: ok3, data: data3 } = await client.getStatus(statuses[0].id);
|
||||
|
||||
expect(ok3).toBe(true);
|
||||
expect(data3.reblogs_count).toBe(1);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -48,4 +48,28 @@ describe("POST /api/v1/statuses/:id/unreblog", () => {
|
|||
expect(ok).toBe(true);
|
||||
expect(data.reblog).toBeNull();
|
||||
});
|
||||
|
||||
test("should update reblog count on original status", async () => {
|
||||
await using client = await generateClient(users[0]);
|
||||
|
||||
// Reblog the status first
|
||||
await client.reblogStatus(statuses[0].id);
|
||||
|
||||
// Check that the reblog count is 1
|
||||
const { ok: ok1, data: data1 } = await client.getStatus(statuses[0].id);
|
||||
|
||||
expect(ok1).toBe(true);
|
||||
expect(data1.reblogs_count).toBe(1);
|
||||
|
||||
const { ok: ok2, data: data2 } = await client.unreblogStatus(
|
||||
statuses[0].id,
|
||||
);
|
||||
|
||||
expect(ok2).toBe(true);
|
||||
expect(data2.reblogs_count).toBe(0);
|
||||
|
||||
const { ok: ok3, data: data3 } = await client.getStatus(statuses[0].id);
|
||||
expect(ok3).toBe(true);
|
||||
expect(data3.reblogs_count).toBe(0);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue