Skip to content

Adding conditional based matchers in LambdaDslObject #1856

@durgamanasa

Description

@durgamanasa

Hello team,

We are trying to write Contract test for Async messages using Pact using Java.

We have the below object

"user": {
"id": "user1",
"email": "example@gmail.com"
}

We want to add the rule like when the "id" is "user1" then "email" field is mandatory. And if "id" is anything else apart from "user1" then "email" field is not mandatory. How can we achieve this using "LambdaDslObject"?

Here is sample LambdaDslObject that we are setting
data.object(
USER,
user -> user.stringValue(ID, "user1"));

Ideally we would like to achieve this with single pact. Meaning that one consumer pact which can be verified by multiple providers.

Eg:

  1. Provider1 produce the "id" as "user1" along with "email" field then the pact should pass
    {"id": "user1", "email": "example@gmail.com"}

  2. Provider2 produce the "id" as "user2" and don't send email field then also pact should pass
    {"id": "user2"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIndicates that an issue, pull request, or discussion needs more information

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions