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

Allow Provider State to be set dynamically instead of hard code #55

Open
2 tasks done
TKDMaster12 opened this issue Oct 25, 2022 · 4 comments
Open
2 tasks done
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@TKDMaster12
Copy link

TKDMaster12 commented Oct 25, 2022

Checklist

Before making a feature request, I have:

Feature description

I have a bunch of pacts for one project. I would like to add states to make the provider side of the pact work better.

@TKDMaster12 TKDMaster12 added the enhancement New feature or request label Oct 25, 2022
@YOU54F
Copy link
Member

YOU54F commented Oct 26, 2022

The relevant line of code is here, providerState isn't set

Feel free to drop a PR or suggest how you wish the provider state to be set, as in what information you actually want it it.

I hadn't built the tool with the idea of working with providerStates/matchers to work with traditional CDCT testing, but would be happy to see someone extend the tool to do so

@YOU54F YOU54F added the good first issue Good for newcomers label Dec 9, 2022
@jaswanthm
Copy link

We are on the same boat as @TKDMaster12 😄 We would like to have provider states passed in. Happy to push a PR to get this feature in.

But was wondering if you have any thoughts on how we might pass the states in. Given this gets initialised early on, I believe we lose context from an individual test point of view.

I was wondering if we can pass a generic provider state PER pactMswAdapter for a given provider. Hope that makes sense. Would love some brainstorming on how we can do it to see if I'm missing anything. Thoughts ?

@TKDMaster12
Copy link
Author

I figured out a work a round. I added an extra header to the calls. Then in the afterAll method pull that header and use that as the state. Hope this helps.

afterAll(async () => {
    if (pactMswAdapter) {
        await pactMswAdapter.writeToFile((path, data) => {

            let name = data.provider.name.split("-");

            data.interactions.forEach((interaction, index) => {
                if (name[name.length - 1] === "questions") {
                    let state = interaction.request.headers['extra-header-state'];
                    interaction.providerState = `${name[name.length - 1]}_${state}_${index}`;
                } else {
                    interaction.providerState = `${name[name.length - 1]}_${index}`;
                }
            });
            fs.writeFileSync(path, JSON.stringify(data));
        }); // writes the pacts to a file
        pactMswAdapter.clear();
    }
    server.close();
});

@mefellows
Copy link

See also pactflow/pact-cypress-adapter#22.

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

No branches or pull requests

4 participants