From 36b682d66215a3d7cc2a03e045f83d40afe966a9 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Thu, 21 Sep 2023 16:28:21 -1000 Subject: [PATCH] Add new user statuses endoint (and tests) --- server/api/api/v1/accounts/[id]/statuses.ts | 4 ++- .../v1/accounts/verify_credentials/index.ts | 2 +- tests/api.test.ts | 29 +++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/server/api/api/v1/accounts/[id]/statuses.ts b/server/api/api/v1/accounts/[id]/statuses.ts index e44b69cf..d4412d55 100644 --- a/server/api/api/v1/accounts/[id]/statuses.ts +++ b/server/api/api/v1/accounts/[id]/statuses.ts @@ -33,13 +33,15 @@ export default async ( if (!user) return errorResponse("User not found", 404); + // TODO: Check if status can be seen by this user const statuses = await Status.find({ where: { account: { id: user.id, }, - isReblog: !exclude_reblogs, + isReblog: exclude_reblogs ? true : undefined, }, + relations: ["account", "emojis", "announces", "likes"], order: { created_at: "DESC", }, diff --git a/server/api/api/v1/accounts/verify_credentials/index.ts b/server/api/api/v1/accounts/verify_credentials/index.ts index 9f7f7460..86c7bc61 100644 --- a/server/api/api/v1/accounts/verify_credentials/index.ts +++ b/server/api/api/v1/accounts/verify_credentials/index.ts @@ -5,6 +5,7 @@ import { errorResponse, jsonResponse } from "@response"; * Patches a user */ export default async (req: Request): Promise => { + // TODO: Add checks for disabled or not email verified accounts // Check if request is a PATCH request if (req.method !== "GET") return errorResponse("This method requires a GET request", 405); @@ -19,7 +20,6 @@ export default async (req: Request): Promise => { if (!user) return errorResponse("Unauthorized", 401); - // TODO: Add Source fields return jsonResponse({ ...(await user.toAPI()), source: user.source, diff --git a/tests/api.test.ts b/tests/api.test.ts index 2e0544ff..20a84af7 100644 --- a/tests/api.test.ts +++ b/tests/api.test.ts @@ -180,6 +180,35 @@ describe("GET /api/v1/accounts/verify_credentials", () => { }); }); +describe("GET /api/v1/accounts/:id/statuses", () => { + test("should return the statuses of the specified user", async () => { + const response = await fetch( + `${config.http.base_url}/api/v1/accounts/${user.id}/statuses`, + { + method: "GET", + headers: { + Authorization: `Bearer ${token.access_token}`, + "Content-Type": "application/json", + }, + } + ); + + expect(response.status).toBe(200); + expect(response.headers.get("content-type")).toBe("application/json"); + + const statuses: APIStatus[] = await response.json(); + + expect(statuses.length).toBe(1); + + const status1 = statuses[0]; + + // Basic validation + expect(status1.content).toBe("Hello, world!"); + expect(status1.visibility).toBe("public"); + expect(status1.account.id).toBe(user.id); + }); +}); + afterAll(async () => { const user = await User.findOneBy({ username: "test",