61 lines
1.4 KiB
TypeScript
61 lines
1.4 KiB
TypeScript
import { expect, test } from "vitest";
|
|
|
|
import type { RoomDetail } from "$lib/shared/model";
|
|
|
|
import {
|
|
deleteRoom,
|
|
getRoom,
|
|
getRoomNPatients,
|
|
getRooms,
|
|
getStation,
|
|
hideRoom,
|
|
newRoom,
|
|
updateStation,
|
|
} from "$lib/server/query";
|
|
import {
|
|
ROOMS, S1,
|
|
} from "$tests/helpers/testdata";
|
|
|
|
test("create room", async () => {
|
|
const rId = await newRoom({ name: "A1", station_id: 1 });
|
|
const room = await getRoom(rId);
|
|
expect(room).toStrictEqual({
|
|
id: rId,
|
|
name: "A1",
|
|
station: S1,
|
|
hidden: false,
|
|
} satisfies RoomDetail);
|
|
});
|
|
|
|
test("update room", 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 room", async () => {
|
|
await deleteRoom(ROOMS[3].id);
|
|
await expect(async () => getRoom(ROOMS[3].id)).rejects.toThrowError("No Room found");
|
|
});
|
|
|
|
test("hide room", async () => {
|
|
await hideRoom(ROOMS[0].id, true);
|
|
const rs1 = await getRooms();
|
|
const exp = [...ROOMS];
|
|
exp.splice(0, 1);
|
|
expect(rs1).toStrictEqual(exp);
|
|
await hideRoom(ROOMS[0].id, false);
|
|
const rs2 = await getRooms();
|
|
expect(rs2).toStrictEqual(ROOMS);
|
|
});
|
|
|
|
test("get rooms", async () => {
|
|
const rooms = await getRooms();
|
|
expect(rooms).toStrictEqual(ROOMS);
|
|
});
|
|
|
|
test("get room n patients", async () => {
|
|
expect(await getRoomNPatients(ROOMS[0].id)).toBe(1);
|
|
});
|