https://linen.dev logo
#help
Title
# help
u

Utku K

03/20/2024, 11:09 AM
Hi I have a question. I need to mock two different APIs for the /accounts/$accountId/eligibility endpoint, but they return different responses. I tried adding two mappings like this, but since the endpoints are exactly the same, they conflict with each other. What can I do?
Copy code
fun stubXXX(statusCode: Int, accountId: Int, responseSample: Sample): StubMapping {
    return stubFor(
        get(urlEqualTo("/accounts/$accountId/eligibility"))
            .willReturn(
                aResponse()
                    .withStatus(statusCode)
                    .withHeader(CONTENT_TYPE, APPLICATION_JSON)
                    .withBody(getReadSampleText(responseSample))
            )

    )
}
Language: kotlin
b

Bas Dijkstra

03/20/2024, 1:10 PM
In the API you're mocking, what determines whether response 1 or response 2 is returned?
u

Utku K

03/20/2024, 1:38 PM
actually there is two API that I want to mock but these two API has same endpoint. Like API 1 - sameEndpoint - return X API 2 - sameEndpoint - return Y api url = wiremock url
b

Bas Dijkstra

03/20/2024, 2:21 PM
There are a couple of potential solutions I can think of: • Use two different WireMock instances • See if you can tell the app calling the WireMock instances to call
<http://wiremock.server/API1/endpoint>
and
<http://wiremock.server/API2/endpoint>
instead of having them both call
<http://wiremock.server/endpoint>
• See if you can have the application inject a header that allows you to differentiate between the two (but that might involve duplicating all your mocks)
1
8 Views