Git ignores the build directory of the Spring-Consumer
[demos/example-siren] / consumer / src / __tests__ / delete-order.spec.js
1 const path = require("path")
2 const chai = require("chai")
3 const chaiAsPromised = require("chai-as-promised")
4 const expect = chai.expect
5 const { PactV3, MatchersV3 } = require("@pact-foundation/pact/v3")
6 const { deleteFirstOrder } = require('../consumer')
7
8 chai.use(chaiAsPromised)
9
10 const {
11   eachLike,
12   url,
13   integer,
14   regex,
15   arrayContaining
16 } = MatchersV3
17
18 describe("Siren Pact test", () => {
19   let provider
20
21   beforeEach(() => {
22     provider = new PactV3({
23       consumer: "Siren Order Provider",
24       provider: "Siren Order Service",
25       dir: path.resolve(process.cwd(), "pacts")
26     })
27   })
28
29   it('deletes the first order using the delete action', () => {
30     provider
31
32       // Get Root Request
33       .uponReceiving("get root")
34       .withRequest({
35         method: "GET",
36         path: "/"
37       })
38       .willRespondWith({
39         status: 200,
40         headers: {
41           'Content-Type': 'application/vnd.siren+json'
42         },
43         body: {
44           class: [ "representation"],
45           links: [{"rel":["orders"], "href":  url(["orders"]) }]
46         }
47       })
48
49       // Get Orders Request
50       .uponReceiving("get all orders")
51       .withRequest({
52         method: "GET",
53         path: "/orders",
54       })
55       .willRespondWith({
56         status: 200,
57         headers: {
58           'Content-Type': 'application/vnd.siren+json'
59         },
60         body: {
61           class: [ "entity" ],
62           entities: eachLike({
63             class: [ "entity" ],
64             rel: [ "item" ],
65             properties: {
66               "id": integer(1234)
67             },
68             links: [
69               {
70                 "rel": [ "self" ],
71                 "href": url(["orders", regex("\\d+", "1234")])
72               }
73             ],
74             "actions": arrayContaining(
75               {
76                 "name": "update",
77                 "method": "PUT",
78                 "href": url(["orders", regex("\\d+", "1234")])
79               },
80               {
81                 "name": "delete",
82                 "method": "DELETE",
83                 "href": url(["orders", regex("\\d+", "1234")])
84               }
85             )
86           }),
87           links: [
88             {
89               rel: [ "self" ],
90               href: url(["orders"])
91             }
92           ]
93         }
94       })
95
96       // Delete Order Request
97       .uponReceiving("delete order")
98       .withRequest({
99         method: "DELETE",
100         path: regex("/orders/\\d+", "/orders/1234"),
101       })
102       .willRespondWith({
103         status: 200
104       })
105
106     return provider.executeTest(mockserver => {
107       return expect(deleteFirstOrder(mockserver.url)).to.eventually.be.true
108     })
109   })
110 })