@@ -16,7 +16,8 @@ import {
1616 ApiTaxFilingOnboardingResponse ,
1717} from "@client/ApiTaxFilingClient" ;
1818import { dateToShortISO } from "@domain/tax-filings/taxIdHelper" ;
19- import { StatusCodes } from "http-status-codes" ;
19+ import { randomElementFromArray } from "@test/helpers" ;
20+ import { ReasonPhrases , StatusCodes } from "http-status-codes" ;
2021
2122jest . mock ( "axios" ) ;
2223jest . mock ( "winston" ) ;
@@ -363,4 +364,37 @@ describe("ApiTaxFilingClient", () => {
363364 expect ( response ) . toEqual ( { state : "API_ERROR" } ) ;
364365 } ) ;
365366 } ) ;
367+
368+ describe ( "health" , ( ) => {
369+ it ( "returns a passing health check if the service is available" , async ( ) => {
370+ const stubResponse = generateSuccessfulApiTaxFilingLookupResponse ( { } ) ;
371+ mockAxios . post . mockResolvedValue ( { data : stubResponse } ) ;
372+
373+ expect ( await client . health ( ) ) . toEqual ( { success : true , data : { message : ReasonPhrases . OK } } ) ;
374+ } ) ;
375+
376+ it ( "returns a passing health check if the service returns a known validation error" , async ( ) => {
377+ const state : "PENDING" | "FAILED" | "UNREGISTERED" = randomElementFromArray ( [
378+ "PENDING" ,
379+ "FAILED" ,
380+ "UNREGISTERED" ,
381+ ] ) ;
382+
383+ const stubResponse = generateErroredApiTaxFilingLookupResponse ( { } , state ) ;
384+ mockAxios . post . mockRejectedValue ( {
385+ response : { data : stubResponse , status : StatusCodes . BAD_REQUEST } ,
386+ } ) ;
387+
388+ expect ( await client . health ( ) ) . toEqual ( { success : true , data : { message : ReasonPhrases . OK } } ) ;
389+ } ) ;
390+
391+ it ( "returns a failing health check if the service is unavailable" , async ( ) => {
392+ mockAxios . post . mockRejectedValue ( { } ) ;
393+
394+ expect ( await client . health ( ) ) . toEqual ( {
395+ success : false ,
396+ data : { message : ReasonPhrases . INTERNAL_SERVER_ERROR } ,
397+ } ) ;
398+ } ) ;
399+ } ) ;
366400} ) ;
0 commit comments