server/tests/api.test.ts

64 lines
2 KiB
TypeScript
Raw Normal View History

/**
* @deprecated
*/
2023-09-22 00:42:59 +02:00
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2024-04-07 06:16:54 +02:00
import { config } from "config-manager";
2024-04-14 02:46:33 +02:00
import { eq } from "drizzle-orm";
import { db } from "~drizzle/db";
import { Emojis } from "~drizzle/schema";
2024-04-14 12:53:21 +02:00
import type { Emoji as APIEmoji } from "~types/mastodon/emoji";
2024-04-14 02:46:33 +02:00
import { getTestUsers, sendTestRequest, wrapRelativeUrl } from "./utils";
2023-09-22 00:42:59 +02:00
const base_url = config.http.base_url;
2023-09-22 00:42:59 +02:00
2024-04-14 02:46:33 +02:00
const { tokens, deleteUsers } = await getTestUsers(1);
2023-09-22 00:42:59 +02:00
2023-10-18 02:57:47 +02:00
describe("API Tests", () => {
2024-04-07 07:30:49 +02:00
afterAll(async () => {
2024-04-14 02:46:33 +02:00
await deleteUsers();
2024-04-07 07:30:49 +02:00
});
describe("GET /api/v1/custom_emojis", () => {
beforeAll(async () => {
await db.insert(Emojis).values({
2024-04-14 02:46:33 +02:00
shortcode: "test",
url: "https://example.com/test.png",
contentType: "image/png",
visibleInPicker: true,
2024-04-07 07:30:49 +02:00
});
});
test("should return an array of at least one custom emoji", async () => {
const response = await sendTestRequest(
new Request(
wrapRelativeUrl(
`${base_url}/api/v1/custom_emojis`,
base_url,
),
{
method: "GET",
headers: {
2024-04-14 02:46:33 +02:00
Authorization: `Bearer ${tokens[0].accessToken}`,
2024-04-07 07:30:49 +02:00
},
},
),
);
expect(response.status).toBe(200);
expect(response.headers.get("content-type")).toBe(
"application/json",
);
const emojis = (await response.json()) as APIEmoji[];
expect(emojis.length).toBeGreaterThan(0);
expect(emojis[0].shortcode).toBeString();
expect(emojis[0].url).toBeString();
});
afterAll(async () => {
await db.delete(Emojis).where(eq(Emojis.shortcode, "test"));
2024-04-07 07:30:49 +02:00
});
});
2023-09-22 00:42:59 +02:00
});