Visitenbuch/tests/integration/query/station.ts
2024-05-14 00:40:10 +02:00

47 lines
1.4 KiB
TypeScript

import { expect, test } from "vitest";
import type { StationDetail } from "$lib/shared/model";
import {
deleteStation, getStation, getStationNRooms, getStations, hideStation, newStation, updateStation,
} from "$lib/server/query";
import {
STATIONS, S1, S2, S3,
} from "$tests/helpers/testdata";
test("create station", async () => {
const sId = await newStation({ name: "S3" });
const station = await getStation(sId);
expect(station).toStrictEqual({ id: sId, name: "S3", hidden: false } satisfies StationDetail);
});
test("update station", async () => {
const name = "HelloStation";
await updateStation(S1.id, { name });
const station = await getStation(S1.id);
expect(station.id).toBe(S1.id);
expect(station.name).toBe(name);
});
test("delete station", async () => {
await deleteStation(S3.id);
await expect(async () => getStation(S3.id)).rejects.toThrowError("No Station found");
});
test("hide station", async () => {
await hideStation(S1.id, true);
const cs1 = await getStations();
expect(cs1).toStrictEqual([S2, S3]);
await hideStation(S1.id, false);
const cs2 = await getStations();
expect(cs2).toStrictEqual(STATIONS);
});
test("get stations", async () => {
const stations = await getStations();
expect(stations).toStrictEqual(STATIONS);
});
test("get station n rooms", async () => {
expect(await getStationNRooms(1)).toBe(2);
});