mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
Add new user statuses endoint (and tests)
This commit is contained in:
parent
c0c6067d4d
commit
36b682d662
|
|
@ -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",
|
||||
},
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { errorResponse, jsonResponse } from "@response";
|
|||
* Patches a user
|
||||
*/
|
||||
export default async (req: Request): Promise<Response> => {
|
||||
// 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<Response> => {
|
|||
|
||||
if (!user) return errorResponse("Unauthorized", 401);
|
||||
|
||||
// TODO: Add Source fields
|
||||
return jsonResponse({
|
||||
...(await user.toAPI()),
|
||||
source: user.source,
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue