Hi I'm running the latest Pactv3 beta pact-js cons...
# pact-js
a
Hi I'm running the latest Pactv3 beta pact-js consumer and the mocked server is returning null for a response body property based on
arrayContaining
- there are other properties using that matcher which are working fine. Is this a known issue, or is there something in the logs I should be looking for to give me a clue?
🤔 1
m
If you could please set log level to debug and share we could take a look
a
Thanks Matt I'll simplify the pact as much as possible and post the debug on Monday. Incidentally hit an issue with the date(pattern, value) matcher in Pactv3 js beta where the mock server always returns todays date rather the value I specify as the 2nd arg.
m
Thanks. I'll take a look at the date matcher next time I'm in there
a
Hi Matt - having narrowed things down a bit I think the issue might be due to nested arrayContaining. This is the query:
Copy code
query badQuery($id: ID!) {
        foo(id: $id) {
            bar {
              results {
                  __typename
              }
            }
        }
    }
This is the expectation:
Copy code
foo: {
  bar: arrayContaining(
    {
      results: arrayContaining({
        __typename: equal('Result')
       })
     }
   )
  }
This is the debug level log:
Copy code
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.variables
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.variables.id
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data.foo
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data.foo.bar
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.results
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.__typename
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.results
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.results[*]
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.results[*].__typename
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Skipping the matching rule (skip_matchers == true)
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data.foo.bar
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data.foo.bar[*]
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data.foo.bar[*].results
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher
[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Skipping the matching rule (skip_matchers == true)
[2022-03-16T10:07:04Z DEBUG pact_plugin_driver::catalogue_manager] Updated catalogue entries:
    core/interaction/http
    core/interaction/https
[2022-03-16T10:07:04Z DEBUG pact_plugin_driver::catalogue_manager] Updated catalogue entries:
    core/content-generator/binary
    core/content-generator/json
    core/content-matcher/json
    core/content-matcher/multipart-form-data
    core/content-matcher/text
    core/content-matcher/xml
[2022-03-16T10:07:04Z DEBUG pact_plugin_driver::catalogue_manager] Updated catalogue entries:
    core/matcher/v1-equality
    core/matcher/v2-max-type
    core/matcher/v2-min-type
    core/matcher/v2-minmax-type
    core/matcher/v2-regex
    core/matcher/v2-type
    core/matcher/v3-content-type
    core/matcher/v3-date
    core/matcher/v3-datetime
    core/matcher/v3-decimal-type
    core/matcher/v3-includes
    core/matcher/v3-integer-type
    core/matcher/v3-null
    core/matcher/v3-number-type
    core/matcher/v3-time
    core/matcher/v4-array-contains
    core/matcher/v4-equals-ignore-order
    core/matcher/v4-max-equals-ignore-order
    core/matcher/v4-min-equals-ignore-order
    core/matcher/v4-minmax-equals-ignore-order
    core/matcher/v4-not-empty
    core/matcher/v4-semver
[2022-03-16T10:07:04Z DEBUG pact_mock_server::mock_server] Started mock server on 127.0.0.1:65384
[2022-03-16T10:07:04Z DEBUG hyper::proto::h1::io] parsed 7 headers 
[2022-03-16T10:07:04Z DEBUG hyper::proto::h1::conn] incoming body is content-length (178 bytes) 
[2022-03-16T10:07:04Z DEBUG hyper::proto::h1::conn] incoming body completed 
[2022-03-16T10:07:04Z DEBUG pact_mock_server::hyper_server] Creating pact request from hyper request
[2022-03-16T10:07:04Z DEBUG pact_mock_server::hyper_server] Extracting query from uri /graphql
[2022-03-16T10:07:04Z INFO  pact_mock_server::hyper_server] Received request HTTP Request ( method: POST, path: /graphql, query: None, headers: Some({"host": ["127.0.0.1:65384"], "content-type": ["application/json"], "content-length": ["178"], "user-agent": ["node-fetch/1.0 (+<https://github.com/bitinn/node-fetch>)"], "accept": ["*/*"], "connection": ["close"], "accept-encoding": ["gzip", "deflate"]}), body: Present(178 bytes, application/json) )
[2022-03-16T10:07:04Z DEBUG pact_mock_server::hyper_server]      body: '{"operationName":"badQuery","variables":{"id":"1"},"query":"query badQuery($id: ID!) {\n  foo(id: $id) {\n    bar {\n      results {\n        __typename\n      }\n    }\n  }\n}"}'
[2022-03-16T10:07:04Z INFO  pact_matching] comparing to expected HTTP Request ( method: POST, path: /graphql, query: None, headers: Some({"Content-Type": ["application/json"]}), body: Present(178 bytes, application/json) )
[2022-03-16T10:07:04Z DEBUG pact_matching]      body: '{"operationName":"badQuery","query":"query badQuery($id: ID!) {\n  foo(id: $id) {\n    bar {\n      results {\n        __typename\n      }\n    }\n  }\n}","variables":{"id":"1"}}'
[2022-03-16T10:07:04Z DEBUG pact_matching]      matching_rules: MatchingRules { rules: {BODY: MatchingRuleCategory { name: BODY, rules: {DocPath { path_tokens: [Root, Field("variables"), Field("id")], expr: "$.variables.id" }: RuleList { rules: [Type], rule_logic: And, cascaded: false }} }, PATH: MatchingRuleCategory { name: PATH, rules: {} }} }
[2022-03-16T10:07:04Z DEBUG pact_matching]      generators: Generators { categories: {} }
[2022-03-16T10:07:04Z DEBUG pact_matching::matchers] String -> String: comparing '/graphql' to '/graphql' using Equality (false)
[2022-03-16T10:07:04Z DEBUG pact_matching] expected content type = 'application/json', actual content type = 'application/json'
[2022-03-16T10:07:04Z DEBUG pact_matching] content type header matcher = 'RuleList { rules: [], rule_logic: And, cascaded: false }'
[2022-03-16T10:07:04Z DEBUG pact_plugin_driver::catalogue_manager] Looking for a content matcher for application/json
[2022-03-16T10:07:04Z DEBUG pact_matching] No content matcher defined for content type 'application/json', using core matcher implementation
[2022-03-16T10:07:04Z DEBUG pact_matching] Using body matcher for content type 'application/json'
[2022-03-16T10:07:04Z DEBUG pact_matching::json] compare: Comparing path $
[2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_maps: Comparing maps at $: {"operationName": String("badQuery"), "query": String("query badQuery($id: ID!) {\n  foo(id: $id) {\n    bar {\n      results {\n        __typename\n      }\n    }\n  }\n}"), "variables": Object({"id": String("1")})} -> {"operationName": String("badQuery"), "query": String("query badQuery($id: ID!) {\n  foo(id: $id) {\n    bar {\n      results {\n        __typename\n      }\n    }\n  }\n}"), "variables": Object({"id": String("1")})}
[2022-03-16T10:07:04Z DEBUG pact_matching::json] compare: Comparing path $.operationName
[2022-03-16T10:07:04Z DEBUG pact_matching::json] JSON -> JSON: Comparing '"badQuery"' to '"badQuery"' using Equality -> Ok(())
[2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_values: Comparing 'String("badQuery")' to 'String("badQuery")' at path '$.operationName' -> Ok(())
[2022-03-16T10:07:04Z DEBUG pact_matching::json] compare: Comparing path $.query
[2022-03-16T10:07:04Z DEBUG pact_matching::json] JSON -> JSON: Comparing '"query badQuery($id: ID!) {\n  foo(id: $id) {\n    bar {\n      results {\n        __typename\n      }\n    }\n  }\n}"' to '"query badQuery($id: ID!) {\n  foo(id: $id) {\n    bar {\n      results {\n        __typename\n      }\n    }\n  }\n}"' using Equality -> Ok(())
[2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_values: Comparing 'String("query badQuery($id: ID!) {\n  foo(id: $id) {\n    bar {\n      results {\n        __typename\n      }\n    }\n  }\n}")' to 'String("query badQuery($id: ID!) {\n  foo(id: $id) {\n    bar {\n      results {\n        __typename\n      }\n    }\n  }\n}")' at path '$.query' -> Ok(())
[2022-03-16T10:07:04Z DEBUG pact_matching::json] compare: Comparing path $.variables
[2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_maps: Comparing maps at $.variables: {"id": String("1")} -> {"id": String("1")}
[2022-03-16T10:07:04Z DEBUG pact_matching::json] compare: Comparing path $.variables.id
[2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_values: Calling match_values for path $.variables.id
[2022-03-16T10:07:04Z DEBUG pact_matching::json] JSON -> JSON: Comparing '"1"' to '"1"' using Type -> Ok(())
[2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_values: Comparing 'String("1")' to 'String("1")' at path '$.variables.id' -> Ok(())
[2022-03-16T10:07:04Z DEBUG pact_matching] --> Mismatches: []
[2022-03-16T10:07:04Z DEBUG pact_mock_server::hyper_server] Test context = {"mockServer": Object({"href": String("<http://127.0.0.1:65384>"), "port": Number(65384)})}
[2022-03-16T10:07:04Z INFO  pact_mock_server::hyper_server] Request matched, sending response HTTP Response ( status: 200, headers: Some({"Content-Type": ["application/json"]}), body: Present(43 bytes, application/json) )
[2022-03-16T10:07:04Z DEBUG pact_mock_server::hyper_server]      body: '{"data":{"foo":{"bar":[{"results":null}]}}}'
[2022-03-16T10:07:04Z DEBUG hyper::proto::h1::io] flushed 355 bytes 
[2022-03-16T10:07:04Z INFO  pact_mock_server::mock_server] Writing pact out to 'C:\Dev\git_repos\apps\case_notes_on_the_go\pacts\ena-app-apigateway.json'
[2022-03-16T10:07:04Z DEBUG pact_models::pact] Merging pact with file "C:\\Dev\\git_repos\\apps\\case_notes_on_the_go\\pacts\\ena-app-apigateway.json"
[2022-03-16T10:07:04Z WARN  pact_models::pact] Note: Existing pact is an older specification version (V3), and will be upgraded
[2022-03-16T10:07:04Z DEBUG pact_mock_server::server_manager] Shutting down mock server with port 65384
[2022-03-16T10:07:04Z DEBUG pact_mock_server::server_manager] Shutting down mock server with port 65384 - MockServerMetrics { requests: 1 }
[2022-03-16T10:07:04Z DEBUG pact_mock_server::mock_server] Mock server cf98a3b4-4aa0-4836-8bcb-9f144d34a04b shutdown - MockServerMetrics { requests: 1 }
[2022-03-16T10:07:04Z DEBUG hyper::server::shutdown] signal received, starting graceful shutdown 

Error: expect(received).resolves.toEqual(expected) // deep equality

- Expected  - 5
+ Received  + 1

  Object {
    "foo": Object {
      "bar": Array [
        Object {
-         "results": Array [
-           Object {
-             "__typename": "Result",
-           },
-         ],
+         "results": null,
        },
      ],
    },
  }
m
Thanks. It looks to be returning
{"data":{"foo":{"bar":[{"results":null}]}}}
despite the nested
arrayContaining
Could you please raise the bug at https://github.com/pact-foundation/pact-js/issues/ and we’ll get it looked into? I can’t tell from here if the issue is in Pact JS or the (rust) core.
Suspect core, at this stage
a
OK thanks - will do
m
Awesome, thanks