Victor Lau
04/20/2022, 5:45 PM"relationships": Object {
"identifiers": Object {
"data": Array [
Object {
- "id": Object {
- "contents": "8",
- "getValue": [Function getValue],
- "json_class": "Pact::SomethingLike",
- },
- "type": Object {
- "data": Object {
- "generate": "resource_identifiers",
- "matcher": Object {
- "json_class": "Regexp",
- "o": 0,
- "s": "^resource_identifiers$",
+ "id": "8",
+ "type": "resource_identifiers",
},
- },
- "getValue": [Function getValue],
- "json_class": "Pact::Term",
- },
- },
],
},
I wrote my response to be like this:
relationships: {
identifiers: {
data: [
{
type: term({ generate: "resource_identifiers", matcher: "^resource_identifiers$" }),
id: string('8'),
},
],
},
treatments: like({
meta: like({
included: boolean(false),
}),
}),
},
Anyone have an idea of what I’m doing wrong? The test is just a simple :
const response = await fetch(`${provider.mockService.baseUrl}/procedures/2`, { headers });
const data = await response.json();
expect(data).toEqual({
data: {},
included: [dataFiltered],
});
Yousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
const { term, eachLike } = pact
data: eachLike({ type: term({ generate: "resource_identifiers", matcher: "^resource_identifiers$" }), id: string('8') })
Boris
04/21/2022, 2:23 AMBoris
04/21/2022, 2:25 AMfetch
call for you. Otherwise your tests might not be handling requests/responses the same way as your code :)Victor Lau
04/21/2022, 9:43 PMaxios
configuration that I didn’t want to fight in the test setup otherwise I would use the actual fetch
we have implemented instead of the manual fetch. Agreed on the handling may not be the same way as my code, but it’s a risk I am accepting (and hopefully will not regret).Victor Lau
04/21/2022, 9:44 PMToEqual
portion, but the pact mock server did generate some data. I rewrote it to test a specific portion of the payload that I care mostly about.
const data = await response.json();
[
'dob',
'phi_dob',
'email',
'first_name',
'full_name',
'gender',
'initials',
'last_name',
'middle_name',
'phone_number',
].map(field => {
expect(data.included[0].attributes[field]).not.toMatch(/\*\*\*\*\*/);
});
Boris
04/22/2022, 2:30 AMdataFiltered
includes matchers.Boris
04/22/2022, 2:33 AMBoris
04/22/2022, 2:34 AM