Closed uglyog closed 2 years ago
@uglyog I'd like to try and work on this issue, if I could get a small hint at what the relevant parts of the codebase are, I could get started. Thanks!
@brendan-donegan We'd love that! I'll let Ron chime in with details, as I'm not too familiar with the V3 branch myself (...yet!). I'm keen to start uplift towards getting this all to a point where it's ready to release.
Here's what I do know:
We access the underlying pact implementation through a native interface (exposed from Rust to with Neon). There's a small wrapper that is included in this repo in the native
folder. This is (I think) compiled on npm install
.
In response to a question on slack, Ron added a comment to a different issue which might help you get started: https://github.com/pact-foundation/pact-js/issues/515#issuecomment-705307100
I notice you're in the pact-foundation slack - I'm going to make a channel there for coordination and communication about the V3 spec branch. Maybe we can help each other as we pick up the context together!
There are three things that need to be done:
This is the generated JSON snippet for that Groovy test:
"generators": {
"header": {
"LOCATION": {
"type": "ProviderState",
"expression": "http://server/users/${userId}",
"dataType": "STRING"
}
},
"body": {
"$.userId": {
"type": "ProviderState",
"expression": "userId",
"dataType": "INTEGER"
}
}
}
Allow the provider state callbacks to return a key-value map. For the consumer tests the keys need to correspond to the variables defined in the method used in step 1. I've done most of the work for this, but this bit here needs to be completed: https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/native/src/verify.rs#L165 - the val
variable there will be the map of key-values (I think).
Complete the implementation in Pact-Rust. I think it is 95% done. I left the following unused variable warning as a reminder to complete this bit.
warning: unused variable: `verification_context`
--> pact_verifier/src/messages.rs:19:3
|
19 | verification_context: HashMap<String, Value>
| ^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_verification_context`
|
= note: `#[warn(unused_variables)]` on by default
But that looks like for messages, so the HTTP one might be done. I'll double check that one.
Of course, step 4 is write up some docs and examples on how to use it.
I'm not going to lie, that's quite a bit to absorb :) I'll see if I can get anywhere with this this week.
@brendan-donegan thanks for looking in to this, any updates?
I'm going to pick this up today
v10.0.0-beta.22 has been released. I still need to provide docs for it, but there is an example at https://github.com/pact-foundation/pact-js/tree/feat/v3.0.0/examples/v3/provider-state-injected
Hi, when we use fromProviderState in the .withRequest we are seeing the Pact object rather than the example value.
Mock server failed with the following mismatches:
1) BodyMismatch (at $.payment.tokenValue) Type mismatch: Expected Map {"expression":"${sessionId}","pact:generator:type":"ProviderState","pact:matcher:type":"type","value":"S0002366452877L42667335E4"} but received String "S0002084432868J82819262U7"
2) BodyMismatch (at $.jId) Type mismatch: Expected Map {"expression":"${jId}","pact:generator:type":"ProviderState","pact:matcher:type":"type","value":"8b8c3858-8eac-4477-b02f-ae3458161428"} but received String "8b8c3858-8eac-4477-b02f-ae3458161428"
at node_modules/@pact-foundation/src/v3/pact.ts:217:35
@MarkConway94: Can you share the code where you use fromProviderState
?
Hi @TimothyJones we use it here
it("Authorises a payment", async () => {
provider
.given("A journey has started")
.uponReceiving("A request to authorise a payment")
.withRequest({
method: "POST",
path: "/auth",
body: {
jId: fromProviderState("${jId}", startJId),
payment: {
tokenType: "SessionId",
tokenValue: fromProviderState("${sessionId}", "SESSION0002366452877L42667335E4"),
},
},
})
.willRespondWith({
status: 200,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST",
},
body: {
status: regex("Authorised|Failed|Retry", "Authorised"),
result: {
jId: string(startJId),
},
},
});
@MarkConway94 I can't see anything wrong with your example. Looks like it is not using the latest PactNative shared library. Ensure you have v10.0.0-beta.22 in your package.json, then delete node_modules/@pact-foundation/pact/native/
and re-install v10.0.0-beta.22.
I've noticed that NPM can be really stupid with versions. If you have "@pact-foundation/pact": "^10.0.0-beta"
in your package.json, it always installs v10.0.0-beta.9.
Hi @uglyog we have this in our package.json
"@pact-foundation/pact": "^10.0.0-beta.22",
and we see this in our package-lock.json
"@pact-foundation/pact": {
"version": "10.0.0-beta.22",
"resolved": "https://registry.npmjs.org/@pact-foundation/pact/-/pact-10.0.0-beta.22.tgz",
@MarkConway94 can you run your tests with debug (setting the environment variable LOG_LEVEL=debug), and provide the logs?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I believe this is actually fixed/completed, closing.
For context: https://pact-foundation.slack.com/archives/C9VBGLUM9/p1602059445097700?thread_ts=1601979678.046000&cid=C9VBGLUM9
Provider state injected values are currently not support in the JS consumer DSL or in the provider state callbacks.