2025-03-22 18:04:47 +01:00
|
|
|
import type { Status } from "@versia/client/schemas";
|
2025-06-15 22:17:33 +02:00
|
|
|
import {
|
|
|
|
|
fakeRequest,
|
|
|
|
|
getTestStatuses,
|
|
|
|
|
getTestUsers,
|
|
|
|
|
} from "@versia-server/tests";
|
2024-11-10 15:24:34 +01:00
|
|
|
import { bench, run } from "mitata";
|
2025-03-29 03:30:06 +01:00
|
|
|
import type { z } from "zod";
|
2024-11-10 13:08:43 +01:00
|
|
|
|
|
|
|
|
const { users, tokens, deleteUsers } = await getTestUsers(5);
|
|
|
|
|
await getTestStatuses(40, users[0]);
|
|
|
|
|
|
|
|
|
|
const testTimeline = async (): Promise<void> => {
|
|
|
|
|
const response = await fakeRequest("/api/v1/timelines/home", {
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: `Bearer ${tokens[0].data.accessToken}`,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2025-03-22 18:04:47 +01:00
|
|
|
const objects = (await response.json()) as z.infer<typeof Status>[];
|
2024-11-10 13:08:43 +01:00
|
|
|
|
|
|
|
|
if (objects.length !== 20) {
|
|
|
|
|
throw new Error("Invalid response (not 20 objects)");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const testInstance = async (): Promise<void> => {
|
|
|
|
|
const response = await fakeRequest("/api/v2/instance", {
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: `Bearer ${tokens[0].data.accessToken}`,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const object = (await response.json()) as Record<string, unknown>;
|
|
|
|
|
|
|
|
|
|
if (typeof object !== "object") {
|
|
|
|
|
throw new Error("Invalid response (not an object)");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bench("timeline", testTimeline).range("amount", 1, 1000);
|
|
|
|
|
bench("instance", testInstance).range("amount", 1, 1000);
|
|
|
|
|
|
|
|
|
|
await run();
|
|
|
|
|
|
|
|
|
|
await deleteUsers();
|