From b9e1c9d68cde5754cecb7561611d9b3593408229 Mon Sep 17 00:00:00 2001 From: AmirTk Date: Sat, 9 Sep 2023 11:04:20 +0000 Subject: [PATCH 1/8] Writing tests for ordering based on id and name --- Ordering.http | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Ordering.http diff --git a/Ordering.http b/Ordering.http new file mode 100644 index 0000000..59b3256 --- /dev/null +++ b/Ordering.http @@ -0,0 +1,26 @@ +GET {{baseUrl}}/products?order=id.desc +?? status == 200 +?? js response.parsedBody[0].id == 77 +?? js response.parsedBody[76].id == 1 +### + +GET {{baseUrl}}/products?order=id.asc +?? status == 200 +?? js response.parsedBody[0].id == 1 +?? js response.parsedBody[76].id == 77 + +### +GET {{baseUrl}}/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 {{baseUrl}}/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 From 1d1930f7631bfd10b4e31794c7f456a1d4e6c209 Mon Sep 17 00:00:00 2001 From: AmirTk Date: Sat, 9 Sep 2023 13:01:28 +0000 Subject: [PATCH 2/8] Remove asc from query in order to test default act --- Ordering.http | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ordering.http b/Ordering.http index 59b3256..74a31b9 100644 --- a/Ordering.http +++ b/Ordering.http @@ -4,7 +4,7 @@ GET {{baseUrl}}/products?order=id.desc ?? js response.parsedBody[76].id == 1 ### -GET {{baseUrl}}/products?order=id.asc +GET {{baseUrl}}/products?order=id ?? status == 200 ?? js response.parsedBody[0].id == 1 ?? js response.parsedBody[76].id == 77 From 9ed8ad65a7d4276496c789d32e908fc5c4543e69 Mon Sep 17 00:00:00 2001 From: matty Date: Sun, 10 Sep 2023 13:10:09 +0330 Subject: [PATCH 3/8] Setup environments --- .env | 1 - .env.codesandbox | 1 + .env.rayvarzCenter | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) delete mode 100644 .env create mode 100644 .env.codesandbox create mode 100644 .env.rayvarzCenter 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/.env.codesandbox b/.env.codesandbox new file mode 100644 index 0000000..ca30164 --- /dev/null +++ b/.env.codesandbox @@ -0,0 +1 @@ +baseUrl="https://2nxkmw-8080.csb.app" diff --git a/.env.rayvarzCenter b/.env.rayvarzCenter new file mode 100644 index 0000000..52464c9 --- /dev/null +++ b/.env.rayvarzCenter @@ -0,0 +1 @@ +baseUrl="https://nw.rayvarz.center/api" From 1d3c3710320ef6e7f92e8a22e24252c4a3746a9d Mon Sep 17 00:00:00 2001 From: matty Date: Sun, 10 Sep 2023 13:19:58 +0330 Subject: [PATCH 4/8] Renamed environments --- .env.codesandbox => .env.mock-sandbox | 0 .env.rayvarzCenter => .env.nw-center | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .env.codesandbox => .env.mock-sandbox (100%) rename .env.rayvarzCenter => .env.nw-center (100%) diff --git a/.env.codesandbox b/.env.mock-sandbox similarity index 100% rename from .env.codesandbox rename to .env.mock-sandbox diff --git a/.env.rayvarzCenter b/.env.nw-center similarity index 100% rename from .env.rayvarzCenter rename to .env.nw-center From 72f2a8dd71acd711da41941bed3d7b56071472f5 Mon Sep 17 00:00:00 2001 From: matty Date: Sun, 10 Sep 2023 21:34:29 +0330 Subject: [PATCH 5/8] Updated codesandbox URL --- .env.mock-sandbox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.mock-sandbox b/.env.mock-sandbox index ca30164..4abd97f 100644 --- a/.env.mock-sandbox +++ b/.env.mock-sandbox @@ -1 +1 @@ -baseUrl="https://2nxkmw-8080.csb.app" +baseUrl="https://pdgw7l-8080.csb.app" From 247774b18182b7f344e6523f51a41ab06273662e Mon Sep 17 00:00:00 2001 From: matty Date: Wed, 25 Oct 2023 14:23:52 +0330 Subject: [PATCH 6/8] Added prefer header tests --- PreferHeader.http | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 PreferHeader.http diff --git a/PreferHeader.http b/PreferHeader.http new file mode 100644 index 0000000..2b33e69 --- /dev/null +++ b/PreferHeader.http @@ -0,0 +1,60 @@ + +{{ + 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; +}} +### + +POST {{baseUrl}}/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 {{baseUrl}}/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 From 3cd00d74bf68140b8f12c3576a98b8a40602c185 Mon Sep 17 00:00:00 2001 From: matty Date: Wed, 25 Oct 2023 16:34:47 +0330 Subject: [PATCH 7/8] Replaced "baseUrl" with implicit "host" and fixed a minor bug regarding ordering --- .env.mock-sandbox | 1 - .env.nw-center | 1 - .httpyac.json | 10 ++++++++++ Ordering.http | 30 ++++++++++++++++++++++++++---- PreferHeader.http | 9 ++++----- Rest.http | 22 +++++++++++----------- 6 files changed, 51 insertions(+), 22 deletions(-) delete mode 100644 .env.mock-sandbox delete mode 100644 .env.nw-center create mode 100644 .httpyac.json diff --git a/.env.mock-sandbox b/.env.mock-sandbox deleted file mode 100644 index 4abd97f..0000000 --- a/.env.mock-sandbox +++ /dev/null @@ -1 +0,0 @@ -baseUrl="https://pdgw7l-8080.csb.app" diff --git a/.env.nw-center b/.env.nw-center deleted file mode 100644 index 52464c9..0000000 --- a/.env.nw-center +++ /dev/null @@ -1 +0,0 @@ -baseUrl="https://nw.rayvarz.center/api" 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 index 74a31b9..958ad27 100644 --- a/Ordering.http +++ b/Ordering.http @@ -1,16 +1,37 @@ -GET {{baseUrl}}/products?order=id.desc +{{ + 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; +}} + +### + +GET /products?order=id.desc ?? status == 200 ?? js response.parsedBody[0].id == 77 + ?? js response.parsedBody[76].id == 1 ### -GET {{baseUrl}}/products?order=id +GET /products?order=id ?? status == 200 ?? js response.parsedBody[0].id == 1 ?? js response.parsedBody[76].id == 77 ### -GET {{baseUrl}}/products?order=product_name.asc + +GET /products?order=product_name.asc ?? status == 200 ?? js response.parsedBody[0].id == 17 ?? js response.parsedBody[76].id == 47 @@ -18,7 +39,8 @@ GET {{baseUrl}}/products?order=product_name.asc ?? js response.parsedBody[76].product_name startsWith Z ### - GET {{baseUrl}}/products?order=product_name.desc + +GET /products?order=product_name.desc ?? status == 200 ?? js response.parsedBody[0].id == 47 ?? js response.parsedBody[76].id == 17 diff --git a/PreferHeader.http b/PreferHeader.http index 2b33e69..0a704fe 100644 --- a/PreferHeader.http +++ b/PreferHeader.http @@ -1,12 +1,11 @@ - {{ const axios = require('axios'); - const wait = axios.get(`${baseUrl}/products`).then(res => { + 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(`${baseUrl}/products?id=eq.78`) + return axios.delete(`${host}/products?id=eq.78`) .then(res => { return null; }) @@ -17,7 +16,7 @@ }} ### -POST {{baseUrl}}/products +POST /products Content-Type: application/json Prefer: return=representation @@ -40,7 +39,7 @@ Prefer: return=representation ### -POST {{baseUrl}}/products +POST /products Content-Type: application/json Prefer: return=headers-only diff --git a/Rest.http b/Rest.http index e7003e4..6f41f40 100644 --- a/Rest.http +++ b/Rest.http @@ -1,11 +1,11 @@ {{ const axios = require('axios'); - const wait = axios.get(`${baseUrl}/products`).then(res => { + 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(`${baseUrl}/products?id=eq.78`) + return axios.delete(`${host}/products?id=eq.78`) .then(res => { return null; }) @@ -16,20 +16,20 @@ }} ### -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 +62,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 +80,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 +106,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); }) From 9e20ac6ec10759ab1e2b25c9752f5e9ae5e9171f Mon Sep 17 00:00:00 2001 From: Zeinab Date: Sat, 9 Dec 2023 10:01:30 +0330 Subject: [PATCH 8/8] Refactoring: Add PreScript.http --- Ordering.http | 18 +----------------- PreScript.http | 15 +++++++++++++++ PreferHeader.http | 17 +---------------- Rest.http | 18 +----------------- 4 files changed, 18 insertions(+), 50 deletions(-) create mode 100644 PreScript.http diff --git a/Ordering.http b/Ordering.http index 958ad27..2b496d0 100644 --- a/Ordering.http +++ b/Ordering.http @@ -1,20 +1,4 @@ -{{ - 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; -}} - +# @import ./PreScript.http ### GET /products?order=id.desc 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 index 0a704fe..7171b0d 100644 --- a/PreferHeader.http +++ b/PreferHeader.http @@ -1,19 +1,4 @@ -{{ - 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; -}} + # @import ./PreScript.http ### POST /products diff --git a/Rest.http b/Rest.http index 6f41f40..c7f636a 100644 --- a/Rest.http +++ b/Rest.http @@ -1,19 +1,4 @@ -{{ - 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; -}} +# @import ./PreScript.http ### GET /products/1 @@ -22,7 +7,6 @@ GET /products/1 ?? body id == 1 ### - GET /products ?? status == 200 ?? body length == 77