import { expect, test } from "vitest"; import { caller } from "$tests/helpers/trpc"; const TEST_VERSION = { category_id: 1, text: "10ml Blut abnehmen", date: "2024-01-01", priority: false, }; test("create entry", async () => { const eID = await caller().entry.create({ patient_id: 1, version: TEST_VERSION, }); expect(eID).gt(0); const entry = await caller().entry.get(eID); expect(entry.patient.id).toBe(1); expect(entry.execution).toBeNull(); expect(entry.current_version.id).gt(0); expect(entry.current_version.category?.id).toBe(TEST_VERSION.category_id); expect(entry.current_version.category?.name).toBe("Laborabnahme"); expect(entry.current_version.text).toBe(TEST_VERSION.text); expect(new Date(entry.current_version.date)).toStrictEqual( new Date(TEST_VERSION.date), ); expect(entry.current_version.priority).toBe(TEST_VERSION.priority); }); test("create entry version", async () => { const eID = await caller().entry.create({ patient_id: 1, version: TEST_VERSION, }); const text = "10ml Blut abnehmen\n\nPS: Nadel nicht vergessen"; const date = "2024-01-02"; const nv = await caller().entry.newVersion({ id: eID, version: { date, text, category_id: 2, priority: true, }, }); const entry = await caller().entry.get(eID); const expectedVersion = { id: nv, author: { id: 1 }, date, text, category: { id: 2 }, priority: true, }; expect(entry.current_version).toMatchObject(expectedVersion); const history = await caller().entry.versions(eID); expect(history).length(2); expect(history[0]).toMatchObject(expectedVersion); expect(history[1].text).toBe(TEST_VERSION.text); expect(history[0].created_at).greaterThan(history[1].created_at); });