mirror of
https://github.com/rjNemo/deno_hello
synced 2026-06-06 01:56:40 +00:00
ix: validation error
This commit is contained in:
parent
25e8826d3c
commit
664e62b1b1
2 changed files with 3 additions and 8 deletions
|
|
@ -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`);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue