MessageProviderPact configures the provider side of a Pact message contract. It supplies named message interactions, message bodies, metadata, provider identity, version details, and Pact Broker credentials for verification. section 8.7
A provider test defines each interaction as a message description mapped to providerWithMetadata. The function returns the message body and event metadata, while verify() retrieves associated contracts from the Pact Broker and checks them. section 8.7
A typical configuration establishes:
- A message interaction such as “a movie add event.” section 8.7
- A providerWithMetadata callback that creates the message body and attaches metadata such as kafka_topic. section 8.7
- Provider identity, version, branch, log level, and Pact Broker URL and token. section 8.7
- A test that calls provider.verify() to validate the configured provider message. section 8.7
Movie event provider
A movie event provider maps “a movie add event” to createMovie("The World's End", "2013") and adds the movies Kafka topic as metadata. The test then calls provider.verify(), allowing the provider implementation to verify the body and metadata published by the consumer contract. section 8.7
Listing 8.22 Message provider constructor
const provider = new MessageProviderPact({
messageProviders: {
'a movie add event': providerWithMetadata(() =>
createMovie("The World's End", "2013"), {
kafka_topic: 'movies'
}),
},
logLevel: 'info',
provider: 'EventProducer',
providerVersion: '1.0.0',
providerVersionBranch: 'main',
pactBrokerUrl: process.env.PACT_BROKER_URL,
pactBrokerToken: process.env.PACT_BROKER_TOKEN,
});
Inspect the complete constructor showing messageProviders, providerWithMetadata, provider versioning, and Pact Broker configuration. section 8.7
