diff --git a/.env b/.env deleted file mode 100644 index 6ea3292..0000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -baseUrl="https://nw.rayvarz.center/api" \ No newline at end of file diff --git a/.httpyac.json b/.httpyac.json new file mode 100644 index 0000000..bcf5d6e --- /dev/null +++ b/.httpyac.json @@ -0,0 +1,10 @@ +{ + "environments": { + "nw-center": { + "host": "https://nw.rayvarz.center/api" + }, + "mock-sandbox": { + "host": "https://pdgw7l-8080.csb.ap" + } + } +} diff --git a/Ordering.http b/Ordering.http new file mode 100644 index 0000000..2b496d0 --- /dev/null +++ b/Ordering.http @@ -0,0 +1,32 @@ +# @import ./PreScript.http +### + +GET /products?order=id.desc +?? status == 200 +?? js response.parsedBody[0].id == 77 + +?? js response.parsedBody[76].id == 1 +### + +GET /products?order=id +?? status == 200 +?? js response.parsedBody[0].id == 1 +?? js response.parsedBody[76].id == 77 + +### + +GET /products?order=product_name.asc +?? status == 200 +?? js response.parsedBody[0].id == 17 +?? js response.parsedBody[76].id == 47 +?? js response.parsedBody[0].product_name startsWith A +?? js response.parsedBody[76].product_name startsWith Z + +### + +GET /products?order=product_name.desc +?? status == 200 +?? js response.parsedBody[0].id == 47 +?? js response.parsedBody[76].id == 17 +?? js response.parsedBody[0].product_name startsWith Z +?? js response.parsedBody[76].product_name startsWith A \ No newline at end of file diff --git a/PreScript.http b/PreScript.http new file mode 100644 index 0000000..e996b66 --- /dev/null +++ b/PreScript.http @@ -0,0 +1,15 @@ +{{ + const axios = require('axios'); + const wait = axios.get(`${host}/products`).then(res => { + let length = res.data.length; + let exists = res.data.find(item => item.id === 78); + if(length===78 && exists){ + return axios.delete(`${host}/products?id=eq.78`) + .then(res => { + return null; + }) + } + return null; + }) + exports.wait = wait; +}} \ No newline at end of file diff --git a/PreferHeader.http b/PreferHeader.http new file mode 100644 index 0000000..7171b0d --- /dev/null +++ b/PreferHeader.http @@ -0,0 +1,44 @@ + # @import ./PreScript.http +### + +POST /products +Content-Type: application/json +Prefer: return=representation + +{ + "id": 78, + "product_name": "Saffaron", + "discontinued": 0, + "supplier_id": 12, + "category_id": 2, + "quantity_per_unit": "20 mg", + "unit_price": 100, + "units_in_stock": 50, + "units_on_order": 0, + "reorder_level": 10 +} +?? status == 201 +?? js response.parsedBody.length == 1 +?? js response.parsedBody[0].id == 78 +?? js response.parsedBody[0].product_name == Saffaron + +### + +POST /products +Content-Type: application/json +Prefer: return=headers-only + +{ + "id": 78, + "product_name": "Saffaron", + "discontinued": 0, + "supplier_id": 12, + "category_id": 2, + "quantity_per_unit": "20 mg", + "unit_price": 100, + "units_in_stock": 50, + "units_on_order": 0, + "reorder_level": 10 +} +?? status == 201 +?? header location == /products?id=eq.78 diff --git a/Rest.http b/Rest.http index e7003e4..c7f636a 100644 --- a/Rest.http +++ b/Rest.http @@ -1,35 +1,19 @@ -{{ - const axios = require('axios'); - - const wait = axios.get(`${baseUrl}/products`).then(res => { - let length = res.data.length; - let exists = res.data.find(item => item.id === 78); - if(length===78 && exists){ - return axios.delete(`${baseUrl}/products?id=eq.78`) - .then(res => { - return null; - }) - } - return null; - }) - exports.wait = wait; -}} +# @import ./PreScript.http ### -GET {{baseUrl}}/products/1 +GET /products/1 ?? status == 200 ?? body product_name == Chai ?? body id == 1 ### - -GET {{baseUrl}}/products +GET /products ?? status == 200 ?? body length == 77 ### -POST {{baseUrl}}/products +POST /products Content-Type: application/json { @@ -62,13 +46,13 @@ Content-Type: application/json "units_on_order": 0, "reorder_level": 10 } - const wait = axios.post(`${baseUrl}/products`, postData, {headers:{ 'Content-Type': 'application/json'} }).then(res => { + const wait = axios.post(`${host}/products`, postData, {headers:{ 'Content-Type': 'application/json'} }).then(res => { return null; }) exports.wait = wait; }} -PATCH {{baseUrl}}/products?id=eq.78 +PATCH /products?id=eq.78 Content-Type: application/json { @@ -80,7 +64,7 @@ Content-Type: application/json const {expect} = require('chai'); const axios = require("axios"); - const wait = axios.get(`${baseUrl}/products?id=eq.78`).then(res => { + const wait = axios.get(`${host}/products?id=eq.78`).then(res => { test("Check Patch", () => { expect(res.data[0].product_name).to.equal("Saffaron-patch") @@ -106,20 +90,20 @@ Content-Type: application/json "units_on_order": 0, "reorder_level": 10 } - const wait = axios.post(`${baseUrl}/products`, postData, {headers:{ 'Content-Type': 'application/json'} } ).then(res => { + const wait = axios.post(`${host}/products`, postData, {headers:{ 'Content-Type': 'application/json'} } ).then(res => { return null; }) exports.wait = wait; }} -DELETE {{baseUrl}}/products?id=eq.78 +DELETE /products?id=eq.78 ?? status == 204 {{ const {expect} = require('chai'); const axios = require("axios"); - const wait = axios.get(`${baseUrl}/products`).then(res => { + const wait = axios.get(`${host}/products`).then(res => { test("Check for Delete", () => { expect(res.data.length).to.equal(77); })