2024-05-13 04:09:57 +02:00
|
|
|
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
|
|
|
|
2024-03-11 03:04:14 +01: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
|
|
|
});
|
|
|
|
|
|
2024-05-13 01:21:06 +02:00
|
|
|
test("Try sending FormData without a boundary", async () => {
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append("test", "test");
|
|
|
|
|
|
|
|
|
|
const response = await sendTestRequest(
|
|
|
|
|
new Request(
|
2024-05-13 23:48:58 +02:00
|
|
|
wrapRelativeUrl(`${base_url}/api/v1/statuses`, base_url),
|
2024-05-13 01:21:06 +02:00
|
|
|
{
|
2024-05-13 23:48:58 +02:00
|
|
|
method: "POST",
|
2024-05-13 01:21:06 +02:00
|
|
|
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");
|
|
|
|
|
});
|
2024-05-17 21:38:38 +02:00
|
|
|
|
|
|
|
|
test("try sending a request with a different origin", async () => {
|
|
|
|
|
if (new URL(config.http.base_url).protocol === "http:") {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const response = await sendTestRequest(
|
|
|
|
|
new Request(
|
|
|
|
|
new URL(
|
|
|
|
|
"/api/v1/instance",
|
|
|
|
|
base_url.replace("https://", "http://"),
|
|
|
|
|
),
|
|
|
|
|
{
|
|
|
|
|
method: "GET",
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: `Bearer ${tokens[0].accessToken}`,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(response.status).toBe(400);
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
expect(data.error).toContain("does not match base URL");
|
|
|
|
|
});
|
2023-09-22 00:42:59 +02:00
|
|
|
});
|