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

Question - How to fix "Pact Binary Error: WARN: Ignoring unsupported matching rules" #205

Closed
cchen-kenzan opened this issue Aug 2, 2018 · 18 comments

Comments

@cchen-kenzan
Copy link

cchen-kenzan commented Aug 2, 2018

Software versions

  • OS: Mac OSX 10.11.6
  • Consumer Pact library: @pact-foundation/pact-node@^6.13.0": version "6.19.7"
  • Provider Pact library: NA
  • Node Version: v8.9.4

Note: The pact tests seem to be running correctly, but getting the following Pact binary errors and wondering how we can resolve them.

Expected behaviour

I want to be able to clear out these Pact binary errors.

Actual behaviour

I'm gettting the following errors when I'm running my interactions to create the pact contracts:

    Pact Binary Error: WARN: Ignoring unsupported matching rules {"match"=>"type"} for path $['body']['createdDate']
    WARN: Ignoring unsupported matching rules {"match"=>"type"} for path $['body']['lastModified']
    WARN: Ignoring unsupported matching rules {"match"=>"regex", "regex"=>"^[A-Za-z0-9 -().\\/+]+$"} for path $['body']['description']
    WARN: Ignoring unsupported matching rules {"match"=>"type"} for path $['body']['id']

Steps to reproduce

We are matching using like in the following manner:

const { Pact, Matchers } = require('@pact-foundation/pact');
const { like, eachLike, regex } = Matchers;

const skillData = {
  createdDate: 1531427089,
  lastModified: 1531427089,
  description: 'Test Description',
  sourceLink: 'http://www.test.com',
  name: 'Test Name',
  id: 123
};

const skillMatchers = {
  createdDate: like(skillData.createdDate),
  lastModified: like(skillData.lastModified),
  description: regex({
    matcher: '^[A-Za-z0-9 -()./+]+$',
    generate: skillData.description
  }),
  id: like(skillData.id),
  name: regex({
    matcher: '^[A-Za-z0-9& ,.!_]+$',
    generate: skillData.name
  }),
  sourceLink: regex({
    matcher: '^(http://www.|https://www.|http://|https://)?[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(:[0-9]{1,5})?(/.*)?$',
    generate: skillData.sourceLink
  })
};

  describe('the getAllSkills function', () => {
    beforeAll(() => {
      return provider.addInteraction({
        uponReceiving: 'a GET request to get all skills',
        withRequest: {
          method: 'GET',
          path: '/api/skills',
          query: 'sort=name'
        },
        willRespondWith: {
          status: 200,
          headers: resHeaders,
          body: eachLike(skillMatchers)
        }
      });
    });

    it('returns all the skills', () => {
      expect.assertions(2);
      return skillsApi.getAllSkills()
        .then(skills => {
          expect(Array.isArray(skills)).toBe(true);
          expect(skills).toEqual([skillData]);
        });
    });
  });
@mefellows
Copy link
Member

@cchen-kenzan is it just those top 4 that are showing up as ignored, or all of the body keys?

Can you please also let us know which version of @pact-foundation/pact you have? (you've shown pact-node which is a related, important lib).

Also there is a micro version upgrade on pact-node you might like to try to see if it addresses your issue.

@bethesque any ideas? I can imagine that the eachLike matcher cascades, but would further assume that the issue would be present on the other keys and not just the four mentioned.

@bethesque
Copy link
Member

I believe I've fixed this in the very latest version of pact support. Does the js library version mentioned above have the latest standalone?

@mefellows
Copy link
Member

It should be at 1.54.1 which was the latest, as of 2 hours ago. Does it need 1.54.2?

@bethesque
Copy link
Member

No, that was an unrelated fix. Bother. I was sure I'd fixed this! @cchen-kenzan can you throw together a git repo that recreates the issue so I can reproduce this on my machine?

@mefellows
Copy link
Member

mefellows commented Aug 3, 2018

@bethesque sorry, just to be clear, the version of standalone in v6.19.8 of pact-node is 1.54.1, which we need @cchen-kenzan to test first (they are currently on 6.19.7).

@bethesque
Copy link
Member

Oh, right. Please update @cchen-kenzan!

@cchen-kenzan
Copy link
Author

Thanks @bethesque and @mefellows it seems to have resolved most of my issues, but I'm still getting one pact binary error/warning on the following code:

const personSkillObj = like({
  lastModified: 1531427089,
  learningPath: false,
  proficiency: 1,
  name: 'Test Skill'
});

const personObj = like({
  id: 10000,
  lastModified: 1531427089,
  name: 'Test User',
  radars: eachLike(12345),
  reports: eachLike('Test Report'),
  role: term({
    matcher: 'User|SiteAdmin|TechradarAdmin',
    generate: 'User'
  }),
  username: 'testuser',
  skills: eachLike(personSkillObj)
});

describe('the getAllPeople function', () => {
    beforeAll(() => {
      return provider.addInteraction({
        uponReceiving: 'a GET request to get all people',
        withRequest: {
          method: 'GET',
          path: '/api/persons'
        },
        willRespondWith: {
          status: 200,
          headers: resHeaders,
          body: eachLike(personObj)
        }
      });
    });

    it('should return all the people', () => {
      expect.assertions(2);
      return teamApi.getAllPeople()
        .then(people => {
          expect(Array.isArray(people)).toBe(true);
          expect(people[0].id).toBe(10000);
        });
    });
  });

This is the unsupported matching rule:

[2018-08-03T18:23:51.336Z] ERROR: pact-node@6.19.8/19589 on clairech01-mac:
    Pact Binary Error: WARN: Ignoring unsupported matching rules {"match"=>"type"} for path $['body'][*]
    WARN: Ignoring unsupported matching rules {"match"=>"type"} for path $['body'][*]['skills'][*]

I think it may have to do with using eachLike in a nested fashion.

@bethesque
Copy link
Member

Yes, I think that is why, but I thought I'd fixed that part. I'll try using your example and see if I can reproduce it.

@bethesque
Copy link
Member

Ok, v1.54.3 of the standalone should fix this!!!!

@czebe
Copy link

czebe commented Aug 13, 2018

What is this version number for?
How can we know our package was updated?
pact standalone cli is at 6.19.8
pact-support is at 1.7.2

@mefellows
Copy link
Member

All you need to check this is that your version of pact-node is at least v6.19.8 or above.

@czebe
Copy link

czebe commented Aug 14, 2018

I'm still getting this error when using matching rule on query parameters. Shouldn't this be supported too?

@bethesque
Copy link
Member

Dammit! This is like whackamole. Please provide your code.

The matching is correct, it's just that when you have nested likes, it's complicated to ensure that you get the correct warnings.

@czebe
Copy link

czebe commented Aug 14, 2018

My spec is not even nested:

provider.addInteraction({
  uponReceiving: "existing product request",
  state: "product exists and user is authorized to access resource",
  withRequest: {
    method: "GET",
    path: "/products",
    query: {
      id:  term({
        generate: "123",
        matcher: "[1-9][0-9]*" // <-- This is causing the error
      })
    }
  },
  willRespondWith: {
     ...
  }
});

@bethesque
Copy link
Member

I've worked out why the warning is there for the query, I just need to work out what to do about it. It can be safely ignored.

@jkrnak
Copy link

jkrnak commented Aug 23, 2018

I have similar problem with an array rule. I'm using pact-1.54.4
I don't think the warning is ignorable, it actually is begin ignored by the pact-provider-verifier standalone.

My matching rule is:

          "$.body.features[*].properties.price": {
            "match": "type"
          },

And I get
WARN: Ignoring unsupported matching rules {"match"=>"type"} for path $['body']['features'][*]['properties']['price']

ps: I'm assuming I'm reporting this to the wrong repo, sorry about it. If you tell me where this should be reported @bethesque I'll create an issue in that repo.

ps2: pact is awesome! :) keep up the good work!

@bethesque
Copy link
Member

Thanks! The issue belongs in the pact-support repository. Can you raise the issue there please? How are you creating it through the DSL?

Most these warnings have actually been false positives - they occur because there is more than one place in the JSON hierarchy that turns the "match by type" (Pact.like) logic on, and once it's turned on, a repeated "match by type" (nesting a Pact.like) is redundant. It's been remarkably tricky to work out all the nesting cases and make sure that rules that are genuinely not being applied get logged, while making sure the redundant ones aren't!

@jkrnak
Copy link

jkrnak commented Aug 23, 2018

Thanks, I've opened the issue: pact-foundation/pact-support#61

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

5 participants