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

41 lines
1.1 KiB
TypeScript

import { expect, test } from "vitest";
import {
deleteCategory, getCategories, getCategory, hideCategory, newCategory,
} from "$lib/server/query";
import { CATEGORIES } from "$tests/helpers/testdata";
test("create category", async () => {
const data = {
name: "Test",
description: "Hello World",
color: "AABB01",
};
const cId = await newCategory(data);
expect(cId).gt(0);
const category = await getCategory(cId);
expect(category).toMatchObject(data);
expect(category.id).toBe(cId);
});
test("get categories", async () => {
const categories = await getCategories();
expect(categories).toStrictEqual(CATEGORIES);
});
test("delete categories", async () => {
await deleteCategory(6);
await expect(getCategory(6)).rejects.toThrowError("No Category found");
});
test("hide category", async () => {
await hideCategory(1, true);
const cs1 = await getCategories();
const exp = [...CATEGORIES];
exp.splice(0, 1);
expect(cs1).toStrictEqual(exp);
await hideCategory(1, false);
const cs2 = await getCategories();
expect(cs2).toStrictEqual(CATEGORIES);
});