Satish Autade
09/04/2023, 2:22 AM"@pact-foundation/pact": "^12.1.0", and PactV3
Can someone please help me resolve this issue ?
~/Documents/projects/squiz/dxp-console/ [feat/quality-47*] npm run test:pact
> dxp-console@0.1.0 test:pact
> jest --config=jest.pact.config.ts
at Object.<anonymous> (apps/component-service/src/Services/component/src/contract-test/helpers/ComponentProvider.ts:8:9)
console.log
MOCK SERVER URL => <http://127.0.0.1:8081>
at apps/component-service/src/Services/component/src/contract-test/ComponentServiceConsumer.spec.ts:80:17
RUNS apps/component-service/src/Services/component/src/contract-test/ComponentServiceConsumer.spec.ts
2023-09-04T02:23:57.073080Z INFO tokio-runtime-worker pact_mock_server::hyper_server: Received request OPTIONS /__dxp/au/components-management/dx-team-uat-6287/v1/component-set
2023-09-04T02:23:57.073488Z INFO tokio-runtime-worker pact_matching: comparing to expected HTTP Request ( method: GET, path: /__dxp/au/components-management/dx-team-uat-6287/v1/component-set, query: Some({"sort[]": ["displayName"], "page": ["1"]}), headers: Some({"origin": ["<http://localhost>"], "accept": ["*/*"], "accept-language": ["en"], "user-agent": ["Mozilla/5.0 (darwin) AppleWebKit/537.36 (KHTML", "like Gecko) jsdom/20.0.3"], "connection": ["keep-alive"], "content-type": ["application/json"], "x-requested-with": ["XMLHttpRequest"], "accept-encoding": ["gzip", "deflate"], "host": ["localhost:8081"], "referer": ["<http://locahost/>"]}), body: Missing )
2023-09-04T02:23:57.075548Z INFO tokio-runtime-worker pact_mock_server::hyper_server: Responding to CORS pre-flight request
2023-09-04T02:23:57.076940Z INFO tokio-runtime-worker pact_mock_server::hyper_server: Received request GET /__dxp/au/components-management/dx-team-uat-6287/v1/component-set
2023-09-04T02:23:57.076963Z INFO tokio-runtime-worker pact_matching: comparing to expected HTTP Request ( method: GET, path: /__dxp/au/components-management/dx-team-uat-6287/v1/component-set, query: Some({"sort[]": ["displayName"], "page": ["1"]}), headers: Some({"origin": ["<http://localhost>"], "accept": ["*/*"], "accept-language": ["en"], "user-agent": ["Mozilla/5.0 (darwin) AppleWebKit/537.36 (KHTML", "like Gecko) jsdom/20.0.3"], "connection": ["keep-alive"], "content-type": ["application/json"], "x-requested-with": ["XMLHttpRequest"], "accept-encoding": ["gzip", "deflate"], "host": ["localhost:8081"], "referer": ["<http://locahost/>"]}), body: Missing )
[12:23:57.079] ERROR (29361): pact@12.1.0: Test failed for the following reasons:
Mock server failed with the following mismatches:
0) The following request was incorrect:
GET /__dxp/au/components-management/dx-team-uat-6287/v1/component-set
FAIL apps/component-service/src/Services/component/src/contract-test/ComponentServiceConsumer.spec.ts
Pact with Component/Management API - Consumer (DXP-Console) Test
GET /component-set
✕ returns an HTTP 200 and a list of component sets (29 ms)
● Pact with Component/Management API - Consumer (DXP-Console) Test › GET /component-set › returns an HTTP 200 and a list of component sets
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 5.041 s
Ran all test suites.Timothy Jones
09/04/2023, 3:09 AMTimothy Jones
09/04/2023, 3:10 AMTimothy Jones
09/04/2023, 3:11 AMTimothy Jones
09/04/2023, 3:11 AMSatish Autade
09/04/2023, 4:21 AMimport { PactV3 as Pact } from '@pact-foundation/pact';
import path from 'path';
const port = 8081;
export const componentProvider = new Pact({
consumer: 'dxp-console',
cors: true,
dir: path.resolve(process.cwd(), 'apps/component-service/src/Services/component/contract-test/pacts'),
logLevel: 'info',
port: port,
provider: 'component-service',
});
describe('Pact with Component/Management API - Consumer (DXP-Console) Test', () => {
describe('GET /component-set', () => {
beforeAll(async () => {
componentProvider
.given('I have a component set')
.uponReceiving('a request for all component sets')
.withRequest({
method: 'GET',
path: '/__dxp/au/components-management/dx-team-uat-6287/v1/component-set',
query: {
page: '1',
'sort[]': ['displayName'],
},
headers: {
'accept': '*/*',
'accept-encoding': 'gzip, deflate',
'accept-language': 'en',
'content-type': 'application/json',
'connection': 'keep-alive',
'host': 'localhost:8081',
'origin': '<http://localhost>',
'referer': '<http://locahost/>',
'user-agent': 'Mozilla/5.0 (darwin) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/20.0.3',
'x-requested-with': 'XMLHttpRequest',
},
})
.willRespondWith({
status: 200,
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
body: GET_COMPONENT_SET_EXPECTED_RESPONSE,
});
});
it('returns an HTTP 200 and a list of component sets', async () => {
await componentProvider.executeTest(async (mockserver) => {
console.log("MOCK SERVER URL => " + mockserver.url);
const componentServiceConfig: ComponentServiceConfiguration = {
...mockBaseServiceConfiguration,
baseUrl: mockserver.url + '/__dxp/au/components-management/dx-team-uat-6287/v1/component-set',
sessionUrl: '<http://localhost:8081/__dxp/au/components-management/dx-team-uat-6287>',
};
componentServiceConfig.httpService = newHttpService;
const componentService = new ComponentService(componentServiceConfig);
const response = await lastValueFrom(componentService.getComponentSet(dto));
//Assert
expect(response).toEqual(GET_COMPONENT_SET_EXPECTED_RESPONSE);
});
});
});
});Timothy Jones
09/04/2023, 4:22 AMsessionUrl: '<http://localhost:8081/> looks suspiciousTimothy Jones
09/04/2023, 4:22 AMmockserver.url ?Timothy Jones
09/04/2023, 4:23 AMbaseUrl correct? Usually it would just be mockserver.url, and your API code would know the pathSatish Autade
09/04/2023, 4:24 AMconst componentServiceConfig: ComponentServiceConfiguration = {
...mockBaseServiceConfiguration,
baseUrl: mockserver.url + '/__dxp/au/components-management/dx-team-uat-6287/v1/component-set',
sessionUrl: mockserver.url + '/__dxp/au/components-management/dx-team-uat-6287',
};Satish Autade
09/04/2023, 4:27 AM[14:26:20.038] ERROR (35262): pact@12.1.0: Test failed for the following reasons:
Mock server failed with the following mismatches:
0) The following request was incorrect:
GET /__dxp/au/components-management/dx-team-uat-6287/v1/component-set
FAIL apps/component-service/src/Services/component/src/contract-test/ComponentServiceConsumer.spec.ts
Pact with Component/Management API - Consumer (DXP-Console) Test
GET /component-set
✕ returns an HTTP 200 and a list of component sets (27 ms)
● Pact with Component/Management API - Consumer (DXP-Console) Test › GET /component-set › returns an HTTP 200 and a list of component setsTimothy Jones
09/04/2023, 4:29 AMTimothy Jones
09/04/2023, 4:29 AMTimothy Jones
09/04/2023, 4:31 AMTimothy Jones
09/04/2023, 4:31 AMTimothy Jones
09/04/2023, 4:32 AMTimothy Jones
09/04/2023, 4:33 AMSatish Autade
09/04/2023, 4:38 AMTimothy Jones
09/04/2023, 4:39 AMSatish Autade
09/04/2023, 4:44 AMPact doesn't display the matcher errors when actual and expected requests are different.?Timothy Jones
09/04/2023, 4:45 AMTimothy Jones
09/04/2023, 4:45 AMTimothy Jones
09/04/2023, 4:45 AMTimothy Jones
09/04/2023, 4:45 AMSatish Autade
09/04/2023, 5:57 AMinfo . Is that why its showing up?Timothy Jones
09/04/2023, 6:33 AMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Satish Autade
09/04/2023, 6:55 AMSatish Autade
09/06/2023, 2:47 AMMatt (pactflow.io / pact-js / pact-go)
Satish Autade
09/06/2023, 3:02 AM