Skip to content

Commit

Permalink
feat(global): 🧪 adding function
Browse files Browse the repository at this point in the history
adding new function in refresh token file

ref #67
  • Loading branch information
Animesh1432 committed May 3, 2024
1 parent 61e0f41 commit 04dcadb
Showing 1 changed file with 4 additions and 60 deletions.
64 changes: 4 additions & 60 deletions test/service/refreshToken.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -78,8 +22,8 @@ describe("login", () => {

test("TC01 Verify API Response Status Code _ through function", async () => {
//{ emailOrPhone: "[email protected]", password: "Pritam@rxefy123" }
const response = await apiTest({
method: APIReqMethod.POST,
const response = await wrappidTest.apiTest({
method: coreConstant.httpMethod.HTTP_POST,
endpoint: "login",
data: { emailOrPhone: "[email protected]", password: "Asdf123@@" }
});
Expand Down

0 comments on commit 04dcadb

Please sign in to comment.