From 04dcadbeec9e2d7b76c6162612cd9ce37b4b12c3 Mon Sep 17 00:00:00 2001 From: Animesh1432 Date: Fri, 3 May 2024 16:32:02 +0530 Subject: [PATCH] feat(global): :test_tube: adding function adding new function in refresh token file ref #67 --- test/service/refreshToken.test.ts | 64 ++----------------------------- 1 file changed, 4 insertions(+), 60 deletions(-) diff --git a/test/service/refreshToken.test.ts b/test/service/refreshToken.test.ts index a3e27a3..eb5440e 100644 --- a/test/service/refreshToken.test.ts +++ b/test/service/refreshToken.test.ts @@ -1,66 +1,10 @@ import { describe, test, expect } from "@jest/globals"; +import { WrappaidTest, coreConstant } from "@wrappid/service-core"; import request from "supertest"; const API_URL = "https://demoapi.wrappid.dev/"; -const APIReqMethod: {[key: string]: RequestMethod} = { - GET: "get", - POST: "post", - PUT: "put", - PATCH: "patch" -}; - -type GenericObject ={ - [key: string]: any -} - -type RequestMethod = "get" | "post" | "put" | "patch"; - -type APITestOptionsType = { - method: RequestMethod; - endpoint: string; - data?: GenericObject -} - -async function apiTest(options: APITestOptionsType) { - const apiRequest = request(API_URL); - // .set("Content-Type", "application/json") - // .set("Accept-Encoding", "gzip, deflate, br") - // .set("Connection", "keep-alive") - // .set("User-Agent", - // "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); - - let requestInstance = null; - - switch (options.method) { - case APIReqMethod.GET: - requestInstance = apiRequest.get(options.endpoint); - - break; - case APIReqMethod.POST: - requestInstance = apiRequest.post(options.endpoint); - - break; - case APIReqMethod.PUT: - requestInstance = apiRequest.put(options.endpoint); - - break; - case APIReqMethod.PATCH: - requestInstance = apiRequest.patch(options.endpoint); - - break; - default: - throw new Error("Method was not mentioned"); - break; - } - - return await requestInstance.send(options.data).set("Content-Type", "application/json") - .set("Accept-Encoding", "gzip, deflate, br") - .set("Connection", "keep-alive") - .set("User-Agent", - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"); - -} +const wrappidTest = new WrappaidTest({baseURL: API_URL}); describe("login", () => { test("TC01 Verify API Response Status Code", async () => { @@ -78,8 +22,8 @@ describe("login", () => { test("TC01 Verify API Response Status Code _ through function", async () => { //{ emailOrPhone: "pritam@rxefy.com", password: "Pritam@rxefy123" } - const response = await apiTest({ - method: APIReqMethod.POST, + const response = await wrappidTest.apiTest({ + method: coreConstant.httpMethod.HTTP_POST, endpoint: "login", data: { emailOrPhone: "neel@rxefy.com", password: "Asdf123@@" } });