-
Notifications
You must be signed in to change notification settings - Fork 518
/
Copy pathpact.setup.js
58 lines (52 loc) · 1.54 KB
/
pact.setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const controller = require("./product.controller");
const Product = require("./product");
const baseOpts = {
logLevel: "INFO",
providerBaseUrl: "http://localhost:8080",
providerVersion: process.env.GIT_COMMIT,
providerVersionBranch: process.env.GIT_BRANCH, // the recommended way of publishing verification results with the branch property
verbose: process.env.VERBOSE === "true",
};
// Setup provider server to verify
const setupServer = () => {
const app = require("express")();
const authMiddleware = require("../middleware/auth.middleware");
app.use(authMiddleware);
app.use(require("./product.routes"));
const server = app.listen("8080");
return server;
};
const stateHandlers = {
"products exists": () => {
controller.repository.products = new Map([
["10", new Product("10", "CREDIT_CARD", "28 Degrees", "v1")],
]);
},
"products exist": () => {
controller.repository.products = new Map([
["10", new Product("10", "CREDIT_CARD", "28 Degrees", "v1")],
]);
},
"a product with ID 10 exists": () => {
controller.repository.products = new Map([
["10", new Product("10", "CREDIT_CARD", "28 Degrees", "v1")],
]);
},
"a product with ID 11 does not exist": () => {
controller.repository.products = new Map();
},
};
const requestFilter = (req, res, next) => {
if (!req.headers["authorization"]) {
next();
return;
}
req.headers["authorization"] = `Bearer ${new Date().toISOString()}`;
next();
};
module.exports = {
baseOpts,
setupServer,
stateHandlers,
requestFilter,
};