feat: URLs are now injected by the mock server
[demos/example-siren] / consumer / src / __tests__ / delete-order.spec.js
index 2b79bf1..88498b9 100644 (file)
@@ -11,7 +11,8 @@ const {
   eachLike,
   url,
   integer,
-  regex
+  regex,
+  arrayContaining
 } = MatchersV3
 
 describe("Siren Pact test", () => {
@@ -21,13 +22,30 @@ describe("Siren Pact test", () => {
     provider = new PactV3({
       consumer: "Siren Order Provider",
       provider: "Siren Order Service",
-      port: 9000,
       dir: path.resolve(process.cwd(), "pacts")
     })
   })
 
   it('deletes the first order using the delete action', () => {
     provider
+
+      // Get Root Request
+      .uponReceiving("get root")
+      .withRequest({
+        path: "/",
+      })
+      .willRespondWith({
+        status: 200,
+        headers: {
+          'Content-Type': 'application/vnd.siren+json'
+        },
+        body: {
+          class: [ "representation"],
+          links: [{"rel":["orders"], "href":  url(["orders"]) }]
+        }
+      })
+
+      // Get Orders Request
       .uponReceiving("get all orders")
       .withRequest({
         path: "/orders",
@@ -48,30 +66,32 @@ describe("Siren Pact test", () => {
             links: [
               {
                 "rel": [ "self" ],
-                "href": url("http://localhost:9000", ["orders", regex("\\d+", "1234")])
+                "href": url(["orders", regex("\\d+", "1234")])
               }
             ],
-            "actions": [
+            "actions": arrayContaining(
               {
                 "name": "update",
                 "method": "PUT",
-                "href": url("http://localhost:9000", ["orders", regex("\\d+", "1234")])
+                "href": url(["orders", regex("\\d+", "1234")])
               },
               {
                 "name": "delete",
                 "method": "DELETE",
-                "href": url("http://localhost:9000", ["orders", regex("\\d+", "1234")])
+                "href": url(["orders", regex("\\d+", "1234")])
               }
-            ]
-          }, 2),
+            )
+          }),
           links: [
             {
               rel: [ "self" ],
-              href: url("http://localhost:9000", ["orders"])
+              href: url(["orders"])
             }
           ]
         }
       })
+
+      // Delete Order Request
       .uponReceiving("delete order")
       .withRequest({
         method: "DELETE",