From e30fc91fa668ff837401389c78db6b2f5392716b Mon Sep 17 00:00:00 2001 From: Ando Date: Wed, 5 Jun 2024 15:27:17 +0300 Subject: [PATCH] feat: impl test for generate filename --- tests/utils_test.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/utils_test.ts b/tests/utils_test.ts index 0d36418..9e15243 100644 --- a/tests/utils_test.ts +++ b/tests/utils_test.ts @@ -1,5 +1,5 @@ import { assert } from '../deps.ts' -import { isValidHttpUrl, getTimestamp } from '../src/utils.ts' +import { isValidHttpUrl, getTimestamp, generateFileName } from '../src/utils.ts' Deno.test('isValidHttpUrl should return true for valid HTTP URLs', () => { assert.assertEquals(isValidHttpUrl({ url: 'http://example.com' }), true) @@ -33,3 +33,17 @@ Deno.test( } ); +Deno.test( + "generateFileName should return correct filename for pdf type", + () => { + const timestamp = /^prefix_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}\.pdf$/; + assert.assert(generateFileName("prefix", "pdf").match(timestamp)); + } +); + +Deno.test("generateFileName should handle empty prefix", () => { + const tm = getTimestamp({ type: "log" }); + assert.assertEquals(generateFileName("", "log"), `_${tm}.log`); + const timestamp = /^_\d{4}-\d{2}-\d{2}\.log$/; + assert.assert(generateFileName("", "log").match(timestamp)); +});