MEGAINFRA-WEBAPP/src/lib/site-map/keys.test.ts

26 lines
1.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { expectedKeys as expected, fixture } from "./__fixtures__/mini-model";
import { modelKeyIndex, validateEvent } from "./keys";
describe("modelKeyIndex", () => {
it("lists exactly the expected keys (same list the Python upload script checks)", () => {
expect([...modelKeyIndex(fixture).keys()].sort()).toEqual(expected);
});
});
describe("validateEvent", () => {
const index = modelKeyIndex(fixture);
it.each([
["road:ch240-260:asphalt:roadbed", 1], ["kerb:ch240-260", 55], ["peg:BJ1", 2], ["swpipe:KI1-1>MH1-2", 2],
["earth:240-250", 50], ["sign:R2.1", 2], ["stud:White/red", 0], ["paint", 1],
])("accepts %s = %s", (key, value) => expect(validateEvent(index, key, value)).toBeNull());
it.each([
["road:ch240-260:asphalt:roadbed", 2, "must be one of 0, 1"],
["kerb:ch240-260", 101, "must be between 0 and 100"],
["earth:240-250", 30, "must be one of 0, 50, 100"],
["sign:R2.1", 3, "must be a whole number between 0 and 2"],
["sign:R2.1", 1.5, "must be a whole number between 0 and 2"],
["peg:BJ1", "2", "must be a number"],
["peg:NOPE", 1, "is not part of this site's model"],
])("rejects %s = %s", (key, value, message) => expect(validateEvent(index, key, value)).toContain(message));
});