mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(api): 🏷️ Replace API types with those from @lysand-org/client
This commit is contained in:
parent
99b8c35f7b
commit
106e34848a
81 changed files with 171 additions and 690 deletions
|
|
@ -2,10 +2,12 @@
|
|||
* @deprecated
|
||||
*/
|
||||
import { afterAll, describe, expect, test } from "bun:test";
|
||||
import type {
|
||||
Account as ApiAccount,
|
||||
Relationship as ApiRelationship,
|
||||
} from "@lysand-org/client/types";
|
||||
import { config } from "config-manager";
|
||||
import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "~/tests/utils";
|
||||
import type { Account as apiAccount } from "~/types/mastodon/account";
|
||||
import type { Relationship as apiRelationship } from "~/types/mastodon/relationship";
|
||||
|
||||
const baseUrl = config.http.base_url;
|
||||
|
||||
|
|
@ -50,7 +52,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const user = (await response.json()) as apiAccount;
|
||||
const user = (await response.json()) as ApiAccount;
|
||||
|
||||
expect(user.display_name).toBe("New Display Name");
|
||||
});
|
||||
|
|
@ -77,7 +79,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as apiAccount;
|
||||
const account = (await response.json()) as ApiAccount;
|
||||
|
||||
expect(account.username).toBe(user.data.username);
|
||||
expect(account.bot).toBe(false);
|
||||
|
|
@ -131,7 +133,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as apiRelationship;
|
||||
const account = (await response.json()) as ApiRelationship;
|
||||
|
||||
expect(account.id).toBe(user2.id);
|
||||
expect(account.followed_by).toBe(false);
|
||||
|
|
@ -162,7 +164,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as apiRelationship;
|
||||
const account = (await response.json()) as ApiRelationship;
|
||||
|
||||
expect(account.id).toBe(user2.id);
|
||||
expect(account.blocking).toBe(true);
|
||||
|
|
@ -184,7 +186,7 @@ describe("API Tests", () => {
|
|||
expect(response.headers.get("content-type")).toBe(
|
||||
"application/json",
|
||||
);
|
||||
const body = (await response.json()) as apiAccount[];
|
||||
const body = (await response.json()) as ApiAccount[];
|
||||
|
||||
expect(Array.isArray(body)).toBe(true);
|
||||
expect(body.length).toBe(1);
|
||||
|
|
@ -216,7 +218,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as apiRelationship;
|
||||
const account = (await response.json()) as ApiRelationship;
|
||||
|
||||
expect(account.id).toBe(user2.id);
|
||||
expect(account.blocking).toBe(false);
|
||||
|
|
@ -247,7 +249,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as apiRelationship;
|
||||
const account = (await response.json()) as ApiRelationship;
|
||||
|
||||
expect(account.id).toBe(user2.id);
|
||||
expect(account.endorsed).toBe(true);
|
||||
|
|
@ -278,7 +280,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as apiRelationship;
|
||||
const account = (await response.json()) as ApiRelationship;
|
||||
|
||||
expect(account.id).toBe(user2.id);
|
||||
expect(account.endorsed).toBe(false);
|
||||
|
|
@ -309,7 +311,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as apiAccount;
|
||||
const account = (await response.json()) as ApiAccount;
|
||||
|
||||
expect(account.id).toBe(user2.id);
|
||||
expect(account.note).toBe("This is a new note");
|
||||
|
|
@ -338,7 +340,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const relationships = (await response.json()) as apiRelationship[];
|
||||
const relationships = (await response.json()) as ApiRelationship[];
|
||||
|
||||
expect(Array.isArray(relationships)).toBe(true);
|
||||
expect(relationships.length).toBeGreaterThan(0);
|
||||
|
|
@ -373,7 +375,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as apiAccount;
|
||||
const account = (await response.json()) as ApiAccount;
|
||||
|
||||
expect(account.id).toBeDefined();
|
||||
expect(account.avatar).toBeDefined();
|
||||
|
|
@ -399,7 +401,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const account = (await response.json()) as apiAccount;
|
||||
const account = (await response.json()) as ApiAccount;
|
||||
|
||||
expect(account.id).toBeDefined();
|
||||
expect(account.header).toBe("");
|
||||
|
|
@ -454,7 +456,7 @@ describe("API Tests", () => {
|
|||
|
||||
const familiarFollowers = (await response.json()) as {
|
||||
id: string;
|
||||
accounts: apiAccount[];
|
||||
accounts: ApiAccount[];
|
||||
}[];
|
||||
|
||||
expect(Array.isArray(familiarFollowers)).toBe(true);
|
||||
|
|
|
|||
|
|
@ -2,20 +2,22 @@
|
|||
* @deprecated
|
||||
*/
|
||||
import { afterAll, describe, expect, test } from "bun:test";
|
||||
import type {
|
||||
AsyncAttachment as ApiAsyncAttachment,
|
||||
Context as ApiContext,
|
||||
Status as ApiStatus,
|
||||
} from "@lysand-org/client/types";
|
||||
import { config } from "config-manager";
|
||||
import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "~/tests/utils";
|
||||
import type { AsyncAttachment as apiAsyncAttachment } from "~/types/mastodon/async_attachment";
|
||||
import type { Context as apiContext } from "~/types/mastodon/context";
|
||||
import type { Status as apiStatus } from "~/types/mastodon/status";
|
||||
|
||||
const baseUrl = config.http.base_url;
|
||||
|
||||
const { users, tokens, deleteUsers } = await getTestUsers(1);
|
||||
const user = users[0];
|
||||
const token = tokens[0];
|
||||
let status: apiStatus | null = null;
|
||||
let status2: apiStatus | null = null;
|
||||
let media1: apiAsyncAttachment | null = null;
|
||||
let status: ApiStatus | null = null;
|
||||
let status2: ApiStatus | null = null;
|
||||
let media1: ApiAsyncAttachment | null = null;
|
||||
|
||||
describe("API Tests", () => {
|
||||
afterAll(async () => {
|
||||
|
|
@ -45,7 +47,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
media1 = (await response.json()) as apiAsyncAttachment;
|
||||
media1 = (await response.json()) as ApiAsyncAttachment;
|
||||
|
||||
expect(media1.id).toBeDefined();
|
||||
expect(media1.type).toBe("unknown");
|
||||
|
|
@ -78,7 +80,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
status = (await response.json()) as apiStatus;
|
||||
status = (await response.json()) as ApiStatus;
|
||||
expect(status.content).toContain("Hello, world!");
|
||||
expect(status.visibility).toBe("public");
|
||||
expect(status.account.id).toBe(user.id);
|
||||
|
|
@ -125,7 +127,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
status2 = (await response.json()) as apiStatus;
|
||||
status2 = (await response.json()) as ApiStatus;
|
||||
expect(status2.content).toContain("This is a reply!");
|
||||
expect(status2.visibility).toBe("public");
|
||||
expect(status2.account.id).toBe(user.id);
|
||||
|
|
@ -170,7 +172,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const statusJson = (await response.json()) as apiStatus;
|
||||
const statusJson = (await response.json()) as ApiStatus;
|
||||
|
||||
expect(statusJson.id).toBe(status?.id || "");
|
||||
expect(statusJson.content).toBeDefined();
|
||||
|
|
@ -220,7 +222,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const rebloggedStatus = (await response.json()) as apiStatus;
|
||||
const rebloggedStatus = (await response.json()) as ApiStatus;
|
||||
|
||||
expect(rebloggedStatus.id).toBeDefined();
|
||||
expect(rebloggedStatus.reblog?.id).toEqual(status?.id ?? "");
|
||||
|
|
@ -250,7 +252,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const unrebloggedStatus = (await response.json()) as apiStatus;
|
||||
const unrebloggedStatus = (await response.json()) as ApiStatus;
|
||||
|
||||
expect(unrebloggedStatus.id).toBeDefined();
|
||||
expect(unrebloggedStatus.reblogged).toBe(false);
|
||||
|
|
@ -278,7 +280,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const context = (await response.json()) as apiContext;
|
||||
const context = (await response.json()) as ApiContext;
|
||||
|
||||
expect(context.ancestors.length).toBe(0);
|
||||
expect(context.descendants.length).toBe(1);
|
||||
|
|
@ -310,7 +312,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const statuses = (await response.json()) as apiStatus[];
|
||||
const statuses = (await response.json()) as ApiStatus[];
|
||||
|
||||
expect(statuses.length).toBe(2);
|
||||
|
||||
|
|
@ -367,7 +369,7 @@ describe("API Tests", () => {
|
|||
"application/json",
|
||||
);
|
||||
|
||||
const updatedStatus = (await response.json()) as apiStatus;
|
||||
const updatedStatus = (await response.json()) as ApiStatus;
|
||||
|
||||
expect(updatedStatus.favourited).toBe(false);
|
||||
expect(updatedStatus.favourites_count).toBe(0);
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
* @deprecated
|
||||
*/
|
||||
import { afterAll, describe, expect, test } from "bun:test";
|
||||
import type {
|
||||
Application as ApiApplication,
|
||||
Token as ApiToken,
|
||||
} from "@lysand-org/client/types";
|
||||
import { config } from "~/packages/config-manager";
|
||||
import type { Application as apiApplication } from "~/types/mastodon/application";
|
||||
import type { Token as apiToken } from "~/types/mastodon/token";
|
||||
import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "./utils";
|
||||
|
||||
const baseUrl = config.http.base_url;
|
||||
|
|
@ -13,7 +15,7 @@ let clientId: string;
|
|||
let clientSecret: string;
|
||||
let code: string;
|
||||
let jwt: string;
|
||||
let token: apiToken;
|
||||
let token: ApiToken;
|
||||
const { users, passwords, deleteUsers } = await getTestUsers(1);
|
||||
|
||||
afterAll(async () => {
|
||||
|
|
@ -178,7 +180,7 @@ describe("GET /api/v1/apps/verify_credentials", () => {
|
|||
expect(response.status).toBe(200);
|
||||
expect(response.headers.get("content-type")).toBe("application/json");
|
||||
|
||||
const credentials = (await response.json()) as Partial<apiApplication>;
|
||||
const credentials = (await response.json()) as Partial<ApiApplication>;
|
||||
|
||||
expect(credentials.name).toBe("Test Application");
|
||||
expect(credentials.website).toBe("https://example.com");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue