33 getExtremesPrediction ,
44 nearestStation ,
55 findStation ,
6- useStation
6+ useStation ,
7+ getTimelinePrediction ,
8+ getWaterLevelAtTime
79} from '../src/index.js'
810import { describe , test , expect } from 'vitest'
911
@@ -33,18 +35,85 @@ describe('getExtremesPrediction', () => {
3335 expect ( predictions [ 0 ] . low ) . toBe ( true )
3436 expect ( predictions [ 0 ] . label ) . toBe ( 'Low' )
3537 } )
36- ; [
37- { lat : 26.7 , lon : - 80.05 } ,
38- { lat : 26.7 , lng : - 80.05 } ,
39- { latitude : 26.7 , longitude : - 80.05 }
40- ] . forEach ( ( position ) => {
41- test ( `accepts position with ${ Object . keys ( position ) . join ( '/' ) } ` , ( ) => {
42- const extremes = getExtremesPrediction ( {
43- ...position ,
44- start : new Date ( '2025-12-17T00:00:00Z' ) ,
45- end : new Date ( '2025-12-18T05:00:00Z' )
38+ } )
39+
40+ describe ( 'getTimelinePrediction' , ( ) => {
41+ test ( 'gets timeline from nearest station' , ( ) => {
42+ const timeline = getTimelinePrediction ( {
43+ lat : 26.7 ,
44+ lon : - 80.05 ,
45+ start : new Date ( '2025-12-19T00:00:00-05:00' ) ,
46+ end : new Date ( '2025-12-19T01:00:00-05:00' )
47+ } )
48+
49+ expect ( timeline . station . id ) . toEqual ( 'us-fl-port-of-west-palm-beach' )
50+ expect ( timeline . datum ) . toBe ( 'MLLW' )
51+ expect ( timeline . timeline . length ) . toBe ( 7 ) // Every 10 minutes for 1 hour = 7 points
52+ } )
53+ } )
54+
55+ describe ( 'getWaterLevelAtTime' , ( ) => {
56+ test ( 'gets water level at specific time from nearest station' , ( ) => {
57+ const waterLevel = getWaterLevelAtTime ( {
58+ lat : 26.7 ,
59+ lon : - 80.05 ,
60+ time : new Date ( '2025-12-19T00:30:00-05:00' ) ,
61+ datum : 'MSL'
62+ } )
63+
64+ expect ( waterLevel . station . id ) . toEqual ( 'us-fl-port-of-west-palm-beach' )
65+ expect ( waterLevel . datum ) . toBe ( 'MSL' )
66+ expect ( waterLevel . time ) . toEqual ( new Date ( '2025-12-19T05:30:00.000Z' ) )
67+ expect ( typeof waterLevel . level ) . toBe ( 'number' )
68+ } )
69+ } )
70+
71+ describe ( 'for a specific station' , ( ) => {
72+ const station = nearestStation ( { lat : 45.6 , lon : - 122.7 } )
73+
74+ describe ( 'getExtremesPrediction' , ( ) => {
75+ test ( 'can return extremes from station' , ( ) => {
76+ const station = nearestStation ( { lat : 26.7 , lon : - 80.05 } )
77+
78+ const start = new Date ( '2025-12-17T00:00:00-05:00' )
79+ const end = new Date ( '2025-12-18T05:00:00-05:00' )
80+
81+ const { predictions } = station . getExtremesPrediction ( {
82+ start,
83+ end,
84+ timeFidelity : 6 ,
85+ datum : 'MLLW'
86+ } )
87+
88+ expect ( predictions . length ) . toBe ( 4 )
89+ expect ( predictions [ 0 ] . time ) . toEqual ( new Date ( '2025-12-17T11:23:06.000Z' ) )
90+ expect ( predictions [ 0 ] . level ) . toBeCloseTo ( 0.9 , 1 )
91+ expect ( predictions [ 0 ] . high ) . toBe ( true )
92+ expect ( predictions [ 0 ] . low ) . toBe ( false )
93+ expect ( predictions [ 0 ] . label ) . toBe ( 'High' )
94+ } )
95+ } )
96+
97+ describe ( 'getTimelinePrediction' , ( ) => {
98+ test ( 'gets timeline' , ( ) => {
99+ const prediction = station . getTimelinePrediction ( {
100+ start : new Date ( '2025-12-19T00:00:00Z' ) ,
101+ end : new Date ( '2025-12-19T01:00:00Z' )
46102 } )
47- expect ( extremes . station . id ) . toEqual ( 'us-fl-port-of-west-palm-beach' )
103+ // Every 10 minutes for 1 hour = 7 points
104+ expect ( prediction . timeline . length ) . toBe ( 7 )
105+ expect ( prediction . datum ) . toBe ( 'MLLW' )
106+ } )
107+ } )
108+
109+ describe ( 'getWaterLevelAtTime' , ( ) => {
110+ test ( 'gets water level at specific time' , ( ) => {
111+ const prediction = station . getWaterLevelAtTime ( {
112+ time : new Date ( '2025-12-19T00:30:00Z' )
113+ } )
114+ expect ( prediction . time ) . toEqual ( new Date ( '2025-12-19T00:30:00Z' ) )
115+ expect ( prediction . datum ) . toBe ( 'MLLW' )
116+ expect ( typeof prediction . level ) . toBe ( 'number' )
48117 } )
49118 } )
50119} )
@@ -56,26 +125,15 @@ describe('nearestStation', () => {
56125 expect ( station . metadata . latitude ) . toBeCloseTo ( 26.77 )
57126 expect ( station . metadata . longitude ) . toBeCloseTo ( - 80.0517 )
58127 } )
59-
60- test ( 'can return extremes from station' , ( ) => {
61- const station = nearestStation ( { lat : 26.7 , lon : - 80.05 } )
62-
63- const start = new Date ( '2025-12-17T00:00:00-05:00' )
64- const end = new Date ( '2025-12-18T05:00:00-05:00' )
65-
66- const { predictions } = station . getExtremesPrediction ( {
67- start,
68- end,
69- timeFidelity : 6 ,
70- datum : 'MLLW'
128+ ; [
129+ { lat : 26.7 , lon : - 80.05 } ,
130+ { lat : 26.7 , lng : - 80.05 } ,
131+ { latitude : 26.7 , longitude : - 80.05 }
132+ ] . forEach ( ( position ) => {
133+ test ( `finds station with ${ Object . keys ( position ) . join ( '/' ) } ` , ( ) => {
134+ const station = nearestStation ( position )
135+ expect ( station . metadata . id ) . toEqual ( 'us-fl-port-of-west-palm-beach' )
71136 } )
72-
73- expect ( predictions . length ) . toBe ( 4 )
74- expect ( predictions [ 0 ] . time ) . toEqual ( new Date ( '2025-12-17T11:23:06.000Z' ) )
75- expect ( predictions [ 0 ] . level ) . toBeCloseTo ( 0.9 , 1 )
76- expect ( predictions [ 0 ] . high ) . toBe ( true )
77- expect ( predictions [ 0 ] . low ) . toBe ( false )
78- expect ( predictions [ 0 ] . label ) . toBe ( 'High' )
79137 } )
80138} )
81139
0 commit comments