test(api): cover assistant metro city mutations

This commit is contained in:
2026-04-01 00:26:53 +02:00
parent c88f2342d5
commit 1a9212fa5f
2 changed files with 185 additions and 0 deletions
@@ -0,0 +1,68 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { executeTool } from "../router/assistant-tools.js";
import { createToolContext } from "./assistant-tools-country-test-helpers.js";
describe("assistant metro city mutation tools - errors", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("returns a stable error when creating a metro city for a missing country", async () => {
const ctx = createToolContext({
country: {
findUnique: vi.fn().mockResolvedValue(null),
},
});
const result = await executeTool(
"create_metro_city",
JSON.stringify({ countryId: "country_missing", name: "Munich" }),
ctx,
);
expect(JSON.parse(result.content)).toEqual({
error: "Country not found with the given criteria.",
});
});
it("returns a stable error when updating a missing metro city", async () => {
const ctx = createToolContext({
metroCity: {
findUnique: vi.fn().mockResolvedValue(null),
},
});
const result = await executeTool(
"update_metro_city",
JSON.stringify({ id: "city_missing", data: { name: "Hamburg-Mitte" } }),
ctx,
);
expect(JSON.parse(result.content)).toEqual({
error: "Metro city not found with the given criteria.",
});
});
it("returns a stable error when deleting a metro city that is still assigned", async () => {
const ctx = createToolContext({
metroCity: {
findUnique: vi.fn().mockResolvedValue({
id: "city_ham",
name: "Hamburg",
_count: { resources: 3 },
}),
},
});
const result = await executeTool(
"delete_metro_city",
JSON.stringify({ id: "city_ham" }),
ctx,
);
expect(JSON.parse(result.content)).toEqual({
error: "Metro city cannot be deleted while it is still assigned to resources.",
});
});
});