import getJiraAxios , { JiraClientError } from "../../../../src/jira/client/axios" ; describe ( "Jira axios instance" , ( ) => { describe ( "request metrics" , ( ) => { describe ( "when request successful" , ( ) => { it ( "sends timing metric" , async ( ) => { jiraNock . get ( "/foo/bar" ) . reply ( 200 ) ; await expect ( getJiraAxios ( jiraHost , "secret" ) . get ( "/foo/bar" ) ) . toResolve ( ) ; expect ( jiraNock ) . toBeDone ( ) ; } ) ; it ( "removes URL query params from path" , async ( ) => { jiraNock . get ( "/foo/bar?baz=true" ) . reply ( 200 ) ; await expect ( getJiraAxios ( jiraHost , "secret" ) . get ( "/foo/bar?baz=true" ) ) . toResolve ( ) ; expect ( jiraNock ) . toBeDone ( ) ; } ) ; } ) ; describe ( "when request fails" , ( ) => { it ( "sends timing metric" , async ( ) => { jiraNock . get ( "/foo/bar" ) . reply ( 500 ) ; await expect ( getJiraAxios ( jiraHost , "secret" ) . get ( "/foo/bar" ) ) . toReject ( ) ; expect ( jiraNock ) . toBeDone ( ) ; } ) ; it ( "Serialized error doesn't have request payload" , async ( ) => { const requestPayload = "TestRequestPayload" ; jiraNock . post ( "/foo/bar" , requestPayload ) . reply ( 500 ) ; let error = undefined ; try { await getJiraAxios ( jiraHost , "secret" ) . post ( "/foo/bar" , requestPayload ) ; } catch ( e ) { error = e ; } expect ( error ) . toBeInstanceOf ( JiraClientError ) ; const serialisedError = JSON . stringify ( error ) ; expect ( serialisedError ) . not . toContain ( requestPayload ) ; } ) ; } ) ; } ) ; } ) ;