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 345 forks source link

[V3] A way to check an xml element by its exact text value in the list of same xml elements #619

Open saw-jan opened 3 years ago

saw-jan commented 3 years ago

Before making a feature request, I have:

Background

Currently, we are using Xml builder as below inorder to check that the response has similar xml

new XmlBuilder('1.0', '', 'ocs')
  .build(ocs => {
    ocs.appendElement('meta', '', (meta) => {
      return ocsMeta(meta, 'ok', '100')
    }).appendElement('data', '', data => {
         data.appendElement('groups', '', groups => {
           groups.eachLike('element', '', group => {
              group.appendText(config.testGroup)
           })
         })
     })
})
groups.eachLike('element', '', group => {
  group.appendText(config.testGroup)
})

This checks by type i.e. has <element> with some string

Feature description

In XmlBuilder, a way to check the presence of an element by its exact text value in the list of elements (don't care about other element's values)

Use case

We have response like:

<ocs>
    <meta>
        <status>ok</status>
        <statuscode>100</statuscode>
        <message>OK</message>
    </meta>
    <data>
        <groups>
            <element>users</element>
            <element>g102</element>
        </groups>
    </data>
</ocs>

We wanted to check that <groups> has <element> with text g102 but don't care about <element>users</element> and other <element>s inside <groups>

individual-it commented 3 years ago

what would be handy for us is something like

groups.containsExactly('element', '{}', group => {
  group.appendText(config.testGroup)
}, 1)

so that the check ends up not only testing the type but also the content, but only for that one element and ignore all other elements