import { beforeAll, expect, test } from "vitest" import { fetchAPI } from "../../src/Fetcher" import { saveSession } from "../../src/api/session" async function login() { const response = await fetchAPI("auth/token/", { email: "maxime@mail.com", password: "123456", }) expect(response.status).toBe(200) const { token, expirationDate } = await response.json() saveSession({ auth: { token, expirationDate: Date.parse(expirationDate) } }) } beforeAll(login) test("create tactic", async () => { await login() const response = await fetchAPI("tactics", { courtType: "PLAIN", name: "test tactic", }) expect(response.status).toBe(200) }) test("spam step creation test", async () => { const createTacticResponse = await fetchAPI("tactics", { courtType: "PLAIN", name: "test tactic", }) expect(createTacticResponse.status).toBe(200) const { id } = await createTacticResponse.json() const tasks = Array.from({ length: 200 }).map(async () => { const response = await fetchAPI(`tactics/${id}/steps`, { parentId: 1, content: { components: [] }, }) expect(response.status).toBe(200) const { stepId } = await response.json() return stepId }) const steps = [] for (const task of tasks) { steps.push(await task) } steps.sort((a, b) => a - b) const expected = Array.from({ length: 200 }, (_, i) => i + 2) expect(steps).toEqual(expected) })