```import { ApolloGraphQLInteraction } from "@pact-foundation/pact"
import { ApolloClient } from "apollo-boost"
import { createHttpLink } from "apollo-link-http"
import { InMemoryCache } from "apollo-cache-inmemory"
import gql from "graphql-tag"
import * as loadNewShowCaseExpectedResponse from './mocks/loadNewShowCase.json';
import { showCase } from '../../../src/services/api/showcase';
const path = require("path")
const Pact = require("@pact-foundation/pact").Pact
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100000;
const PORT = 20002;
describe("Show Case", () => {
const provider = new Pact({
port: PORT,
log: path.resolve(process.cwd(), "aut-tests/contract/logs", "mockserver-integration.log"),
dir: path.resolve(process.cwd(), "aut-tests/contract/pacts"),
spec: 2,
logLevel: 'DEBUG',
pactfileWriteMode: "overwrite",
consumer: "courier-phoenix",
provider: "ze-catalog-service",
})
beforeAll(() => provider.setup());
afterAll(() => provider.finalize());
describe("Load New Show Case", () => {
beforeEach(() => {
const graphqlQueryInteraction = new ApolloGraphQLInteraction()
.uponReceiving("A request with a new show case")
.withRequest({
path: "/public-api",
method: "POST",
})
.withOperation("loadNewShowCase")
.withQuery(`query loadNewShowCase($filter: ShowCaseFilter) {${showCase}}`)
.withVariables({})
.willRespondWith({
status: 200,
headers: {
"Content-Type": "application/json; charset=utf-8",
},
body: loadNewShowCaseExpectedResponse
});
return provider.addInteraction(graphqlQueryInteraction)
})
test("returns correct body, header and statusCode", async() => {
const client = new ApolloClient({
cache: new InMemoryCache({
addTypename: false
}),
link: createHttpLink({
fetch: require("node-fetch"),
uri: `
http://localhost:${PORT}/public-api`,
}),
})
let response = client
.query({
query: gql`query loadNewShowCase($filter: ShowCaseFilter) {
${showCase}
}`
})
response = await response.then((result: any) => {
result.data
expect(result.data).toEqual(loadNewShowCaseExpectedResponse)
})
.catch( error => {
return error
})
})
afterEach(() => provider.verify())
})
})```