Mahesh Damavarapu
04/02/2024, 12:16 PM2024-04-02T12:13:50.251575Z ERROR ThreadId(09) pact_verifier: Failed to load pact - Failed to load pact from '<http://localhost:9292>'
I am able to see the consumer contract is available in the fetched path.
Any help here pleaseYousaf Nabi (pactflow.io)
Mahesh Damavarapu
04/02/2024, 3:05 PM<?php
//namespace MessageConsumer;
require_once __DIR__ . '/../../CommandMessageConsumer.php';
use Exception;
use GuzzleHttp\Psr7\Uri;
use PhpPact\Consumer\MessageBuilder;
use PhpPact\Standalone\PactConfigInterface;
use PhpPact\Standalone\PactMessage\PactMessageConfig;
use PhpPact\Standalone\ProviderVerifier\Model\VerifierConfig;
use PHPUnit\Framework\TestCase;
use stdClass;
/**
* Class ExampleMessageConsumerTest
*/
class ReplyMessageConsumerTest extends TestCase
{
private static PactConfigInterface $config;
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
self::$config = (new PactMessageConfig())
->setConsumer('PayoutService')
->setProvider('LedgerService')
->setPactDir('pacts/pcl/');
}
public static function tearDownAfterClass(): void
{
parent::tearDownAfterClass();
}
/**
* @throws Exception
*/
public function testProcessPayload()
{
$builder = new MessageBuilder(self::$config);
$contents = new stdClass();
$contents->responseType = 'ACCEPTED';
$body = new stdClass();
$body->caller_source_id = 'ledger-processor';
$body->instrument_type = 'CURRENCY';
$body->last_update_at = '1663227601993';
$body->transaction_id = 'payment-processor_2007';
$body->value = 0.55;
$body->currency = 'EUR';
$body->status = 'REDEEMED';
$body->user_id = 'usr_sai';
$metadata = new stdClass();
$metadata->last_update_at = '1663227601993';
$body->metadata = $metadata;
$contents->body = $body;
//$metadata = ['queue'=>'test_queue', 'routing_key'=>'test_routing_key'];
$metadata = [];
$builder
->given('a transaction')
->expectsToReceive('a transaction message')
->withMetadata($metadata)
->withContent($contents);
// established mechanism to this via callbacks
$consumerMessage = new CommandMessageConsumer();
$callback = [$consumerMessage, 'ProcessPayload'];
$builder->setCallback($callback);
$hasException = false;
try {
$builder->verify();
} catch (Exception $e) {
$hasException = true;
}
$this->assertFalse($hasException, 'Expects verification to pass without exceptions being thrown');
}
}
Mahesh Damavarapu
04/02/2024, 3:05 PM{
"consumer": {
"name": "PayoutService"
},
"provider": {
"name": "LedgerService"
},
"messages": [
{
"description": "a transaction message",
"metadata": {
"contentType": "application/json"
},
"providerStates": [
{
"name": "a transaction"
}
],
"contents": {
"responseType": "ACCEPTED",
"body": {
"caller_source_id": "ledger-processor",
"instrument_type": "CURRENCY",
"last_update_at": "1663227601993",
"transaction_id": "payment-processor_2007",
"value": 0.55,
"currency": "EUR",
"status": "REDEEMED",
"user_id": "usr_sai",
"metadata": {
"last_update_at": "1663227601993"
}
}
},
"matchingRules": {}
}
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}
Mahesh Damavarapu
04/02/2024, 3:06 PMconst {ReplyHandler} = require('../ls-provider')
const {
MessageProviderPact,
providerWithMetadata,
} = require('@pact-foundation/pact');
describe('LedgerService provider tests', () => {
const p = new MessageProviderPact({
messageProviders: {
'a transaction message': providerWithMetadata(() => ReplyHandler(), {
queue: 'transactions',
}),
},
provider: 'LedgerService',
//providerVersion: versionFromGitTag(),
pactBrokerUrl: '<http://localhost:9292>',
publishVerificationResult: true,
providerVersion: '1.0',
consumerVersionSelectors: ['1.0'],
//logLevel: "DEBUG",
//verbose: true,
});
describe('send a reply event', () => {
it('sends a valid reply', () => {
return p.verify();
});
});
});
Mahesh Damavarapu
04/02/2024, 3:07 PMYousaf Nabi (pactflow.io)
Mahesh Damavarapu
04/02/2024, 3:09 PMconst {createTransaction} = require('../cs-provider')
const {
MessageProviderPact,
providerWithMetadata,
} = require('@pact-foundation/pact');
describe('CommissionService provider tests', () => {
const p = new MessageProviderPact({
messageProviders: {
'a transaction message': providerWithMetadata(() => createTransaction(), {
queue: 'transactions',
}),
},
provider: 'CommissionService',
//providerVersion: versionFromGitTag(),
pactBrokerUrl: '<http://localhost:9292>',
publishVerificationResult: true,
providerVersion: '1.0',
consumerVersionSelectors: ['1.0']
});
describe('send a transaction event', () => {
it('sends a valid transaction', () => {
return p.verify();
});
});
});
Yousaf Nabi (pactflow.io)
consumerVersionSelectors
incorrectlyMahesh Damavarapu
04/02/2024, 3:10 PMYousaf Nabi (pactflow.io)
Mahesh Damavarapu
04/02/2024, 3:14 PMconsumerVersionSelectors: [{
latest: true,
},],
Mahesh Damavarapu
04/02/2024, 3:14 PMMahesh Damavarapu
04/02/2024, 3:15 PMYousaf Nabi (pactflow.io)
• `latest`: true. Used in conjuction with theproperty. If atag
is specified, andtag
islatest
, then the latest pact for each of the consumers with that tag will be returned. If atrue
is specified and the latest flag is not set totag
, all the pacts with the specified tag will be returned. (This might seem a bit weird, but it’s done this way to match the syntax used for the matrix query params. See https://docs.pact.io/selectors).true
Yousaf Nabi (pactflow.io)
Yousaf Nabi (pactflow.io)
true
. Return the pacts for the configured mainBranch
of each consumer. Use of this selector requires that the consumer has configured the mainBranch
property, and has set a branch name when publishing the pacts. As of October 2021, this is not yet supported in all Pact client libraries.
If your consumer is publishing on a branch other than main, you can pick it up via
• webhooks, triggering a verification by url
• including work in progress pacts, which will trigger on provider verifications, as well as the consumer version selectors
If you are just wanting to pick up a specific consumer branch (which is unlikely, you can add that in via selector)
You need to use tags, if you are using latest flag, in the consumer version selectors, as per the docs.
pact-js should probably error if you pass in invalid consumerVersionSelectors, rather than defaulting to passing no version selectorsMahesh Damavarapu
04/02/2024, 4:21 PMYousaf Nabi (pactflow.io)
Mahesh Damavarapu
04/03/2024, 4:17 AM