diff --git a/package.json b/package.json index 28b8a819b315cd2c0f35b2da47d0f848a16ebdc3..ae0955a9787912142a7abc0fe46c0e4cc917f2a0 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "test": "jest", - "test:watch": "NODE_ENV=dev jest --watch", + "test:watch": "jest --testTimeout=20000 --watch", "test:coverage": "jest --testTimeout=20000 --coverage", "dev": "nodemon src/index.ts", "start": "node dist/index.js", diff --git a/src/test/industry-4.0/industry-4.0.spec.ts b/src/test/industry-4.0/industry-4.0.spec.ts index 4dbd6097056c551226ccf81f1e0ca510d9780c04..97c1bc3688ffe077b0ccf4636c10394ff900731f 100644 --- a/src/test/industry-4.0/industry-4.0.spec.ts +++ b/src/test/industry-4.0/industry-4.0.spec.ts @@ -1,17 +1,15 @@ import "reflect-metadata"; import { describe, it, expect, beforeEach, jest } from "@jest/globals"; - import { container } from "../../inversify/inversify.config"; import { GCLController } from "../../gcl/gcl.controller"; +import HttpClient from "../../httpclient/http.service"; -describe("GCL Controller Testing", () => { +describe("Industry 4.0 Controller Testing", () => { beforeEach(async () => {}); - it("should be defined", async () => { + it("Controller Should be defined", async () => { let controller = container.resolve(GCLController); - console.log("======>Hello"); - - expect(controller).toEqual({}); + expect(controller).toBeDefined(); }); }); diff --git a/src/test/retail/local-retail.spec.ts b/src/test/retail/local-retail.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..a5241507a773d9a1b1c355aec1974835e0979790 --- /dev/null +++ b/src/test/retail/local-retail.spec.ts @@ -0,0 +1,27 @@ +import "reflect-metadata"; +import { describe, it, expect, beforeAll, jest } from "@jest/globals"; + +import { container } from "../../inversify/inversify.config"; +import { GCLController } from "../../gcl/gcl.controller"; +import HttpClient from "../../httpclient/http.service"; +import SearchRequestFromUI from "./request-from-ui/search.request.json"; +import SearcResponseFromPS from "./response-from-ps/search.response.json"; +import SearchResponseToUI from "./response-to-ui/response.search.json"; +describe("Local-retail Controller Testing", () => { + let controller: GCLController; + beforeAll(async () => { + controller = container.resolve(GCLController); + }); + + it("Controller Should be defined", async () => { + expect(controller).toBeDefined(); + }); + + it("Search API should be working fine", async () => { + jest + .spyOn(HttpClient.prototype, "post") + .mockImplementation(async () => SearcResponseFromPS); + const data = await controller.search(SearchRequestFromUI); + expect(JSON.stringify(data)).toEqual(JSON.stringify(SearchResponseToUI)); + }); +}); diff --git a/src/test/retail/request-from-ui/search.request.json b/src/test/retail/request-from-ui/search.request.json new file mode 100644 index 0000000000000000000000000000000000000000..dc4c8448a740e3cfa6293856abd7054a44c1a779 --- /dev/null +++ b/src/test/retail/request-from-ui/search.request.json @@ -0,0 +1,17 @@ +{ + "context": { + "domain": "retail:1.1.0" + }, + "searchString": "earphone", + "category": { + "categoryCode": "electronics" + }, + "fulfillment": { + "type": "Delivery", + "stops": [ + { + "location": "28.4594965,77.0266383" + } + ] + } +} diff --git a/src/test/retail/response-from-ps/search.response.json b/src/test/retail/response-from-ps/search.response.json new file mode 100644 index 0000000000000000000000000000000000000000..881ecaf677820612a49082775ab643887cba2083 --- /dev/null +++ b/src/test/retail/response-from-ps/search.response.json @@ -0,0 +1,121 @@ +{ + "context": { + "ttl": "PT10M", + "action": "search", + "timestamp": "2024-01-12T07:20:27.323Z", + "message_id": "a5d31306-c976-4f0d-8d3a-3a377965144f", + "transaction_id": "f649c6aa-d845-4874-9c9c-6020d9140bf7", + "domain": "retail:1.1.0", + "version": "1.1.0", + "bap_id": "ps-bap-network.becknprotocol.io", + "bap_uri": "https://ps-bap-network.becknprotocol.io", + "location": { + "country": { "name": "India", "code": "IND" }, + "city": { "name": "Bangalore", "code": "std:080" } + } + }, + "responses": [ + { + "context": { + "domain": "retail:1.1.0", + "action": "on_search", + "version": "1.1.0", + "bpp_id": "beckn-sandbox-bpp.becknprotocol.io", + "bpp_uri": "https://sandbox-bpp-network.becknprotocol.io", + "country": "IND", + "city": "std:080", + "location": { + "country": { "code": "IND" }, + "city": { "code": "std:080" } + }, + "bap_id": "ps-bap-network.becknprotocol.io", + "bap_uri": "https://ps-bap-network.becknprotocol.io", + "transaction_id": "f649c6aa-d845-4874-9c9c-6020d9140bf7", + "message_id": "a5d31306-c976-4f0d-8d3a-3a377965144f", + "ttl": "PT10M", + "timestamp": "2024-01-12T07:20:34.016Z" + }, + "message": { + "catalog": { + "descriptor": { "name": "HBO" }, + "providers": [ + { + "id": "./retail.kirana/ind.blr/33@tourism-bpp-infra2.becknprotocol.io.provider", + "descriptor": { "name": "Venky.Mahadevan@Bazaar" }, + "locations": [ + { + "id": "./retail.kirana/ind.blr/1@tourism-bpp-infra2.becknprotocol.io.provider_location", + "gps": "12.909955,77.596316" + } + ], + "categories": [ + { + "id": "c1", + "descriptor": { "code": "grocery", "name": "grocery" } + }, + { + "id": "c2", + "descriptor": { "code": "electronics", "name": "electronics" } + } + ], + "fulfillments": [ + { "id": "f1", "type": "Delivery", "tracking": false }, + { "id": "f2", "type": "Self-Pickup", "tracking": false } + ], + "items": [ + { + "id": "./retail.kirana/ind.blr/247@tourism-bpp-infra2.becknprotocol.io.item", + "descriptor": { + "images": [ + { + "url": "https://tourism-bpp-infra2.becknprotocol.io/attachments/view/253.jpg" + } + ], + "name": "Isothermal Stainless Steel Hiking Flask MH500 Yellow - Water bottle", + "short_desc": "InstaCuppa Stainless Steel Thermos Flask Water Bottle with Sports Sipper Lid, Double Walled Vacuum Insulation", + "long_desc": "<div> <ul> <li>ULTRA MODERN DESIGN - Our thermos bottle is crafted with a unique and modern design. Gone are the days of old and boring flasks. Guaranteed to impress your colleagues, friends & family.</li> <li>ADVANCED TEMPERATURE CONTROL – A double-wall, vacuum-insulated design helps lock in heat for up to 12 hours and cold for up to 24!</li> <li>ELIMINATES CONDENSATION – Offering improved grip and control, these innovative dual-layer bottles offer a slip-resistant surface that’s free of sweat and condensation..</li> <li>LEAK-PROOF and ECO-FRIENDLY – Remove, and clean, the large, screw on lid provides faster access to water inside and won’t spill a drop even when it’s tipped upside or put in your gym bag.</li> <li>The distress quilted jacket is a versatile fashion choice you can wear on any occasion. A style essential piece for Women which will reveal your strong sense of personality</li> </ul> <div> <p><b>Product Details</b></p> <ul> <li>Advanced Temperature Retention.This thermos water bottle ensures your beverages will remain hot or cold for a long time.Hot for up to 12 hours.Cold for up to 24 hours.</li> <li>Retains Original Flavors.Vacuum insulation ensures this travel thermos water bottle is airtight and retains the original flavor of your beverages.Also, this bottle is B.P.A Free.</li> <li>Premium Quality Materials.This stylish bottle is a double-walled vacuum insulated and made from premium 304-grade stainless steel - which makes this flask bottle.</li> </ul> </div>" + }, + "matched": true, + "price": { + "listed_value": "1200.0", + "currency": "INR", + "value": "1200.0" + }, + "recommended": true, + "location_id": "./retail.kirana/ind.blr/1@tourism-bpp-infra2.becknprotocol.io.provider_location", + "category_id": "c1", + "fulfillment_id": "f1", + "tags": [ + { + "descriptor": { "name": "item-cataegory" }, + "list": [ + { + "descriptor": { "name": "category" }, + "value": "retail" + } + ], + "display": true + }, + { + "descriptor": { "name": "item-properties" }, + "list": [ + { + "descriptor": { "name": "waterbottle" }, + "value": "y" + }, + { "descriptor": { "name": "Trekking" }, "value": "y" }, + { "descriptor": { "name": "Sipper" }, "value": "y" }, + { "descriptor": { "name": "Hiking" }, "value": "y" } + ], + "display": true + } + ] + } + ] + } + ] + } + } + } + ] +} diff --git a/src/test/retail/response-to-ui/response.search.json b/src/test/retail/response-to-ui/response.search.json new file mode 100644 index 0000000000000000000000000000000000000000..c3b1a1c5c4dc825a5c1124613601b65c3cc87719 --- /dev/null +++ b/src/test/retail/response-to-ui/response.search.json @@ -0,0 +1,95 @@ +{ + "data": [ + { + "context": { + "domain": "retail:1.1.0", + "action": "on_search", + "version": "1.1.0", + "bpp_id": "beckn-sandbox-bpp.becknprotocol.io", + "bpp_uri": "https://sandbox-bpp-network.becknprotocol.io", + "country": "IND", + "city": "std:080", + "location": { + "country": { + "code": "IND" + }, + "city": { + "code": "std:080" + } + }, + "bap_id": "ps-bap-network.becknprotocol.io", + "bap_uri": "https://ps-bap-network.becknprotocol.io", + "transaction_id": "f649c6aa-d845-4874-9c9c-6020d9140bf7", + "message_id": "a5d31306-c976-4f0d-8d3a-3a377965144f", + "ttl": "PT10M", + "timestamp": "2024-01-12T07:20:34.016Z" + }, + "message": { + "name": "HBO", + "providers": [ + { + "id": "./retail.kirana/ind.blr/33@tourism-bpp-infra2.becknprotocol.io.provider", + "name": "Venky.Mahadevan@Bazaar", + "locations": [ + { + "id": "./retail.kirana/ind.blr/1@tourism-bpp-infra2.becknprotocol.io.provider_location", + "gps": "12.909955,77.596316" + } + ], + "items": [ + { + "id": "./retail.kirana/ind.blr/247@tourism-bpp-infra2.becknprotocol.io.item", + "short_desc": "InstaCuppa Stainless Steel Thermos Flask Water Bottle with Sports Sipper Lid, Double Walled Vacuum Insulation", + "long_desc": "<div> <ul> <li>ULTRA MODERN DESIGN - Our thermos bottle is crafted with a unique and modern design. Gone are the days of old and boring flasks. Guaranteed to impress your colleagues, friends & family.</li> <li>ADVANCED TEMPERATURE CONTROL – A double-wall, vacuum-insulated design helps lock in heat for up to 12 hours and cold for up to 24!</li> <li>ELIMINATES CONDENSATION – Offering improved grip and control, these innovative dual-layer bottles offer a slip-resistant surface that’s free of sweat and condensation..</li> <li>LEAK-PROOF and ECO-FRIENDLY – Remove, and clean, the large, screw on lid provides faster access to water inside and won’t spill a drop even when it’s tipped upside or put in your gym bag.</li> <li>The distress quilted jacket is a versatile fashion choice you can wear on any occasion. A style essential piece for Women which will reveal your strong sense of personality</li> </ul> <div> <p><b>Product Details</b></p> <ul> <li>Advanced Temperature Retention.This thermos water bottle ensures your beverages will remain hot or cold for a long time.Hot for up to 12 hours.Cold for up to 24 hours.</li> <li>Retains Original Flavors.Vacuum insulation ensures this travel thermos water bottle is airtight and retains the original flavor of your beverages.Also, this bottle is B.P.A Free.</li> <li>Premium Quality Materials.This stylish bottle is a double-walled vacuum insulated and made from premium 304-grade stainless steel - which makes this flask bottle.</li> </ul> </div>", + "name": "Isothermal Stainless Steel Hiking Flask MH500 Yellow - Water bottle", + "price": { + "value": "1200.0", + "currency": "INR" + }, + "images": [ + { + "url": "https://tourism-bpp-infra2.becknprotocol.io/attachments/view/253.jpg" + } + ], + "tags": [ + { + "name": "item-cataegory", + "display": true, + "list": [ + { + "name": "category", + "value": "retail" + } + ] + }, + { + "name": "item-properties", + "display": true, + "list": [ + { + "name": "waterbottle", + "value": "y" + }, + { + "name": "Trekking", + "value": "y" + }, + { + "name": "Sipper", + "value": "y" + }, + { + "name": "Hiking", + "value": "y" + } + ] + } + ] + } + ] + } + ] + } + } + ] +}