@@ -87,6 +87,65 @@ describe("StatuspageClient", () => {
8787 ) ;
8888 } ) ;
8989
90+ test ( "getPage returns a single parsed page" , async ( ) => {
91+ mockFetch ( MOCK_PAGES [ 0 ] ) ;
92+ const singlePage = await client . getPage ( "sp_page_001" ) ;
93+ expect ( singlePage ) . toEqual ( MOCK_PAGES [ 0 ] ) ;
94+ expect ( singlePage . id ) . toBe ( "sp_page_001" ) ;
95+ expect ( singlePage . name ) . toBe ( "Acme Corp Status" ) ;
96+ } ) ;
97+
98+ test ( "getPage calls correct URL path" , async ( ) => {
99+ mockFetch ( MOCK_PAGES [ 0 ] ) ;
100+ await client . getPage ( "sp_page_001" ) ;
101+ const fetchMock = globalThis . fetch as ReturnType < typeof mock > ;
102+ const [ url ] = fetchMock . mock . calls [ 0 ] as [ string , RequestInit ] ;
103+ expect ( url ) . toBe ( "https://api.statuspage.io/v1/pages/sp_page_001" ) ;
104+ } ) ;
105+
106+ test ( "getPage throws on non-200 response" , async ( ) => {
107+ mockFetch ( { error : "Not Found" } , 404 ) ;
108+ await expect ( client . getPage ( "nonexistent" ) ) . rejects . toThrow (
109+ "Statuspage API error: 404" ,
110+ ) ;
111+ } ) ;
112+
113+ test ( "getPage throws on schema mismatch" , async ( ) => {
114+ mockFetch ( { id : 123 , unexpected : true } ) ;
115+ await expect ( client . getPage ( "sp_page_001" ) ) . rejects . toThrow ( ) ;
116+ } ) ;
117+
118+ test ( "getScheduledIncidents returns parsed scheduled incidents" , async ( ) => {
119+ const scheduled = MOCK_INCIDENTS . filter ( ( i ) => i . scheduled_for != null ) ;
120+ mockFetch ( scheduled ) ;
121+ const incidents = await client . getScheduledIncidents ( "sp_page_001" ) ;
122+ expect ( incidents ) . toEqual ( scheduled ) ;
123+ expect ( incidents ) . toHaveLength ( 1 ) ;
124+ expect ( incidents [ 0 ] . scheduled_for ) . toBe ( "2024-06-20T02:00:00.000Z" ) ;
125+ } ) ;
126+
127+ test ( "getScheduledIncidents calls correct URL path" , async ( ) => {
128+ mockFetch ( [ ] ) ;
129+ await client . getScheduledIncidents ( "sp_page_001" ) ;
130+ const fetchMock = globalThis . fetch as ReturnType < typeof mock > ;
131+ const [ url ] = fetchMock . mock . calls [ 0 ] as [ string , RequestInit ] ;
132+ expect ( url ) . toBe (
133+ "https://api.statuspage.io/v1/pages/sp_page_001/incidents/scheduled" ,
134+ ) ;
135+ } ) ;
136+
137+ test ( "getScheduledIncidents throws on non-200 response" , async ( ) => {
138+ mockFetch ( { error : "Forbidden" } , 403 ) ;
139+ await expect ( client . getScheduledIncidents ( "sp_page_001" ) ) . rejects . toThrow (
140+ "Statuspage API error: 403" ,
141+ ) ;
142+ } ) ;
143+
144+ test ( "getScheduledIncidents throws on schema mismatch" , async ( ) => {
145+ mockFetch ( [ { bad : "data" } ] ) ;
146+ await expect ( client . getScheduledIncidents ( "sp_page_001" ) ) . rejects . toThrow ( ) ;
147+ } ) ;
148+
90149 test ( "sends correct auth header" , async ( ) => {
91150 mockFetch ( MOCK_PAGES ) ;
92151 await client . getPages ( ) ;
0 commit comments