|
1 | 1 | import { expect, test } from "vitest" |
2 | | -import { parsePath, ParsedPath, parseFilenameFromContentDisposition, parseExpiration } from "../src/shared" |
| 2 | +import { |
| 3 | + parsePath, |
| 4 | + ParsedPath, |
| 5 | + parseFilenameFromContentDisposition, |
| 6 | + parseExpiration, |
| 7 | + parseExpirationReadable, |
| 8 | +} from "../src/shared" |
3 | 9 |
|
4 | 10 | test("parsePath", () => { |
5 | 11 | const testPairs: [string, ParsedPath][] = [ |
@@ -43,29 +49,35 @@ test("parseFilenameFromContentDisposition", () => { |
43 | 49 | }) |
44 | 50 |
|
45 | 51 | test("parseExpiration", () => { |
46 | | - const testPairs: [string, number | null][] = [ |
47 | | - ["100", 100], |
48 | | - ["10.1", 10.1], |
49 | | - ["10m", 600], |
50 | | - ["10.0m", 600], |
51 | | - ["10h", 10 * 60 * 60], |
52 | | - ["10.0h", 10 * 60 * 60], |
53 | | - ["10d", 10 * 24 * 60 * 60], |
54 | | - ["10 d", 10 * 24 * 60 * 60], |
55 | | - ["10 d", 10 * 24 * 60 * 60], |
56 | | - ["10 ", 10], |
57 | | - [" 10 ", 10], |
| 52 | + const testPairs: [string, number | null, string | null][] = [ |
| 53 | + ["1", 1, "1 second"], |
| 54 | + ["1m", 60, "1 minute"], |
| 55 | + ["0.5d", 12 * 60 * 60, "0.5 day"], |
| 56 | + ["100", 100, "100 seconds"], |
| 57 | + ["10.1", 10.1, "10.1 seconds"], |
| 58 | + ["10m", 600, "10 minutes"], |
| 59 | + ["10.0m", 600, "10 minutes"], |
| 60 | + ["10h", 10 * 60 * 60, "10 hours"], |
| 61 | + ["10.0h", 10 * 60 * 60, "10 hours"], |
| 62 | + ["10d", 10 * 24 * 60 * 60, "10 days"], |
| 63 | + ["10 d", 10 * 24 * 60 * 60, "10 days"], |
| 64 | + ["10 d", 10 * 24 * 60 * 60, "10 days"], |
| 65 | + ["10 ", 10, "10 seconds"], |
| 66 | + [" 10 ", 10, "10 seconds"], |
58 | 67 |
|
59 | | - [" 10 g", null], |
60 | | - ["10g", null], |
61 | | - ["-10", null], |
62 | | - ["-10d", null], |
63 | | - ["10M", null], |
64 | | - ["10Y", null], |
65 | | - ["d", null], |
| 68 | + [" 10 g", null, null], |
| 69 | + ["10g", null, null], |
| 70 | + ["-10", null, null], |
| 71 | + ["-10d", null, null], |
| 72 | + ["10M", null, null], |
| 73 | + ["10Y", null, null], |
| 74 | + ["d", null, null], |
66 | 75 | ] |
67 | | - for (const [input, output] of testPairs) { |
68 | | - const parsed = parseExpiration(input) |
69 | | - expect(parsed, `checking expiration of ${input}`).toStrictEqual(output) |
| 76 | + for (const [input, parsed, readableParsed] of testPairs) { |
| 77 | + const expiration = parseExpiration(input) |
| 78 | + expect(expiration, `checking expiration of ${input}`).toStrictEqual(parsed) |
| 79 | + |
| 80 | + const readable = parseExpirationReadable(input) |
| 81 | + expect(readable, `checking readable expiration of ${input}`).toStrictEqual(readableParsed) |
70 | 82 | } |
71 | 83 | }) |
0 commit comments