From 664e62b1b1b71d83e4ce366ae9e7a44b80e13a06 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Fri, 19 Feb 2021 15:36:43 +0100 Subject: [PATCH] ix: validation error --- src/types/id.test.ts | 9 ++------- src/types/id.ts | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/types/id.test.ts b/src/types/id.test.ts index 2a0953f..915c880 100644 --- a/src/types/id.test.ts +++ b/src/types/id.test.ts @@ -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`); }); diff --git a/src/types/id.ts b/src/types/id.ts index 1a1335e..e77eeea 100644 --- a/src/types/id.ts +++ b/src/types/id.ts @@ -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)) {