ix: validation error

This commit is contained in:
Ruidy 2021-02-19 15:36:43 +01:00
parent 25e8826d3c
commit 664e62b1b1
2 changed files with 3 additions and 8 deletions

View file

@ -1,16 +1,11 @@
import { assertThrows } from "https://deno.land/std@0.87.0/testing/asserts.ts";
import { localesSize } from "../repositories/locales.ts";
import { ID } from "./id.ts";
import { ValidationError } from "../errors/exceptions.ts";
import { ID } from "./id.ts";
Deno.test("ID validation fails for non strictly positive values", () => {
assertThrows(() => new ID(-1), ValidationError, "Invalid index: -1");
});
Deno.test("Hello fails for too large values", () => {
assertThrows(
() => new ID(localesSize),
ValidationError,
`Invalid index: ${localesSize}`,
);
assertThrows(() => new ID(666), ValidationError, `Invalid index: 666`);
});

View file

@ -10,7 +10,7 @@ export class ID {
this.#validate(value);
}
#idIsValid = (id: number) => id > 0 && id < localesSize;
#idIsValid = (id: number) => id > 0 && id <= localesSize;
#validate = (id: number) => {
if (!this.#idIsValid(id)) {