pact-foundation / pact-js

JS version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
https://pact.io
Other
1.62k stars 343 forks source link

Support combining matching rules #1203

Open mefellows opened 6 months ago

mefellows commented 6 months ago

In some cases, you need to apply multiple matchers to a field in order to properly validate it. Only Pact JVM currently supports this behaviour.

The capability to combine matching rules will be enabled in the next release (v0.4.19), but the clients will need to update their DSLs to support it.

Motivating Use Case

From a request in slack.

How might you write a matcher to check both the keys and values and the same time (use eachKeyMatches and eachValueMatches simultaneously):

    enum Keys {
      One = "One",
      Two = "Two",
    }

    interface Value {
      min: number
      max: number
    }

    type R = Record<Keys, Value>
    const record: R  = {
      [Keys.One]:
        {
          min: 1,
          max: 2
        }
    }

  it("check record", async () => {
    messagePact
      .expectsToReceive("record")
      .withContent({
        // What need to write here to check type R ?
      })
  })

Proposed API to support this

TBC

Background: https://github.com/pact-foundation/pact-reference/issues/399#issuecomment-2024081745

mefellows commented 4 months ago

See also https://github.com/pact-foundation/pact-php/pull/597

sergewar commented 1 month ago

@mefellows do you have any expectation when this feature will be implemented for JS?

mefellows commented 1 month ago

There are no immediate plans to implement, so if you would like to pick this up I'd be happy to support you.