From fc3d37644789407f89a862c7225ee3912c2009a2 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Wed, 29 May 2024 18:19:55 +1000 Subject: [PATCH] test(uuid): add tests for invalid namespace UUID (#4875) --- uuid/v3_test.ts | 15 ++++++++++++++- uuid/v5_test.ts | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/uuid/v3_test.ts b/uuid/v3_test.ts index 300891160..466dbb35f 100644 --- a/uuid/v3_test.ts +++ b/uuid/v3_test.ts @@ -1,5 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "@std/assert"; +import { + assert, + assertEquals, + AssertionError, + assertRejects, +} from "@std/assert"; import { generate, validate } from "./v3.ts"; const NAMESPACE = "1b671a64-40d5-491e-99b0-da01ff1f3341"; @@ -37,3 +42,11 @@ Deno.test("validate() checks if a string is a valid v3 UUID", async () => { assert(validate(t), `${t} should be valid`); assert(!validate(n), `${n} should not be valid`); }); + +Deno.test("generate() throws on invalid namespace", async () => { + await assertRejects( + async () => await generate("invalid-uuid", new Uint8Array()), + AssertionError, + "namespace must be a valid UUID", + ); +}); diff --git a/uuid/v5_test.ts b/uuid/v5_test.ts index a33e9149a..81b66546a 100644 --- a/uuid/v5_test.ts +++ b/uuid/v5_test.ts @@ -1,5 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { assert, assertEquals } from "@std/assert"; +import { + assert, + assertEquals, + AssertionError, + assertRejects, +} from "@std/assert"; import { generate, validate } from "./v5.ts"; const NAMESPACE = "1b671a64-40d5-491e-99b0-da01ff1f3341"; @@ -37,3 +42,11 @@ Deno.test("validate() checks if a string is a valid v5 UUID", async () => { assert(validate(t), `${t} should be valid`); assert(!validate(n), `${n} should not be valid`); }); + +Deno.test("generate() throws on invalid namespace", async () => { + await assertRejects( + async () => await generate("invalid-uuid", new Uint8Array()), + AssertionError, + "namespace must be a valid UUID", + ); +});