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

No way to set provider state #16

Open
CassianoSF opened this issue Aug 30, 2022 · 1 comment
Open

No way to set provider state #16

CassianoSF opened this issue Aug 30, 2022 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@CassianoSF
Copy link

CassianoSF commented Aug 30, 2022

Can you add an interface to pass a providerState id in pact files? It would be very helpful for me, I'm trying to use it with graphql, and I've made a lot of progress, this is the only feature missing for my use case so far.

This is the custom cypress command I'm using:

Cypress.Commands.add('stubRequest', ({ request, response, alias }) => {
  const previousInteceptions = Cypress.config('interceptions');

  const expectedKey = hash(
    JSON.parse(
      JSON.stringify({
        query: cleanQuery(getGqlString(request.query)),
        variables: request.variables,
      }),
    ),
  );

  Cypress.config('interceptions', {
    ...(previousInteceptions || {}),
    [expectedKey]: { alias, response },
  });

  if (previousInteceptions) return;

  cy.intercept('POST', 'http://localhost:4000/graphql', (req) => {
    const interceptions = Cypress.config('interceptions');

    const receivedKey = hash(
      JSON.parse(
        JSON.stringify({
          query: cleanQuery(req.body.query),
          variables: { ...req.body.variables },
        }),
      ),
    );

    const match = interceptions[receivedKey];
    if (match) {
      req.alias = match.alias;
      req.reply({ body: match.response });
    }
  });
});

With this I can stub exact request/responses 🙂

    cy.stubRequest({
      request: requestQueryUsersSeccess,
      response: queryUsersSuccess,
      alias: 'QUERY_USERS_SUCCESS',
    });
    cy.stubRequest({
      request: requestCreateUserSuccess,
      response: mutationCreateUserSuccess,
      alias: 'MUTATION_CREATE_USER_SUCCESS',
    });

If it was possible to add an providerState into this stubRequest command, it would be perfect!

@YOU54F
Copy link
Member

YOU54F commented Oct 6, 2022

Happy to consider a PR if you are willing

@YOU54F YOU54F added enhancement New feature or request good first issue Good for newcomers labels Dec 9, 2022
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

2 participants