Some checks failed
test / Test completion check (push) Has been cancelled
test / test (20, macos-latest) (push) Has been cancelled
test / test (20, ubuntu-latest) (push) Has been cancelled
test / test (20, windows-latest) (push) Has been cancelled
test / test (22, macos-latest) (push) Has been cancelled
test / test (22, ubuntu-latest) (push) Has been cancelled
test / test (22, windows-latest) (push) Has been cancelled
test / test (24, macos-latest) (push) Has been cancelled
test / test (24, ubuntu-latest) (push) Has been cancelled
test / test (24, windows-latest) (push) Has been cancelled
60 lines
No EOL
1.8 KiB
JavaScript
60 lines
No EOL
1.8 KiB
JavaScript
// Setting up our test framework
|
|
const chai = require("chai");
|
|
const expect = chai.expect;
|
|
const chaiAsPromised = require("chai-as-promised");
|
|
chai.use(chaiAsPromised);
|
|
|
|
// We need Pact in order to use it in our test
|
|
const { provider } = require("../pact");
|
|
const { eachLike } = require("@pact-foundation/pact").MatchersV3;
|
|
|
|
// Importing our system under test (the orderClient) and our Order model
|
|
const { Order } = require("./order");
|
|
const { fetchOrders } = require("./orderClient");
|
|
|
|
// This is where we start writing our test
|
|
describe("Pact with Order API", () => {
|
|
describe("given there are orders", () => {
|
|
const itemProperties = {
|
|
name: "burger",
|
|
quantity: 2,
|
|
value: 100,
|
|
};
|
|
|
|
const orderProperties = {
|
|
id: 1,
|
|
items: eachLike(itemProperties),
|
|
};
|
|
|
|
describe("when a call to the API is made", () => {
|
|
before(() => {
|
|
provider
|
|
.given("there are orders")
|
|
.uponReceiving("a request for orders")
|
|
.withRequest({
|
|
method: "GET",
|
|
path: "/orders",
|
|
})
|
|
.willRespondWith({
|
|
body: eachLike(orderProperties),
|
|
status: 200,
|
|
headers: {
|
|
"Content-Type": "application/json; charset=utf-8",
|
|
},
|
|
});
|
|
});
|
|
|
|
it("will receive the list of current orders", () => {
|
|
return provider.executeTest((mockserver) => {
|
|
// The mock server is started on a randomly available port,
|
|
// so we set the API mock service port so HTTP clients
|
|
// can dynamically find the endpoint
|
|
process.env.API_PORT = mockserver.port;
|
|
return expect(fetchOrders()).to.eventually.have.deep.members([
|
|
new Order(orderProperties.id, [itemProperties]),
|
|
]);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}); |