refactor(api): 🔥 Remove old @versia/client version

This commit is contained in:
Jesse Wierzbinski 2025-03-22 18:04:47 +01:00
parent 54e282b03c
commit 8d1af1b0cd
No known key found for this signature in database
121 changed files with 649 additions and 756 deletions

View file

@ -2,10 +2,8 @@
* @deprecated
*/
import { afterAll, describe, expect, test } from "bun:test";
import type {
Account as ApiAccount,
Relationship as ApiRelationship,
} from "@versia/client/types";
import type { z } from "@hono/zod-openapi";
import type { Account, Relationship } from "@versia/client/schemas";
import { config } from "~/config.ts";
import { fakeRequest, getTestUsers } from "~/tests/utils";
@ -47,7 +45,7 @@ describe("API Tests", () => {
"application/json",
);
const user = (await response.json()) as ApiAccount;
const user = (await response.json()) as z.infer<typeof Account>;
expect(user.display_name).toBe("New Display Name");
});
@ -69,7 +67,7 @@ describe("API Tests", () => {
"application/json",
);
const account = (await response.json()) as ApiAccount;
const account = (await response.json()) as z.infer<typeof Account>;
expect(account.username).toBe(user.data.username);
expect(account.bot).toBe(false);
@ -118,7 +116,9 @@ describe("API Tests", () => {
"application/json",
);
const account = (await response.json()) as ApiRelationship;
const account = (await response.json()) as z.infer<
typeof Relationship
>;
expect(account.id).toBe(user2.id);
expect(account.followed_by).toBe(false);
@ -144,7 +144,9 @@ describe("API Tests", () => {
"application/json",
);
const account = (await response.json()) as ApiRelationship;
const account = (await response.json()) as z.infer<
typeof Relationship
>;
expect(account.id).toBe(user2.id);
expect(account.blocking).toBe(true);
@ -164,7 +166,7 @@ describe("API Tests", () => {
expect(response.headers.get("content-type")).toContain(
"application/json",
);
const body = (await response.json()) as ApiAccount[];
const body = (await response.json()) as z.infer<typeof Account>[];
expect(Array.isArray(body)).toBe(true);
expect(body.length).toBe(1);
@ -191,7 +193,9 @@ describe("API Tests", () => {
"application/json",
);
const account = (await response.json()) as ApiRelationship;
const account = (await response.json()) as z.infer<
typeof Relationship
>;
expect(account.id).toBe(user2.id);
expect(account.blocking).toBe(false);
@ -217,7 +221,9 @@ describe("API Tests", () => {
"application/json",
);
const account = (await response.json()) as ApiRelationship;
const account = (await response.json()) as z.infer<
typeof Relationship
>;
expect(account.id).toBe(user2.id);
expect(account.endorsed).toBe(true);
@ -243,7 +249,9 @@ describe("API Tests", () => {
"application/json",
);
const account = (await response.json()) as ApiRelationship;
const account = (await response.json()) as z.infer<
typeof Relationship
>;
expect(account.id).toBe(user2.id);
expect(account.endorsed).toBe(false);
@ -269,7 +277,7 @@ describe("API Tests", () => {
"application/json",
);
const account = (await response.json()) as ApiAccount;
const account = (await response.json()) as z.infer<typeof Account>;
expect(account.id).toBe(user2.id);
expect(account.note).toBe("This is a new note");
@ -293,7 +301,9 @@ describe("API Tests", () => {
"application/json",
);
const relationships = (await response.json()) as ApiRelationship[];
const relationships = (await response.json()) as z.infer<
typeof Relationship
>[];
expect(Array.isArray(relationships)).toBe(true);
expect(relationships.length).toBeGreaterThan(0);
@ -323,7 +333,7 @@ describe("API Tests", () => {
"application/json",
);
const account = (await response.json()) as ApiAccount;
const account = (await response.json()) as z.infer<typeof Account>;
expect(account.id).toBeDefined();
expect(account.avatar).toBeDefined();
@ -344,7 +354,7 @@ describe("API Tests", () => {
"application/json",
);
const account = (await response.json()) as ApiAccount;
const account = (await response.json()) as z.infer<typeof Account>;
expect(account.id).toBeDefined();
expect(account.header).toBe("");
@ -389,7 +399,7 @@ describe("API Tests", () => {
const familiarFollowers = (await response.json()) as {
id: string;
accounts: ApiAccount[];
accounts: z.infer<typeof Account>[];
}[];
expect(Array.isArray(familiarFollowers)).toBe(true);

View file

@ -2,19 +2,16 @@
* @deprecated
*/
import { afterAll, describe, expect, test } from "bun:test";
import type {
AsyncAttachment as ApiAsyncAttachment,
Context as ApiContext,
Status as ApiStatus,
} from "@versia/client/types";
import type { z } from "@hono/zod-openapi";
import type { Attachment, Context, Status } from "@versia/client/schemas";
import { fakeRequest, getTestUsers } from "~/tests/utils";
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: z.infer<typeof Status> | null = null;
let status2: z.infer<typeof Status> | null = null;
let media1: z.infer<typeof Attachment> | null = null;
describe("API Tests", () => {
afterAll(async () => {
@ -39,7 +36,7 @@ describe("API Tests", () => {
"application/json",
);
media1 = (await response.json()) as ApiAsyncAttachment;
media1 = (await response.json()) as z.infer<typeof Attachment>;
expect(media1.id).toBeDefined();
expect(media1.type).toBe("unknown");
@ -67,7 +64,7 @@ describe("API Tests", () => {
"application/json",
);
status = (await response.json()) as ApiStatus;
status = (await response.json()) as z.infer<typeof Status>;
expect(status.content).toContain("Hello, world!");
expect(status.visibility).toBe("public");
expect(status.account.id).toBe(user.id);
@ -109,7 +106,7 @@ describe("API Tests", () => {
"application/json",
);
status2 = (await response.json()) as ApiStatus;
status2 = (await response.json()) as z.infer<typeof Status>;
expect(status2.content).toContain("This is a reply!");
expect(status2.visibility).toBe("public");
expect(status2.account.id).toBe(user.id);
@ -149,7 +146,9 @@ describe("API Tests", () => {
"application/json",
);
const statusJson = (await response.json()) as ApiStatus;
const statusJson = (await response.json()) as z.infer<
typeof Status
>;
expect(statusJson.id).toBe(status?.id || "");
expect(statusJson.content).toBeDefined();
@ -194,7 +193,9 @@ describe("API Tests", () => {
"application/json",
);
const rebloggedStatus = (await response.json()) as ApiStatus;
const rebloggedStatus = (await response.json()) as z.infer<
typeof Status
>;
expect(rebloggedStatus.id).toBeDefined();
expect(rebloggedStatus.reblog?.id).toEqual(status?.id ?? "");
@ -219,7 +220,9 @@ describe("API Tests", () => {
"application/json",
);
const unrebloggedStatus = (await response.json()) as ApiStatus;
const unrebloggedStatus = (await response.json()) as z.infer<
typeof Status
>;
expect(unrebloggedStatus.id).toBeDefined();
expect(unrebloggedStatus.reblogged).toBe(false);
@ -242,7 +245,7 @@ describe("API Tests", () => {
"application/json",
);
const context = (await response.json()) as ApiContext;
const context = (await response.json()) as z.infer<typeof Context>;
expect(context.ancestors.length).toBe(0);
expect(context.descendants.length).toBe(1);
@ -269,7 +272,9 @@ describe("API Tests", () => {
"application/json",
);
const statuses = (await response.json()) as ApiStatus[];
const statuses = (await response.json()) as z.infer<
typeof Status
>[];
expect(statuses.length).toBe(2);
@ -316,7 +321,9 @@ describe("API Tests", () => {
"application/json",
);
const updatedStatus = (await response.json()) as ApiStatus;
const updatedStatus = (await response.json()) as z.infer<
typeof Status
>;
expect(updatedStatus.favourited).toBe(false);
expect(updatedStatus.favourites_count).toBe(0);

View file

@ -2,17 +2,15 @@
* @deprecated
*/
import { afterAll, describe, expect, test } from "bun:test";
import type {
Application as ApiApplication,
Token as ApiToken,
} from "@versia/client/types";
import type { z } from "@hono/zod-openapi";
import type { Application, Token } from "@versia/client/schemas";
import { fakeRequest, getTestUsers } from "./utils.ts";
let clientId: string;
let clientSecret: string;
let code: string;
let jwt: string;
let token: ApiToken;
let token: z.infer<typeof Token>;
const { users, passwords, deleteUsers } = await getTestUsers(1);
afterAll(async () => {
@ -168,7 +166,9 @@ describe("GET /api/v1/apps/verify_credentials", () => {
"application/json",
);
const credentials = (await response.json()) as Partial<ApiApplication>;
const credentials = (await response.json()) as Partial<
z.infer<typeof Application>
>;
expect(credentials.name).toBe("Test Application");
expect(credentials.website).toBe("https://example.com");

View file

@ -1,6 +1,6 @@
import { generateChallenge } from "@/challenges";
import { randomString } from "@/math";
import { Client as VersiaClient } from "@versia/client-ng";
import { Client as VersiaClient } from "@versia/client";
import { Note, Token, User, db } from "@versia/kit/db";
import { Notes, Users } from "@versia/kit/tables";
import { solveChallenge } from "altcha-lib";