How to use @pact-foundation/pact - 10 common examples

To help you get started, we’ve selected a few @pact-foundation/pact examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pact-foundation / pact-js / examples / messages / provider / message-provider.spec.ts View on Github external
describe("Message provider tests", () => {
  const p = new MessageProviderPact({
    messageProviders: {
      "a request for a dog": () => createDog(27),
    },
    stateHandlers: {
      "some state": () => {
        // TODO: prepare system useful in order to create a dog
        console.log('State handler: setting up "some state" for interaction')
        return Promise.resolve(`state set to create a dog`)
      },
    },
    consumer: "MyJSMessageConsumer",
    log: path.resolve(process.cwd(), "logs"),
    logLevel: "info",
    provider: "MyJSMessageProvider",
    providerVersion: "1.0.0",
github pact-foundation / pact-js / examples / graphql / provider.spec.ts View on Github external
it("validates the expectations of Matching Service", () => {
    // lexical binding required here
    const opts = {
      // Local pacts
      // pactUrls: [path.resolve(process.cwd(), "./pacts/graphqlconsumer-graphqlprovider.json")],
      pactBrokerPassword: "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1",
      pactBrokerUrl: "https://test.pact.dius.com.au/",
      pactBrokerUsername: "dXfltyFMgNOFZAxr8io9wJ37iUpY42M",
      provider: "GraphQLProvider",
      providerBaseUrl: "http://localhost:4000/graphql",
      providerVersion: "1.0.0",
      publishVerificationResult: true,
      tags: ["prod"],
    }

    return new Verifier(opts).verifyProvider().then(output => {
      server.close()
    })
  })
})
github replicatedhq / kots / web / src / contracts / ship-cloud-api / contracts / create-gitops-cluster.js View on Github external
title: "FooBarGit Cluster",
        installationId: 987654,
        gitOpsRef: {
          owner: "me",
          repo: "myself",
          branch: "i",
        },
      },
    });
    // expect(result.data.createGitOpsCluster).to.deep.equal({"id": "generated", "slug": "foobargit-cluster"})
    // createdClusterId = result.data.createGitOpsCluster.id;
    global.provider.verify().then(() => done());
  });
}

const createGitOpsClusterInteraction = new Pact.GraphQLInteraction()
  .uponReceiving("a mutation to create a gitops cluster for solo dev")
  .withRequest({
    path: "/graphql",
    method: "POST",
    headers: {
      "Authorization": createSessionToken("solo-account-session-1"),
      "Content-Type": "application/json",
    }
  })
  .withOperation("createGitOpsCluster")
  .withQuery(createGitOpsClusterRaw)
  .withVariables({
    title: "FooBarGit Cluster",
    installationId: 987654,
    gitOpsRef: {
      owner: "me",
github thombergs / code-examples / pact / pact-node-messages / src / provider / hero-event-producer.spec.js View on Github external
describe("message producer", () => {

    const messagePact = new MessageProviderPact({
        messageProviders: {
            "a hero created message": () => CreateHeroEventProducer.produceHeroCreatedEvent(),
        },
        log: path.resolve(process.cwd(), "logs", "pact.log"),
        logLevel: "info",
        provider: "node-message-provider",

        pactUrls: [path.resolve(process.cwd(), "pacts", "node-message-consumer-node-message-provider.json")],

        // Pact seems not to load a pact file from a pact broker, so we have to make do with the local pact file
        // see https://github.com/pact-foundation/pact-js/issues/248
        // pactBrokerUrl: "https://adesso.pact.dius.com.au",
        // pactBrokerUsername: process.env.PACT_USERNAME,
        // pactBrokerPassword: process.env.PACT_PASSWORD,
        // publishVerificationResult: true,
        // providerVersion: '1.0.0',
github pact-foundation / pact-js / examples / serverless / provider / message-provider.spec.js View on Github external
describe("Message provider tests", () => {
  const p = new MessageProviderPact({
    messageProviders: {
      "a request to save an event": () => createEvent(),
    },
    logLevel: "WARN",
    provider: "SNSPactEventProvider",
    providerVersion: "1.0.0",

    // For local validation
    // pactUrls: [path.resolve(process.cwd(), "pacts", "snspacteventconsumer-snspacteventprovider.json")],

    // Uncomment to use the broker
    pactBrokerUrl: "https://test.pact.dius.com.au/",
    pactBrokerUsername: "dXfltyFMgNOFZAxr8io9wJ37iUpY42M",
    pactBrokerPassword: "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1",
    publishVerificationResult: true,
github replicatedhq / kots / kotsadm / api / pact / provider_tests_local.js View on Github external
s3rver.run().then(() => {
  console.log("Starting pact verifier");
  new Verifier().verifyProvider(opts).then(() => {
    console.log("Stopping s3 server");
    s3rver.close();
  })
  .catch((err) => {
    console.log("Stopping s3 server");
    s3rver.close();
    console.error(err);
    process.exit(1);
  });
});
github replicatedhq / kots / kotsadm / api / pact / provider_tests_broker.js View on Github external
s3rver.run().then(() => {
  console.log("Starting pact verifier");
  new Verifier().verifyProvider(opts).then(() => {
    console.log("Stopping s3 server");
    s3rver.close();
  })
  .catch((err) => {
    console.log("Stopping s3 server");
    s3rver.close();
    console.error(err);
    process.exit(1);
  });
});
github replicatedhq / kots / web / src / contracts / ship-cloud-api / contracts / get-latest-kots-preflight-result.js View on Github external
const result = await getShipClient("get-latest-kots-preflight-result-user-session").query({
      query: getLatestKotsPreflightResult
    });

    const { getLatestKotsPreflightResult: gqlData } = result.data;

    expect(gqlData.appSlug).to.equal("get-latest-kots-preflight-result-app-slug");
    expect(gqlData.clusterSlug).to.equal("get-latest-kots-preflight-result-cluster-slug");
    expect(typeof gqlData.result).to.equal("string");
    expect(typeof gqlData.createdAt).to.equal("string");

    global.provider.verify().then(() => done());
  });
};

const getLatestKotsPreflightResultInteraction = new Pact.GraphQLInteraction()
  .uponReceiving("a query to get the latest kots preflight result")
  .withRequest({
    path: "/graphql",
    method: "POST",
    headers: {
      "Authorization": createSessionToken("get-latest-kots-preflight-result-user-session"),
      "Content-Type": "application/json",
    }
  })
  .withOperation("getLatestKotsPreflightResult")
  .withQuery(getLatestKotsPreflightResultRaw)
  .withVariables({})
  .willRespondWith({
    status: 200,
    headers: { "Content-Type": "application/json" },
    body: {
github pact-foundation / pact-js / examples / jest / __tests__ / catAPI.spec.js View on Github external
beforeEach(() => {
      const interaction = {
        state: "i have a list of cats",
        uponReceiving: "a request for cats with given catId",
        withRequest: {
          method: "GET",
          path: "/cats",
          query: {
            "catId[]": Matchers.eachLike("1"),
          },
          headers: {
            Accept: "application/json",
          },
        },
        willRespondWith: {
          status: 200,
          headers: {
            "Content-Type": "application/json",
          },
          body: EXPECTED_BODY,
        },
      }

      return provider.addInteraction(interaction)
    })
github replicatedhq / kots / web / src / contracts / ship-cloud-api / contracts / create-init-session.js View on Github external
it("creates an init session for solo dev", async (done) => {
    await global.provider.addInteraction(createHelmInitSessionInteraction);
    const result = await getShipClient("solo-account-session-1").mutate({
      mutation: createInitSession,
      variables: {
        pendingInitId: "",
        upstreamUri: "https://github.com/helm/charts/stable/grafana",
        clusterID: null,
        githubPath: null,
      },
    });
    global.provider.verify().then(() => done());
    });
}

const createHelmInitSessionInteraction = new Pact.GraphQLInteraction()
  .uponReceiving("a mutation to create a helm init session")
  .withRequest({
    path: "/graphql",
    method: "POST",
    headers: {
      "Authorization": createSessionToken("solo-account-session-1"),
      "Content-Type": "application/json",
    }
  })
  .withOperation("createInitSession")
  .withQuery(createInitSessionRaw)
  .withVariables({
    pendingInitId: "",
    upstreamUri: "https://github.com/helm/charts/stable/grafana",
    clusterID: null,
    githubPath: null,