example-query-param
- Spec V2: Query strings are stored as a string e.g.
"query": "name=Polar"
. - Spec V3: Query strings are stored as Map (to an array) instead of strings e.g.
"query": {"name": ["Polar"]}
Adding the query param(s) to the request:
- js-v2
- js-jest-pact-v2
- python-v2
- js-v3
- js-jest-pact-v3
await mockProvider.addInteraction({
state: "There are some bears",
uponReceiving: "A request for the Polar bear species by name",
willRespondWith: {
status: 200,
body: expectedResponse,
},
withRequest: {
method: "GET",
path: "/species",
query: { name: "Polar" },
},
});
provider.addInteraction({
state: "There are some bears",
uponReceiving: "A request for the Polar bear species by name",
withRequest: {
method: "GET",
path: "/species",
query: { name: "Polar" },
},
willRespondWith: {
status: 200,
body: expectedResponse,
},
})
(
pact.given("There are some bears")
.upon_receiving("A request for the Polar bear species by name")
.with_request("GET", "/species", query={"name": "Polar"})
.will_respond_with(200, body=expected)
)
mockProvider
.given("There are some bears")
.uponReceiving("A request for the Polar bear species by name")
.withRequest({
method: "GET",
path: "/species",
query: { name: "Polar" },
})
.willRespondWith({
status: 200,
body: { ...expectedResponse },
});
provider
.given("There are some bears")
.uponReceiving("A request for the Polar bear species by name")
.withRequest({
method: "GET",
path: "/species",
query: { name: "Polar" },
})
.willRespondWith({
status: 200,
body: { ...expectedResponse },
})
Pacts
- v2
- v2-v3 diff
- v3
{
"consumer": {
"name": "BearServiceClient"
},
"provider": {
"name": "BearService"
},
"interactions": [
{
"description": "A request for the Polar bear species by name",
"providerState": "There are some bears",
"request": {
"method": "GET",
"path": "/species",
"query": "name=Polar"
},
"response": {
"status": 200,
"headers": {},
"body": {
"name": "Polar",
"colour": "White"
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}
--- v2
+++ v3
@@ -8,11 +8,17 @@
"interactions": [
{
"description": "A request for the Polar bear species by name",
- "providerState": "There are some bears",
+ "providerStates": [
+ {
+ "name": "There are some bears"
+ }
+ ],
"request": {
"method": "GET",
"path": "/species",
- "query": "name=Polar"
+ "query": {
+ "name": ["Polar"]
+ }
},
"response": {
"status": 200,
@@ -26,7 +32,7 @@
],
"metadata": {
"pactSpecification": {
- "version": "2.0.0"
+ "version": "3.0.0"
}
}
}
{
"consumer": {
"name": "BearServiceClient"
},
"provider": {
"name": "BearService"
},
"interactions": [
{
"description": "A request for the Polar bear species by name",
"providerStates": [
{
"name": "There are some bears"
}
],
"request": {
"method": "GET",
"path": "/species",
"query": {
"name": ["Polar"]
}
},
"response": {
"status": 200,
"headers": {},
"body": {
"name": "Polar",
"colour": "White"
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "3.0.0"
}
}
}