Skip to content

feat: add support for arrayContains matcher#131

Merged
surpher merged 1 commit into
surpher:feat/v2.0.0from
pepejeria:feat/array-contains-matcher
Jul 16, 2026
Merged

feat: add support for arrayContains matcher#131
surpher merged 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 3 times, most recently from 4505ab0 to 6fc44e8 Compare July 14, 2026 11:43
@pepejeria
pepejeria force-pushed the feat/array-contains-matcher branch from 6fc44e8 to 70690c5 Compare July 14, 2026 11:46
@surpher

surpher commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Thank you for this.

@surpher
surpher merged commit f0cfcce into surpher:feat/v2.0.0 Jul 16, 2026
2 of 5 checks passed
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.

2 participants