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
Add ability to set provider state #22
Add ability to set provider state #22
Conversation
Thanks Simon 👏 ! Apologies for the delay in getting back to you here. At first glance, it seems a reasonable suggestion. There are a couple of questions / comments:
Other than that, the PR is much appreciated and it looks OK to me. I'll unblock the build to ensure it passes all checks. |
usePactRequest: (option: AnyObject, alias: string) => Chainable | ||
usePactGet: (alias: string, pactConfig: PactConfigType) => Chainable | ||
usePactGet: (alias: string, pactConfig: PactConfigType, providerState?: string) => Chainable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure pactConfig
should have been here. it isn't shown in the examples and wasn't used in line 39 until this change.
}) | ||
}) | ||
} | ||
} | ||
|
||
const requestDataMap: AnyObject = {} | ||
|
||
const usePactGet = (alias: string) => { | ||
const usePactGet = (alias: string, pactConfig: PactConfigType, providerState: string = '') => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pactConfig
is a required field, so this would be a breaking interface change for the user.
Also I don't think it should be included?
@@ -72,7 +72,7 @@ before(() => { | |||
cy.setupPact('ui-consumer', 'api-provider') | |||
}) | |||
``` | |||
### cy.usePactWait([alias] | alias) | |||
### cy.usePactWait([alias] | alias, providerState) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the examples show providerState as non-optional.
it is optional, and will default to ''
as per this change.
@@ -106,7 +107,8 @@ describe('constructPactFile', () => { | |||
pactConfig: { | |||
consumerName: 'ui-consumer', | |||
providerName: 'todo-api' | |||
} | |||
}, | |||
providerState: 'State' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add new test cases to show the additional of state, if set, and defaulting to ''
if not set please.
Thanks @SimonBachmaier for your first contribution 🚀 I think adding provider state and matchers to cypress-pact is valuable but with caveats, which we haven't distinguished well at the moment. At least anecdotally from feedback pactflow/docs.pactflow.io#125 Few comments on the change It is probably worth a note on the README that this adapter generates pacts in a v2 specification format, so uses This adapter wasn't intended for use with regular CDCT, due to lack of provider states and matchers, (and actually if you are able to test your app with Pact and Cypress to generate Pacts, you can easily test at the unit test level, and get quicker feedback and more granular control) Re-using the pact contracts, or using shared fixtures between your Integration and Unit tests is a good technique for reusability and sharing of test data. One of our community champions created a video about it here https://www.youtube.com/watch?v=MtJA90VC9g4&ab_channel=TheTestTribe |
I'd probably consider that as a separate change @SimonBachmaier just another note, we use conventions commit messages to generate changelogs https://github.com/pact-foundation/pact-js/blob/master/CONTRIBUTING.md#release-notes We could do with adding a contributing section to this repo, but for now you may want to update your commit message for the feature to |
Thank you very much for reviewing the PR. I will add the mentioned changes and then come back to you. By the sound of it, this adapter is built for a completely different use case than what I initially understood. My team wanted to use the adapter to validate the mocked network calls used in our Cypress tests. (We also already use jest-pact) If this adapter is meant for something else and doesn't aim to generate contracts that can be used with a pact broker, then we would need a different solution anyway. |
Yes, it's primary purpose is for generating pact files, but for use with Pactflow's https://docs.pactflow.io/docs/bi-directional-contract-testing/ feature. We actually use Cypress and Pact at Pactflow, and we are not using this adapter. We would obviously like to avoid the mock drifts, and we actually achieve this is by reusing the payload definitions from our Pact tests in the cypress route stubs. The approach is summarised here: https://stackoverflow.com/a/68492932/1008568
Having these two features would certainly improve the reliability of the tests and we would be more than open to accepting a PR that allows this. The key thing is that we would like to preserve the simplicity of the interface for those that just want a simple solution to stub network routes, without having to think about matchers etc. |
Hey @SimonBachmaier if you want to address the couple of PR comments or comment on them, I am still happy to help move this PR along :) |
Hey @mefellows and @YOU54F Thank you for your great input and sorry again for not getting back to this request earlier. |
Thanks Simon, no worries - if there are any changes let us know. I'll close this off for now but we can resurrect in the future if we decide to add it. |
Similar to issue #16 we had the need to be able to set the provider state when using this plugin.
This pull request adds functionality to pass the state when calling usePactGet and usePactWait
The state is simply passed as a new parameter:
New
Old