Marcello Rigan
04/13/2022, 12:10 PMYousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
Marcello Rigan
04/13/2022, 12:15 PMid: somethingLike(string()),
description: somethingLike(string()),
uri: somethingLike(string()),
serviceName: somethingLike(string()),
method: somethingLike(string()),
this entry will be used multiple times. I also need to use this feature in an array in an arrayMatt (pactflow.io / pact-js / pact-go)
Marcello Rigan
04/13/2022, 1:27 PMsortOrderList: [
{
id: somethingLike(string()),
description: somethingLike(string()),
uri: somethingLike(string()),
serviceName: somethingLike(string()),
method: somethingLike(string()),
}
],
The API actually returned 2 Entries . something like this
sortOrderList: [
{
id: "XXX",
description: "XXX",
uri: "XXX",
serviceName: "XXX",,
method: "XXX",
},
{
id: "XXX",
description: "XXX",
uri:"XXX",
serviceName: "XXX",
method: "XXX",
],
I dont care about the values. I only want to check if the types are right . So to temporarily fix this i just added a new entry like this:
sortOrderList: [
{
id: somethingLike(string()),
description: somethingLike(string()),
uri: somethingLike(string()),
serviceName: somethingLike(string()),
method: somethingLike(string()),
},
{
id: somethingLike(string()),
description: somethingLike(string()),
uri: somethingLike(string()),
serviceName: somethingLike(string()),
method: somethingLike(string()),
},
],
Every entry is basically the same. I want a way to only declare 1 entry and it should use that schema for every entry thats being returned by the APIMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
sortOrderList: eachLike({
id: string(),
description: string(),
uri: string(),
serviceName: string(),
method: string(),
}, 1)
Marcello Rigan
04/13/2022, 1:32 PMMatt (pactflow.io / pact-js / pact-go)
string()
Yousaf Nabi (pactflow.io)
const { somethingLike: like, term, eachLike } = pact
const bodyExpectation = {
id: like('id'),
description: like('description'),
uri: like('uri'),
serviceName: like('serviceName'),
method: like('method'),
}
// Define body list payload, reusing existing object matcher
// Note that using eachLike ensure that all values are matched by type
const listExpectation = eachLike(bodyExpectation)
Matt (pactflow.io / pact-js / pact-go)
I tried that. that didnt workwhat problem/error are you seeing?
Matt (pactflow.io / pact-js / pact-go)
eachLike
says “here is a representative example of an item I expect to see in the array. When I verify the provider, every item should have this shape”Yousaf Nabi (pactflow.io)
Matt (pactflow.io / pact-js / pact-go)
arrayContaining
is a different thing. It says `here are some object shapes I expect to see in this array. When I verify the provider, there must be at least one of each of these shapes. I’ll ignore any others that don’t match the shape”Marcello Rigan
04/13/2022, 1:36 PMMarcello Rigan
04/13/2022, 1:47 PMMarcello Rigan
04/13/2022, 1:59 PMsortOrderList:[
eachLike({
id: string(),
description: string(),
uri: string(),
serviceName: string(),
method: string(),
})]
sortOrderList:
eachLike({
id: string(),
description: string(),
uri: string(),
serviceName: string(),
method: string(),
}),
this seems to work for me. Thank you