mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
Add status pinning and unpinning, fix bugs
This commit is contained in:
parent
0a74bbfe93
commit
f51476e810
14 changed files with 322 additions and 116 deletions
|
|
@ -21,6 +21,14 @@ let user2: UserWithRelations;
|
|||
|
||||
describe("API Tests", () => {
|
||||
beforeAll(async () => {
|
||||
await client.user.deleteMany({
|
||||
where: {
|
||||
username: {
|
||||
in: ["test", "test2"],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
user = await createNewLocalUser({
|
||||
email: "test@test.com",
|
||||
username: "test",
|
||||
|
|
@ -291,6 +299,30 @@ describe("API Tests", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("GET /api/v1/blocks", () => {
|
||||
test("should return an array of APIAccount objects for the user's blocked accounts", async () => {
|
||||
const response = await fetch(
|
||||
`${config.http.base_url}/api/v1/blocks`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${token.access_token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.headers.get("content-type")).toBe(
|
||||
"application/json"
|
||||
);
|
||||
const body = (await response.json()) as APIAccount[];
|
||||
|
||||
expect(Array.isArray(body)).toBe(true);
|
||||
expect(body.length).toBe(1);
|
||||
expect(body[0].id).toBe(user2.id);
|
||||
});
|
||||
});
|
||||
|
||||
describe("POST /api/v1/accounts/:id/unblock", () => {
|
||||
test("should unblock the specified user and return an APIRelationship object", async () => {
|
||||
const response = await fetch(
|
||||
|
|
@ -369,6 +401,31 @@ describe("API Tests", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("GET /api/v1/mutes", () => {
|
||||
test("should return an array of APIAccount objects for the user's muted accounts", async () => {
|
||||
const response = await fetch(
|
||||
`${config.http.base_url}/api/v1/mutes`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${token.access_token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.headers.get("content-type")).toBe(
|
||||
"application/json"
|
||||
);
|
||||
|
||||
const body = (await response.json()) as APIAccount[];
|
||||
|
||||
expect(Array.isArray(body)).toBe(true);
|
||||
expect(body.length).toBe(1);
|
||||
expect(body[0].id).toBe(user2.id);
|
||||
});
|
||||
});
|
||||
|
||||
describe("POST /api/v1/accounts/:id/unmute", () => {
|
||||
test("should unmute the specified user and return an APIRelationship object", async () => {
|
||||
const response = await fetch(
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import {
|
|||
createNewLocalUser,
|
||||
} from "~database/entities/User";
|
||||
import type { APIAccount } from "~types/entities/account";
|
||||
import type { APIAsyncAttachment } from "~types/entities/async_attachment";
|
||||
import type { APIContext } from "~types/entities/context";
|
||||
import type { APIStatus } from "~types/entities/status";
|
||||
|
||||
|
|
@ -19,9 +20,18 @@ let token: Token;
|
|||
let user: UserWithRelations;
|
||||
let status: APIStatus | null = null;
|
||||
let status2: APIStatus | null = null;
|
||||
let media1: APIAsyncAttachment | null = null;
|
||||
|
||||
describe("API Tests", () => {
|
||||
beforeAll(async () => {
|
||||
await client.user.deleteMany({
|
||||
where: {
|
||||
username: {
|
||||
in: ["test", "test2"],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
user = await createNewLocalUser({
|
||||
email: "test@test.com",
|
||||
username: "test",
|
||||
|
|
@ -65,6 +75,36 @@ describe("API Tests", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("POST /api/v2/media", () => {
|
||||
test("should upload a file and return a MediaAttachment object", async () => {
|
||||
const formData = new FormData();
|
||||
formData.append("file", new Blob(["test"], { type: "text/plain" }));
|
||||
|
||||
// @ts-expect-error FormData is not iterable
|
||||
const response = await fetch(
|
||||
`${config.http.base_url}/api/v2/media`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${token.access_token}`,
|
||||
},
|
||||
body: formData,
|
||||
}
|
||||
);
|
||||
|
||||
expect(response.status).toBe(202);
|
||||
expect(response.headers.get("content-type")).toBe(
|
||||
"application/json"
|
||||
);
|
||||
|
||||
media1 = (await response.json()) as APIAsyncAttachment;
|
||||
|
||||
expect(media1.id).toBeDefined();
|
||||
expect(media1.type).toBe("unknown");
|
||||
expect(media1.url).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("POST /api/v1/statuses", () => {
|
||||
test("should create a new status and return an APIStatus object", async () => {
|
||||
const response = await fetch(
|
||||
|
|
@ -78,6 +118,7 @@ describe("API Tests", () => {
|
|||
body: JSON.stringify({
|
||||
status: "Hello, world!",
|
||||
visibility: "public",
|
||||
media_ids: [media1?.id],
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
|
@ -327,7 +368,7 @@ describe("API Tests", () => {
|
|||
|
||||
expect(statuses.length).toBe(2);
|
||||
|
||||
const status1 = statuses[1];
|
||||
const status1 = statuses[0];
|
||||
|
||||
// Basic validation
|
||||
expect(status1.content).toBe("This is a reply!");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue