Skip to content

Commit 6eb289f

Browse files
Add test suite for PDF checker
- Add test script with minimal JSON fixtures - Test 3 scenarios: no changes, newer year, URL change - Add tests/README.md with usage instructions
1 parent e2f72d5 commit 6eb289f

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

tests/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Tests
2+
3+
## Running Tests
4+
5+
```bash
6+
./tests/test-pdf-checker.sh
7+
```
8+
9+
## Test Fixtures
10+
11+
Minimal JSON fixtures in `fixtures/` test different scenarios:
12+
- `current-version.json` - Up-to-date version (expects no changes)
13+
- `old-version.json` - Older year (expects newer year detection)
14+
- `url-changed.json` - Same year, different URL (expects data correction detection)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"title": "2024-2025 OSI Time Standards",
3+
"sourceUrl": "https://www.oregonswimming.org/wzorlsc/UserFiles/Image/QuickUpload/2024-2025-osi-time-standards-full_040221.pdf",
4+
"generatedOn": "2025-10-24",
5+
"ageGroups": []
6+
}

tests/fixtures/old-version.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"title": "2023-2024 OSI Time Standards",
3+
"sourceUrl": "https://www.oregonswimming.org/wzorlsc/UserFiles/Image/QuickUpload/2023-2024-osi-time-standards-full_040221.pdf",
4+
"generatedOn": "2024-10-24",
5+
"ageGroups": []
6+
}

tests/fixtures/url-changed.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"title": "2024-2025 OSI Time Standards",
3+
"sourceUrl": "https://www.oregonswimming.org/wzorlsc/UserFiles/Image/QuickUpload/2024-2025-osi-time-standards-OLD.pdf",
4+
"generatedOn": "2025-10-24",
5+
"ageGroups": []
6+
}

tests/test-pdf-checker.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
3+
# Test script for check-for-new-pdf.js
4+
# Uses minimal test fixtures to verify behavior
5+
6+
set -e
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
10+
CHECK_SCRIPT="$PROJECT_ROOT/.github/scripts/check-for-new-pdf.js"
11+
FIXTURES_DIR="$SCRIPT_DIR/fixtures"
12+
13+
# Colors for output
14+
RED='\033[0;31m'
15+
GREEN='\033[0;32m'
16+
YELLOW='\033[1;33m'
17+
BLUE='\033[0;34m'
18+
NC='\033[0m' # No Color
19+
20+
echo -e "${BLUE}================================================${NC}"
21+
echo -e "${BLUE}Testing PDF Checker Script${NC}"
22+
echo -e "${BLUE}================================================${NC}"
23+
echo ""
24+
25+
# Function to run test
26+
run_test() {
27+
local test_name="$1"
28+
local fixture_file="$2"
29+
local expected_exit_code="$3"
30+
31+
echo -e "${BLUE}------------------------------------------------${NC}"
32+
echo -e "${BLUE}Test: $test_name${NC}"
33+
echo -e "${BLUE}Fixture: $(basename "$fixture_file")${NC}"
34+
echo -e "${BLUE}------------------------------------------------${NC}"
35+
36+
# Run the script with the fixture file and capture exit code
37+
set +e
38+
node "$CHECK_SCRIPT" "$fixture_file"
39+
actual_exit_code=$?
40+
set -e
41+
42+
echo ""
43+
44+
# Verify exit code
45+
if [ $actual_exit_code -eq $expected_exit_code ]; then
46+
echo -e "${GREEN}✓ PASSED${NC} - Exit code: $actual_exit_code (expected: $expected_exit_code)"
47+
else
48+
echo -e "${RED}✗ FAILED${NC} - Exit code: $actual_exit_code (expected: $expected_exit_code)"
49+
exit 1
50+
fi
51+
52+
echo ""
53+
}
54+
55+
# Test 1: No changes (current version is up to date)
56+
run_test "No changes - Current version up to date" \
57+
"$FIXTURES_DIR/current-version.json" \
58+
1
59+
60+
# Test 2: Newer year detected
61+
run_test "Newer year detected (2023-2024 → 2024-2025)" \
62+
"$FIXTURES_DIR/old-version.json" \
63+
0
64+
65+
# Test 3: URL changed for same year
66+
run_test "URL changed for same year (data correction)" \
67+
"$FIXTURES_DIR/url-changed.json" \
68+
0
69+
70+
# Summary
71+
echo -e "${GREEN}================================================${NC}"
72+
echo -e "${GREEN}All tests passed!${NC}"
73+
echo -e "${GREEN}================================================${NC}"

0 commit comments

Comments
 (0)