48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { describe, it, expect, beforeAll, afterAll, beforeEach } from "vitest";
|
|
import type { FastifyInstance } from "fastify";
|
|
import { createTestApp, cleanDb } from "./helpers.js";
|
|
import { db } from "../src/db/index.js";
|
|
import { packages } from "../src/db/schema.js";
|
|
|
|
let app: FastifyInstance;
|
|
|
|
beforeAll(async () => {
|
|
app = await createTestApp();
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await app.close();
|
|
});
|
|
|
|
beforeEach(async () => {
|
|
await cleanDb();
|
|
});
|
|
|
|
describe("GET /packages", () => {
|
|
it("returns empty list when no packages exist", async () => {
|
|
const res = await app.inject({ method: "GET", url: "/packages" });
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
expect(res.json()).toEqual([]);
|
|
});
|
|
|
|
it("returns seeded packages", async () => {
|
|
await db.insert(packages).values([
|
|
{ slug: "small", name: "Small", vcpu: 1, ram: 1024, disk: 20, priceMonthly: "5.00" },
|
|
{ slug: "medium", name: "Medium", vcpu: 2, ram: 2048, disk: 40, priceMonthly: "10.00" },
|
|
]);
|
|
|
|
const res = await app.inject({ method: "GET", url: "/packages" });
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
const body = res.json();
|
|
expect(body).toHaveLength(2);
|
|
expect(body.map((p: { slug: string }) => p.slug).sort()).toEqual(["medium", "small"]);
|
|
});
|
|
|
|
it("does not require authentication", async () => {
|
|
const res = await app.inject({ method: "GET", url: "/packages" });
|
|
expect(res.statusCode).toBe(200);
|
|
});
|
|
});
|