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);
|
if (!user) return errorResponse("User not found", 404);
|
||||||
|
|
||||||
|
// TODO: Check if status can be seen by this user
|
||||||
const statuses = await Status.find({
|
const statuses = await Status.find({
|
||||||
where: {
|
where: {
|
||||||
account: {
|
account: {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
},
|
},
|
||||||
isReblog: !exclude_reblogs,
|
isReblog: exclude_reblogs ? true : undefined,
|
||||||
},
|
},
|
||||||
|
relations: ["account", "emojis", "announces", "likes"],
|
||||||
order: {
|
order: {
|
||||||
created_at: "DESC",
|
created_at: "DESC",
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { errorResponse, jsonResponse } from "@response";
|
||||||
* Patches a user
|
* Patches a user
|
||||||
*/
|
*/
|
||||||
export default async (req: Request): Promise<Response> => {
|
export default async (req: Request): Promise<Response> => {
|
||||||
|
// TODO: Add checks for disabled or not email verified accounts
|
||||||
// Check if request is a PATCH request
|
// Check if request is a PATCH request
|
||||||
if (req.method !== "GET")
|
if (req.method !== "GET")
|
||||||
return errorResponse("This method requires a GET request", 405);
|
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);
|
if (!user) return errorResponse("Unauthorized", 401);
|
||||||
|
|
||||||
// TODO: Add Source fields
|
|
||||||
return jsonResponse({
|
return jsonResponse({
|
||||||
...(await user.toAPI()),
|
...(await user.toAPI()),
|
||||||
source: user.source,
|
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 () => {
|
afterAll(async () => {
|
||||||
const user = await User.findOneBy({
|
const user = await User.findOneBy({
|
||||||
username: "test",
|
username: "test",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue