Skip to content

Commit

Permalink
feat: impl test for generate filename
Browse files Browse the repository at this point in the history
  • Loading branch information
Ando committed Jun 5, 2024
1 parent b0095cf commit e30fc91
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tests/utils_test.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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));
});

0 comments on commit e30fc91

Please sign in to comment.