Skip to content

Commit 3b77192

Browse files
author
Arpith Siromoney
committed
Fix test data dates and handle Date.now() fallback test
Corrects test dates from 2025 to 2024 to match expected timestamps. Also updates articleUtils.test.js to properly handle the invalid date test case that uses Date.now() as fallback (dynamic timestamp).
1 parent c3e9ad5 commit 3b77192

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/lib/articleUtils.test.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,15 @@ testCases.hash_function_tests.forEach((testCase) => {
4242
testCases.score_function_tests.forEach((testCase) => {
4343
test(testCase.description, () => {
4444
const result = score(testCase.input);
45-
assert.strictEqual(result, testCase.expected,
46-
`Score mismatch: got ${result}, expected ${testCase.expected}`);
45+
if (testCase.expected_type === 'timestamp') {
46+
// For invalid dates that fallback to Date.now(), just check it's a number
47+
assert.strictEqual(typeof result, 'number',
48+
`Score should be a number: got ${typeof result}`);
49+
assert.ok(result > 0, `Score should be positive: got ${result}`);
50+
} else {
51+
assert.strictEqual(result, testCase.expected,
52+
`Score mismatch: got ${result}, expected ${testCase.expected}`);
53+
}
4754
});
4855
});
4956

testdata/test-cases.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ hash_function_tests:
2020
score_function_tests:
2121
- description: "Score with pubDate"
2222
input:
23-
pubDate: "2025-10-10T00:00:00Z"
23+
pubDate: "2024-10-10T00:00:00Z"
2424
expected: 1728518400000
2525

2626
- description: "Score with alternative date field 'pubdate'"
2727
input:
28-
pubdate: "2025-10-08T00:00:00Z"
28+
pubdate: "2024-10-08T00:00:00Z"
2929
expected: 1728345600000
3030

3131
- description: "Score with alternative date field 'date'"
3232
input:
33-
date: "2025-10-06T00:00:00Z"
33+
date: "2024-10-06T00:00:00Z"
3434
expected: 1728172800000
3535

3636
- description: "Score with invalid date falls back to Date.now()"
@@ -46,10 +46,10 @@ request_headers_tests:
4646

4747
- description: "Headers with lastModified"
4848
input:
49-
lastModified: "Wed, 09 Oct 2025 12:00:00 GMT"
49+
lastModified: "Wed, 09 Oct 2024 12:00:00 GMT"
5050
expected:
5151
user-agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36"
52-
If-Modified-Since: "Wed, 09 Oct 2025 12:00:00 GMT"
52+
If-Modified-Since: "Wed, 09 Oct 2024 12:00:00 GMT"
5353

5454
- description: "Headers with etag"
5555
input:
@@ -60,11 +60,11 @@ request_headers_tests:
6060

6161
- description: "Headers with both lastModified and etag"
6262
input:
63-
lastModified: "Wed, 09 Oct 2025 12:00:00 GMT"
63+
lastModified: "Wed, 09 Oct 2024 12:00:00 GMT"
6464
etag: "\"abc123\""
6565
expected:
6666
user-agent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36"
67-
If-Modified-Since: "Wed, 09 Oct 2025 12:00:00 GMT"
67+
If-Modified-Since: "Wed, 09 Oct 2024 12:00:00 GMT"
6868
If-None-Match: "\"abc123\""
6969

7070
redis_keys_tests:

0 commit comments

Comments
 (0)