|
| 1 | +import stations from '@neaps/tide-stations' |
1 | 2 | import { |
2 | 3 | getExtremesPrediction, |
3 | 4 | nearestStation, |
4 | | - findStation |
| 5 | + findStation, |
| 6 | + useStation |
5 | 7 | } from '../src/index.js' |
6 | 8 | import { describe, test, expect } from 'vitest' |
7 | 9 |
|
@@ -96,3 +98,63 @@ describe('findStation', () => { |
96 | 98 | expect(station.getExtremesPrediction).toBeDefined() |
97 | 99 | }) |
98 | 100 | }) |
| 101 | + |
| 102 | +describe('datum', () => { |
| 103 | + test('defaults to MLLW datum', () => { |
| 104 | + const station = findStation('us-fl-ankona-indian-river') |
| 105 | + const extremes = station.getExtremesPrediction({ |
| 106 | + start: new Date('2025-12-17T00:00:00Z'), |
| 107 | + end: new Date('2025-12-18T00:00:00Z') |
| 108 | + }) |
| 109 | + expect(extremes.datum).toBe('MLLW') |
| 110 | + }) |
| 111 | + |
| 112 | + test('accepts datum option', () => { |
| 113 | + const station = findStation('us-fl-ankona-indian-river') |
| 114 | + const extremes = station.getExtremesPrediction({ |
| 115 | + start: new Date('2025-12-17T00:00:00Z'), |
| 116 | + end: new Date('2025-12-18T00:00:00Z'), |
| 117 | + datum: 'NAVD88' |
| 118 | + }) |
| 119 | + expect(extremes.datum).toBe('NAVD88') |
| 120 | + }) |
| 121 | + |
| 122 | + test('throws error for unavailable datum', () => { |
| 123 | + const station = findStation('us-ma-boston') |
| 124 | + expect(() => { |
| 125 | + station.getExtremesPrediction({ |
| 126 | + start: new Date('2025-12-17T00:00:00Z'), |
| 127 | + end: new Date('2025-12-18T00:00:00Z'), |
| 128 | + datum: 'UNKNOWN_DATUM' |
| 129 | + }) |
| 130 | + }).toThrow(/missing UNKNOWN_DATUM/) |
| 131 | + }) |
| 132 | + |
| 133 | + test('throws error when missing MSL datum', () => { |
| 134 | + // Find station without MSL but with other datums |
| 135 | + const station = stations.find( |
| 136 | + (s) => !('MSL' in s.datums) && Object.keys(s.datums).length > 0 |
| 137 | + ) |
| 138 | + if (!station) expect.fail('No station without MSL datum found') |
| 139 | + expect(() => { |
| 140 | + useStation(station).getExtremesPrediction({ |
| 141 | + start: new Date('2025-12-17T00:00:00Z'), |
| 142 | + end: new Date('2025-12-18T00:00:00Z'), |
| 143 | + datum: 'NAVD88' |
| 144 | + }) |
| 145 | + }).toThrow(/missing MSL/) |
| 146 | + }) |
| 147 | + |
| 148 | + test('does not apply datums when non available', () => { |
| 149 | + // Find a station with no datums |
| 150 | + const station = stations.find((s) => Object.entries(s.datums).length === 0) |
| 151 | + if (!station) expect.fail('No station without datums found') |
| 152 | + const extremes = useStation(station).getExtremesPrediction({ |
| 153 | + start: new Date('2025-12-17T00:00:00Z'), |
| 154 | + end: new Date('2025-12-18T00:00:00Z') |
| 155 | + }) |
| 156 | + |
| 157 | + expect(extremes.datum).toBeUndefined() |
| 158 | + expect(extremes.predictions.length).toBeGreaterThan(0) |
| 159 | + }) |
| 160 | +}) |
0 commit comments