Skip to content

Pact Verifier specifying auto generated id in producer tests #166

@illumina-icancio

Description

@illumina-icancio

Is there a way to modify or pass an auto-generated id so that my verifier will be able to find a newly inserted record when it calls the get method?

Example: I have the following API call: GET http://localhost:5000/products/Product-123 and will return
{
"id": "Product-123",
"name": "Some Product Name"
}

In my pact file, I have specified the path as: /products/Product-123 with the specific Id:
{
"description": "A valid GET request for Product",
"providerState": "Products exists",
"request": {
"method": "get",
"path": "/products/Product-123"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json; charset=utf-8"
},
"body": {
"id": "Product-123",
"name": "Some Product Name"
}
}
}
However, when the provider tests are run, the database is initially empty and I have to stage/set up the data in the provider state. When records are created/inserted in the database, the Ids are auto-generated and there’s no way to match what is specified in the pact file. So in my tests, the id generated from my data setup will have a value different from what is specified in my pact file.

When I run my tests on the provider side, the request I specified in my pact file will return a 404 because it does not exist. Is there a support/workaround for this where I can replace the id or the path? If yes, can someone point me to an example or a documentation please.

Appreciate any help. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions