server/tests/api.test.ts

39 lines
1.2 KiB
TypeScript
Raw Normal View History

import { afterAll, 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 { 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
});
test("Try sending FormData without a boundary", async () => {
const formData = new FormData();
formData.append("test", "test");
const response = await sendTestRequest(
new Request(
wrapRelativeUrl(`${base_url}/api/v1/custom_emojis`, base_url),
{
method: "GET",
headers: {
Authorization: `Bearer ${tokens[0].accessToken}`,
"Content-Type": "multipart/form-data",
},
body: formData,
},
),
);
expect(response.status).toBe(400);
const data = await response.json();
expect(data.error).toBeString();
expect(data.error).toContain("https://stackoverflow.com");
});
2023-09-22 00:42:59 +02:00
});