Skip to content

feat: add support for arrayContains matcher#131

Open
pepejeria wants to merge 1 commit into
surpher:feat/v2.0.0from
pepejeria:feat/array-contains-matcher
Open

feat: add support for arrayContains matcher#131
pepejeria wants to merge 1 commit into
surpher:feat/v2.0.0from
pepejeria:feat/array-contains-matcher

Conversation

@pepejeria

@pepejeria pepejeria commented Jul 8, 2026

Copy link
Copy Markdown

📝 Summary of Changes

Adds support for the Pact v4 arrayContains matcher.

An arrayContains matcher checks that an array contains at least one element matching each of the provided variants, in any order (extra elements are allowed).

Changes:

  • Sources/Matchers/ArrayContainsMatcher.swift (new):
    • ArrayContainsMatcher — serialises to the integration JSON the Pact FFI expects: { "pact:matcher:type": "arrayContains", "variants": [ … ] }.
    • ObjectMatcher — encodes a [String: AnyMatcher] variant as a plain JSON object (so nested matchers are extracted per-variant by the core).
  • Sources/Matchers/Matcher+V4.swift:
    • Replaced the // TODO: "arrayContains" with two arrayContains(_:) overloads (object variants and general AnyMatcher variants).
  • Tests/Matchers/MatcherArrayContainsTests.swift (new): serialisation tests (object variants, scalar variants, empty).

⚠️ Items of Note

  • A dedicated struct is used rather than GenericMatcher because the JSON shape differs: arrayContains has a top-level variants array and no value field, whereas GenericMatcher always emits value and has no variants key.
  • The emitted integration JSON was verified against the reference implementation (pact-foundation/pact-reference, pact_ffi/src/mock_server/bodies.rs).

🧐🗒 Reviewer Notes

💁 Example

try response.jsonBody(
    .like([
        "actions": .arrayContains([
            ["name": .equals("add-item"),    "method": .oneOf(["POST"])],
            ["name": .equals("delete-item"), "method": .oneOf(["DELETE"])],
        ])
    ])
)

🔨 How To Test

Run tests :)

@pepejeria pepejeria force-pushed the feat/array-contains-matcher branch from 52550b7 to f58a049 Compare July 8, 2026 09:33
@pepejeria pepejeria force-pushed the feat/array-contains-matcher branch from f58a049 to 4505ab0 Compare July 8, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant