Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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",
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()
})
})
})
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",
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',
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,
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);
});
});
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);
});
});
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: {
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)
})
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,