mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
Add new follow API endpoint
This commit is contained in:
parent
36b682d662
commit
a9688b8178
7 changed files with 275 additions and 30 deletions
|
|
@ -8,12 +8,14 @@ import { RawActivity } from "~database/entities/RawActivity";
|
|||
import { Token, TokenType } from "~database/entities/Token";
|
||||
import { User } from "~database/entities/User";
|
||||
import { APIAccount } from "~types/entities/account";
|
||||
import { APIRelationship } from "~types/entities/relationship";
|
||||
import { APIStatus } from "~types/entities/status";
|
||||
|
||||
const config = getConfig();
|
||||
|
||||
let token: Token;
|
||||
let user: User;
|
||||
let user2: User;
|
||||
|
||||
beforeAll(async () => {
|
||||
if (!AppDataSource.isInitialized) await AppDataSource.initialize();
|
||||
|
|
@ -26,6 +28,14 @@ beforeAll(async () => {
|
|||
display_name: "",
|
||||
});
|
||||
|
||||
// Initialize second test user
|
||||
user2 = await User.createNew({
|
||||
email: "test2@test.com",
|
||||
username: "test2",
|
||||
password: "test2",
|
||||
display_name: "",
|
||||
});
|
||||
|
||||
const app = new Application();
|
||||
|
||||
app.name = "Test Application";
|
||||
|
|
@ -209,11 +219,31 @@ describe("GET /api/v1/accounts/:id/statuses", () => {
|
|||
});
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
const user = await User.findOneBy({
|
||||
username: "test",
|
||||
});
|
||||
describe("POST /api/v1/accounts/:id/follow", () => {
|
||||
test("should follow the specified user and return an APIRelationship object", async () => {
|
||||
const response = await fetch(
|
||||
`${config.http.base_url}/api/v1/accounts/${user2.id}/follow`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${token.access_token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({}),
|
||||
}
|
||||
);
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.headers.get("content-type")).toBe("application/json");
|
||||
|
||||
const account: APIRelationship = await response.json();
|
||||
|
||||
expect(account.id).toBe(user2.id);
|
||||
expect(account.following).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
const activities = await RawActivity.createQueryBuilder("activity")
|
||||
.where("activity.data->>'actor' = :actor", {
|
||||
actor: `${config.http.base_url}/@test`,
|
||||
|
|
@ -231,8 +261,9 @@ afterAll(async () => {
|
|||
})
|
||||
);
|
||||
|
||||
if (user) {
|
||||
await user.selfDestruct();
|
||||
await user.remove();
|
||||
}
|
||||
await user.selfDestruct();
|
||||
await user.remove();
|
||||
|
||||
await user2.selfDestruct();
|
||||
await user2.remove();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue