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

I'd like to be able to utilise "like" and "eachLike" Matchers #191

Open
2 tasks done
stevenpollack opened this issue Feb 28, 2024 · 3 comments
Open
2 tasks done

I'd like to be able to utilise "like" and "eachLike" Matchers #191

stevenpollack opened this issue Feb 28, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@stevenpollack
Copy link

Checklist

Before making a feature request, I have:

Feature description

Maybe the verifyTest method can take options like responseBody (and requestBody), and these would contain mock data would passed along to like or eachLike. E.g.

const mockResponse = {
  authorEmail: "[email protected]",
  componentType: ComponentType.SSA,
  description: "Description of the component",
  id: -999,
}

const interaction = new ApolloGraphQLInteraction()
  .uponReceiving('a query')
// ... you get the idea ...
  .willRespondWith({
    status: 200,
    body: like(mockResponse)
  }); 

So if I did something like

describe('some component', () => { 
  afterAll(async () => {
    await pactMswAdapter.writeToFile();
    pactMswAdapter.clear();
  });
  test('some specific query', () => {
    // go through the AAAs
    pactMswAdaptor.verifyTest({responseBody: like(mockResponse)});
  });
})

The resulting pact .json files could have appropriately rendered matchingRules properties. For instance, a response property of a graphql interaction might look like:

"response": {
  "body": {
    "data": {
      "deleteComponent": {
        "authorEmail": "[email protected]",
        "componentType": "ssa",
        "description": "Description of the component",
        "id": -999,
      }
    }
  },
  "headers": {
    "Content-Type": "application/json"
  },
  "matchingRules": {
    "$.body.data.deleteComponent.authorEmail": {
      "match": "type"
    },
    "$.body.data.deleteComponent.componentType": {
      "match": "regex",
      "regex": "null|ssa|cs"
    },
    "$.body.data.deleteComponent.description": {
      "match": "type"
    },
    "$.body.data.deleteComponent.id": {
      "match": "type"
    },
  },
  "status": 200
}

Use case

This is a very sensible thing to have when you're only interested in the shape of a response and not the exact values. For example, a service handling basic user information like

{
  name: string,
  age: number,
  email: string,
  country: string,
}

might not care about the exact age or country of the test data, so long as they are numbers and strings. Making our test data flexible allows for (cosmetic) data refactoring without worry about can-i-deploy freaking out.

Conversely, the adapter loses much of its potential utility if it creates pacts that are rigid in their assertions. Teams that require the use of like and eachLike (for example) won't be inclined to use this adapter because they'll have to manually define interactions a la pact-js.

@stevenpollack stevenpollack added the enhancement New feature or request label Feb 28, 2024
@YOU54F
Copy link
Member

YOU54F commented Jun 28, 2024

I originally designed this tool to work with bi-directional contract testing whereby schema matching is done against the OAS from the pact example response and matchers are not required or used

https://docs.pactflow.io/docs/bi-directional-contract-testing/tools/msw

I would consider enhancements to the tool in order to support matchers, but I am unlikely to deliver it myself

@braydend
Copy link

@stevenpollack have you made an attempt to add the matching functionality?
I'm also quite keen for this functionality. Happy to help get this over the line

@stevenpollack
Copy link
Author

stevenpollack commented Aug 16, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants