Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pact V3 eachKeyLike matcher is not being applied properly #1434

Closed
Shan-V opened this issue Sep 14, 2021 · 2 comments
Closed

Pact V3 eachKeyLike matcher is not being applied properly #1434

Shan-V opened this issue Sep 14, 2021 · 2 comments

Comments

@Shan-V
Copy link

Shan-V commented Sep 14, 2021

Eachkeylike matcher is not working as expected

const modelResponse = {
  categories: {
    additionalProp1: {
      id: 'string',
      items: ['string'],
      name: 'string',
      sortOrder: 0,
    },
    additionalProp2: {
      id: 'string',
      items: ['string'],
      name: 'string',
      sortOrder: 0,
    },
    // Nth additional Prop
    additionalPropN: {
      id: 'string',
      items: ['string'],
      name: 'string',
      sortOrder: 0,
    },
  },
};

This is a JS matcher implementation

const expectation = {
    categories: eachKeyLike('1SMKX6JGWKY3J', {
        id: regex(/^[A-Z0-9]+$/,'1SMKX6JGWKY3J'),
        name: string('Dessert'),
        sortOrder: integer(3),
        items: atLeastOneLike(string('F79QJX241ZAHP')),
      })
}

Actual response from provider

const actualResponse = {
    categories: {
        '4KS8YA1PY4YPC': {
          id: '4KS8YA1PY4YPC',
          name: 'Plain ol\' Crepe',
          sortOrder: 1,
          items: ['19AGCTC43X5YC'],
        },
        'D70N53J6R34K9': {
          id: '41SJNCEK3FXTJ',
          name: 'Flavored Crepes',
          sortOrder: 0,
          items: ['D70N53J6R34K9'],
        },
      },
    }

However getting a error log as following

    1.1) body: $.categories Expected 1SMKX6JGWKY3J={"id":"1SMKX6JGWKY3J","items":["F79QJX241ZAHP"],"name":"Dessert","sortOrder":3} but was missing

    {
    +  "4KS8YA1PY4YPC": {
    +    "id": "4KS8YA1PY4YPC",
    -  "1SMKX6JGWKY3J": {
    -    "id": "1SMKX6JGWKY3J",
    +    "name": "Plain ol' Crepe",
    -    "name": "Dessert",
    +    "sortOrder": 1,
    -    "sortOrder": 3
        "items": [
    +      "19AGCTC43X5YC"
    +    ]
    -      "F79QJX241ZAHP"
    -    ],
    +  },
    +  "D70N53J6R34K9": {
    +    "id": "D70N53J6R34K9",
    +    "name": "Flavored Crepes",
    +    "sortOrder": 0,
    +    "items": [
    +      "19AGCTC43X5YC"
    +    ]
      }
@uglyog
Copy link
Member

uglyog commented Sep 18, 2021

What version of Pact-JVM are you using? The Pact-JS eachKeyLike matcher is using the values matching rule, which requires Pact-JVM 4.2.x.

@Shan-V
Copy link
Author

Shan-V commented Sep 24, 2021

It seems working as expected with Pact-JVM 4.2.8. I was testing with 4.1.x versions.

@Shan-V Shan-V closed this as completed Sep 24, 2021
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

No branches or pull requests

2 participants