Skip to content

Commit

Permalink
Refactor Axios client initialization and request logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy committed Aug 30, 2024
1 parent 9c9373f commit 044db0b
Showing 1 changed file with 33 additions and 30 deletions.
63 changes: 33 additions & 30 deletions src/tests/integration/helper/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,47 @@ import { Agent } from "http"
const PROVIDER_URL = "http://localhost:5000"

const options = (state, consumer): AxiosRequestConfig => {
return {
url: "/api/contract/states",
baseURL: PROVIDER_URL,
method: "POST",
data: {
consumer,
state,
},
headers: {
"Content-Type": "application/json",
},
httpAgent: new Agent({ keepAlive: false }),
}
return {
url: "/api/contract/states",
baseURL: PROVIDER_URL,
method: "POST",
data: {
consumer,
state,
},
headers: {
"Content-Type": "application/json",
},
}
}

const client = axios.create({
httpAgent: new Agent({ keepAlive: false }),
})

export const stateSetup = (state, consumer = "integration-tests") => {
return axios(options(state, consumer))
return client.request(options(state, consumer))
}


export const userSetup = (): Promise<AxiosResponse> => {
return axios({
url: "/api/contract/test-user",
baseURL: PROVIDER_URL,
method: "POST",
headers: {
"Content-Type": "application/json",
},
})
return axios({
url: "/api/contract/test-user",
baseURL: PROVIDER_URL,
method: "POST",
headers: {
"Content-Type": "application/json",
},
})
}

export const apiTokenSetup = (): Promise<AxiosResponse> => {
return axios({
url: "/api/contract/api-token",
baseURL: PROVIDER_URL,
method: "POST",
headers: {
"Content-Type": "application/json",
},
})
return axios({
url: "/api/contract/api-token",
baseURL: PROVIDER_URL,
method: "POST",
headers: {
"Content-Type": "application/json",
},
})
}

0 comments on commit 044db0b

Please sign in to comment.