How to use the @pact-foundation/pact.GraphQLInteraction function in @pact-foundation/pact

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 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 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 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,
github replicatedhq / kots / web / src / contracts / ship-cloud-api / contracts / list-watches-ship-cluster.js View on Github external
expect(childWatch.cluster.id).to.equal("ship-cluster-1");

      expect(childWatch.pastVersions).to.have.lengthOf(0);

      expect(childWatch.pendingVersions).to.have.lengthOf(1);
      expect(childWatch.pendingVersions[0].title).to.equal("0.1.4");
      expect(childWatch.pendingVersions[0].status).to.equal("pending");
      expect(childWatch.pendingVersions[0].sequence).to.equal(1);

      global.provider.verify();
      done();
    });
  });
}

const listWatchesInteraction = new Pact.GraphQLInteraction()
  .uponReceiving("a query to list watches for ship-clusters account")
  .withRequest({
    path: "/graphql",
    method: "POST",
    headers: {
      "Authorization": createSessionToken("ship-cluster-account-session-1"),
      "Content-Type": "application/json",
    }
  })
  .withQuery(listWatchesRaw)
  .withOperation("listWatches")
  .withVariables({

  })
  .willRespondWith({
    status: 200,
github replicatedhq / kots / web / src / contracts / ship-cloud-api / contracts / get-watch-version.js View on Github external
await global.provider.addInteraction(getWatchVersionInteraction);
    const result = await getShipClient("solo-account-session-1").query({
      query: getWatchVersion,
      variables: {
        id: "solo-account-watch-1",
        sequence: 0,
      }
    });

    expect(result.data.getWatchVersion.sequence).to.equal(0);
    expect(result.data.getWatchVersion.rendered).to.equalIgnoreSpaces(`apiVersion: v1\ndata:\n  factorio-password: eW91ci5wYXNzd29yZA==\n  factorio-username: eW91ci51c2VybmFtZQ==\n  rcon-password: \"\"\n  server-password: \"\"\nkind: Secret\nmetadata:\n labels:\n    app: factorio-factorio\n    release: factorio\n  name: factorio-factorio\ntype: Opaque\n---\napiVersion: v1\nkind: Service\nmetadata:\n  labels:\n    app: factorio-factorio\n    release: factorio\n  name: factorio-factorio\nspec:\n  ports:\n  - name: factorio\n    port: 34197\n    protocol: UDP\ntargetPort: factorio\n  selector:\n    app: factorio-factorio\n  type: LoadBalancer\n---\napiVersion: extensions/v1beta1\nkind: Deployment\nmetadata:\n  labels:\n    app: factorio-factorio\n    release: factorio\n  name: factorio-factorio\nspec:\n  template:\n    metadata:\n      labels:\n        app: factorio-factorio\n    spec:\n      containers:\n      - env:\n        - name: FACTORIO_SERVER_NAME\n          value: Kubernetes Server\n        - name: FACTORIO_DESCRIPTION\n          value: Factorio running on Kubernetes\n        - name: FACTORIO_PORT\n          value: \"34197\"\n        - name: FACTORIO_MAX_PLAYERS\n    value: \"255\"\n        - name: FACTORIO_IS_PUBLIC\n          value: \"false\"\n        - name: FACTORIO_REQUIRE_USER_VERIFICATION\n          value: \"false\"\n        - name: FACTORIO_ALLOW_COMMANDS\n          value: admins-only\n        - name: FACTORIO_NO_AUTO_PAUSE\n          value: \"false\"\n        - name: FACTORIO_AUTOSAVE_INTERVAL\nvalue: \"2\"\n        - name: FACTORIO_AUTOSAVE_SLOTS\n          value: \"3\"\n        image: quay.io/games_on_k8s/factorio:0.14.22\n        imagePullPolicy: Always\n        name: factorio-factorio\n        ports:\n        - containerPort: 34197\n          name: factorio\n          protocol: UDP\n        resources:\n          requests:\n            cpu: 500m\n            memory: 512Mi\n        volumeMounts:\n- mountPath: /opt/factorio/saves\n          name: saves\n        - mountPath: /opt/factorio/mods\n   name: mods\n      volumes:\n      - name: saves\n        persistentVolumeClaim:\n          claimName:factorio-factorio-savedgames\n      - emptyDir: {}\n        name: mods\n---\napiVersion: v1\nkind: PersistentVolumeClaim\nmetadata:\n  labels:\n    app: factorio-factorio\n    release: factorio\n  name: factorio-factorio-savedgames\nspec:\n  accessModes:\n  - ReadWriteOnce\n  resources:\n    requests:\n      storage: 1Gi\n`);
    global.provider.verify().then(() => done());
  });
}

const getWatchVersionInteraction = new Pact.GraphQLInteraction()
  .uponReceiving("a query to get a single watch version for solo account")
  .withRequest({
    path: "/graphql",
    method: "POST",
    headers: {
      "Authorization": createSessionToken("solo-account-session-1"),
      "Content-Type": "application/json",
    }
  })
  .withQuery(getWatchVersionRaw)
  .withOperation("getWatchVersion")
  .withVariables({
    id: "solo-account-watch-1",
    sequence: 0,
  })
  .willRespondWith({
github replicatedhq / kots / web / src / contracts / ship-cloud-api / contracts / get-kots-app.js View on Github external
slug: "kots-app-slug"
      },
    });
    expect(result.data.getKotsApp.id).to.equal("get-kots-app-id");
    expect(result.data.getKotsApp.name).to.equal("kots-app-name");
    expect(result.data.getKotsApp.slug).to.equal("kots-app-slug");
    expect(result.data.getKotsApp.currentSequence).to.equal(0);
    expect(result.data.getKotsApp.hasPreflight).to.equal(false);
    expect(result.data.getKotsApp.isAirgap).to.equal(false);
    expect(result.data.getKotsApp.currentVersion).to.equal(null);

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

  });

  const getKotsAppInteraction = new Pact.GraphQLInteraction()
    .uponReceiving("A query to get a kots app")
    .withRequest({
      path: "/graphql",
      method: "POST",
      headers: {
        "Authorization": createSessionToken("get-kots-app-user-session"),
        "Content-Type": "application/json",
      }
    })
    .withOperation("getKotsApp")
    .withQuery(getKotsAppRaw)
    .withVariables({
      slug: "kots-app-slug"
    })
    .willRespondWith({
      status: 200,
github replicatedhq / kots / web / src / contracts / ship-cloud-api / contracts / create-midstream-watch.js View on Github external
"id": "",
        "type": ""
      },
      "sequence": 0,
      "version": "0.3.1"
    },
    "contentSHA": "126fa6eb8f09171050751c65a386f41aef4fe9ebe00c8b1e66f2c4e60319ec4e"
  }
}`
        },
    });
    global.provider.verify().then(() => done());
  });
}

const createMidstreamWatchInteraction = new Pact.GraphQLInteraction()
  .uponReceiving("a mutation to create a midstream watch for solo dev")
  .withRequest({
    path: "/graphql",
    method: "POST",
    headers: {
      "Authorization": createSessionToken("solo-account-session-1"),
      "Content-Type": "application/json",
    }
  })
  .withOperation("createWatch")
  .withQuery(createNewWatchRaw)
  .withVariables({
    stateJSON: `{
  "v1": {
    "config": {},
    "releaseName": "factorio",
github replicatedhq / kots / web / src / contracts / ship-cloud-api / contracts / kots-downstream-history-with-notes.js View on Github external
});
    const{ data } = result;
    const downstream = data.getKotsDownstreamHistory[0];

    expect(downstream.title).to.equal("my-other-awesome-version");
    expect(downstream.status).to.equal("pending");
    expect(typeof downstream.createdOn).to.equal("string");
    expect(downstream.sequence).to.equal(0);
    expect(downstream.releaseNotes).to.equal("# Release Notes Markdown Text");
    expect(typeof downstream.preflightResult).to.equal("string");
    expect(typeof downstream.preflightResultCreatedAt).to.equal("string");

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

  const getKotsDownstreamHistoryInteraction = new Pact.GraphQLInteraction()
    .uponReceiving("A query to get kots downstream version history that has release notes")
    .withRequest({
      path: "/graphql",
      method: "POST",
      headers: {
        "Authorization": createSessionToken("kots-release-notes-user-session"),
        "Content-Type": "application/json",
      }
    })
    .withOperation("getKotsDownstreamHistory")
    .withQuery(getKotsDownstreamHistoryRaw)
    .withVariables({
      clusterSlug: "kots-release-notes-cluster-slug",
      upstreamSlug: "kots-release-notes-app-slug"
    })
    .willRespondWith({
github replicatedhq / kots / web / src / contracts / ship-cloud-api / contracts / get-watch-contributors.js View on Github external
expect(user.id).to.equal("get-watch-contributors-user");
        expect(user.createdAt).to.startWith("Thu Apr 18 2019 12:34:56 GMT+0000");
        expect(user.githubId).to.equal(1235);
        expect(user.login).to.equal("get-watch-contributors-username");
        expect(user.avatar_url).to.equal("https://avatars3.githubusercontent.com/u/234567?v=4");

        global.provider.verify();
        done();
      });
    });
  });

}

const getWatchContributorsInteraction = new Pact.GraphQLInteraction()
  .uponReceiving("a query to get a watch's contributors")
  .withRequest({
    path: "/graphql",
    method: "POST",
    headers: {
      "Authorization": createSessionToken("get-watch-contributors-session-1"),
      "Content-Type": "application/json",
    }
  })
  .withQuery(getWatchContributorsRaw)
  .withOperation("watchContributors")
  .withVariables({
    id: "get-watch-contributors-watch"
  })
  .willRespondWith({
    status: 200,
github replicatedhq / kots / web / src / contracts / ship-cloud-api / contracts / upload-airgap-license.js View on Github external
const result = await getShipClient("upload-license-session-1").mutate({
      mutation: uploadKotsLicense,
      variables: {
        value: YAML_LICENSE
      }
    });
    const { uploadKotsLicense: gqlResponse } = result.data;
    expect(gqlResponse.hasPreflight).toBe(false);
    expect(gqlResponse.slug).toBe("sentry-enterprise");

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

}

const uploadKotsLicenseInteraction = new Pact.GraphQLInteraction()
  .uponReceiving("a mutation to upload a license")
  .withRequest({
    path: "/graphql",
    method: "POST",
    headers: {
      "Authorization": createSessionToken("upload-license-session-1"),
      "Content-Type": "application/json",
    }
  })
  .withOperation("uploadKotsLicense")
  .withQuery(uploadKotsLicenseRaw)
  .withVariables({
    value: YAML_LICENSE
  })
  .willRespondWith({
    status: 200,