Giter VIP home page Giter VIP logo

Comments (7)

surpher avatar surpher commented on August 17, 2024 1

Yes sure. There might be a caveat though where v2 is full on concurrency focused. Changes the set up and structure of pact tests.
Make sure that v2 fits your needs first.

from pactswift.

StasMarynych avatar StasMarynych commented on August 17, 2024

Just noticed that arrayContaining method is implemented in v3, are there any chances that we could easily add that matcher without v4 ?

from pactswift.

StasMarynych avatar StasMarynych commented on August 17, 2024

I was able to implement some sort of arrayContains matcher in my fork. Response generation is ok, and also i tried to add matching rule by doing this:

processedMatcherValue.rules[${node_with_array_contains}] = AnyEncodable([
	"matchers": [
		"match": AnyEncodable("arrayContains"),
		"variants": AnyEncodable(${all_processed_variants})
	]
])

but arrayContains matching rules wont appear in output pact contact in case of the tests with mock server. (Encoding logic looks fine in PactBuilderTests)

PactBuilderTests:

let testBody: Any = [
	"data": [
		"foo": Matcher.ContainsLike([
			[
				"bar": Matcher.SomethingLike("string1")
			],
			[
				"baz": Matcher.SomethingLike("string2")
			]
		], useAllValues: true)
	]
]

Generated JSON: (Do we really need to duplicate internal array $.data.foo matchers if they are already located in the variants value? Or real expected values should be used instead of matcher rules in the variants key?)

matchingRules =         {
            body =             {
                "$.data.foo" =                 {
                    matchers =                     {
                        match = arrayContains;
                        variants =                         {
                            "$.data.foo[0].bar" =                             {
                                matchers =                                 (
                                                                        {
                                        match = type;
                                    }
                                );
                            };
                            "$.data.foo[1].baz" =                             {
                                matchers =                                 (
                                                                        {
                                        match = type;
                                    }
                                );
                            };
                        };
                    };
                };
                "$.data.foo[0].bar" =                 {
                    matchers =                     (
                                                {
                            match = type;
                        }
                    );
                };
                "$.data.foo[1].baz" =                 {
                    matchers =                     (
                                                {
                            match = type;
                        }
                    );
                };
            };
        };

But the final pact contacts doesn't include $.data.foo matching rules (Problem is in json format i guess, but I could not find any pact example with arrayContains matcher).

{
      "description": "Request for a an object with simpler contains like matcher",
      "providerStates": [
        {
          "name": "dynamic json"
        }
      ],
      "request": {
        "method": "GET",
        "path": "/articles/simpler/containsLikeMatcher"
      },
      "response": {
        "body": {
          "foo": [
            {
              "bar": {
                "key1": "value1",
                "key2": 123
              }
            },
            {
              "baz": {
                "key3": "value2",
                "key4": 456
              }
            }
          ]
        },
        "matchingRules": {
          "body": {
            "$.foo[0].bar.key1": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "type"
                }
              ]
            },
            "$.foo[0].bar.key2": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "integer"
                }
              ]
            },
            "$.foo[1].baz.key3": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "type"
                }
              ]
            },
            "$.foo[1].baz.key4": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "integer"
                }
              ]
            }
          }
        },
        "status": 200
      }

Data that passed into mock server also looks ok

from pactswift.

StasMarynych avatar StasMarynych commented on August 17, 2024

Finally, got the example of arrayContains rule using pact_mock_server_cli. Will refactor matcher processing to match the appropriate format

"$.baz": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "arrayContains",
                  "variants": [
                    {
                      "index": 0,
                      "rules": {
                        "": {
                          "combine": "AND",
                          "matchers": [
                            {
                              "match": "equality"
                            }
                          ]
                        }
                      }
                    },
                    {
                      "index": 0,
                      "rules": {
                        "": {
                          "combine": "AND",
                          "matchers": [
                            {
                              "match": "equality"
                            }
                          ]
                        }
                      }
                    }
                  ]
                }
              ]
            }

from pactswift.

StasMarynych avatar StasMarynych commented on August 17, 2024

Final results.

One of the tests:

Screenshot 2023-07-25 at 17 55 05

Generated JSON

{
      "description": "Request for a an object with contains like matcher",
      "providerStates": [
        {
          "name": "dynamic json"
        }
      ],
      "request": {
        "method": "GET",
        "path": "/articles/simpler/containsLikeMatcher"
      },
      "response": {
        "body": {
          "foo": {
            "bar": {
              "key1": "value1",
              "key2": 123
            }
          }
        },
        "matchingRules": {
          "body": {
            "$.foo": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "arrayContains",
                  "variants": [
                    {
                      "index": 0,
                      "rules": {
                        "bar.key1": {
                          "combine": "AND",
                          "matchers": [
                            {
                              "match": "type"
                            }
                          ]
                        },
                        "bar.key2": {
                          "combine": "AND",
                          "matchers": [
                            {
                              "match": "integer"
                            }
                          ]
                        }
                      }
                    },
                    {
                      "index": 1,
                      "rules": {
                        "baz.key3": {
                          "combine": "AND",
                          "matchers": [
                            {
                              "match": "type"
                            }
                          ]
                        },
                        "baz.key4": {
                          "combine": "AND",
                          "matchers": [
                            {
                              "match": "integer"
                            }
                          ]
                        }
                      }
                    }
                  ]
                }
              ]
            }
          }
        },
        "status": 200
      }

from pactswift.

surpher avatar surpher commented on August 17, 2024

Hey @StasMarynych
Sorry for late reply. I'm unfortunately quite far away from GitHub lately. I saw your closed PR, what happened there?

I've pulled the fork that refactored and massively rebased PactSwift code to take advantage of libpact_ffi more.
Changes are on this branch https://github.com/surpher/PactSwift/tree/feat/v2.0.0 and it has full on support for modern swift concurrency.

from pactswift.

StasMarynych avatar StasMarynych commented on August 17, 2024

Hey @surpher , thats totally fine) np

That mr was opened by the accident actually. Firstly, I wanted to be sure that current version of libpact_ffi that is in PactSwiftMockServer package supports that new type of matcher at all. Now, I see that everything is ok. So, if there is no arrayContains matcher in https://github.com/surpher/PactSwift/tree/feat/v2.0.0 would it be better to create the MR based on this branch?

from pactswift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.