Skip to content

Commit

Permalink
fix: stores correct http response for unique test-ids (#41)
Browse files Browse the repository at this point in the history
Signed-off-by: re-Tick <[email protected]>
  • Loading branch information
re-Tick authored Feb 14, 2023
1 parent 8aaaf00 commit 88691f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
26 changes: 12 additions & 14 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import http, { Headers, OptionsOfJSONResponseBody, Response } from "got";
import http, { Headers, Options } from "got";

export class Request {
headers: Headers;
options: OptionsOfJSONResponseBody;
options: Options;

constructor() {
this.headers = { "User-Agent": "keploy-typescript-sdk" };
Expand Down Expand Up @@ -32,7 +32,7 @@ export class Request {
url: requestUrl,
method: "GET",
headers: this.headers,
responseType: "json",
responseType: "buffer",
searchParams,
};

Expand All @@ -49,7 +49,7 @@ export class Request {
url: requestUrl,
method: "POST",
headers: this.headers,
responseType: "json",
responseType: "buffer",
searchParams,
};

Expand Down Expand Up @@ -82,7 +82,7 @@ export class Request {
url: requestUrl,
method: "PUT",
headers: this.headers,
responseType: "json",
responseType: "buffer",
searchParams,
};

Expand All @@ -99,7 +99,7 @@ export class Request {
url: requestUrl,
method: "PATCH",
headers: this.headers,
responseType: "json",
responseType: "buffer",
searchParams,
};

Expand Down Expand Up @@ -136,14 +136,12 @@ export default class HttpClient {
this.baseUrl = baseUrl;
}

async makeHttpRequest<T>(request: Request): Promise<T> {
async makeHttpRequestRaw(request: Request) {
const options = { ...request.raw(), prefixUrl: this.baseUrl };
return http(options).json();
}

async makeHttpRequestRaw<T>(request: Request): Promise<Response<T>> {
const options = { ...request.raw(), prefixUrl: this.baseUrl };
const resp: Response<T> = await http(options);
return resp;
try {
await http(options);
} catch (error) {
console.log(error);
}
}
}
9 changes: 7 additions & 2 deletions src/keploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,13 @@ export default class Keploy {
return this.responses[id];
}

// stores http response for unique test-ids to capture them at middleware layer
putResp(id: ID, resp: HttpResponse) {
this.responses[id] = resp;
// put http response in map only once for unique test-ids. Since, finish event
// can trigger multiple time for redirect.
if (this.responses[id] === null || this.responses[id] === undefined) {
this.responses[id] = resp;
}
}

capture(req: TestCaseReq) {
Expand Down Expand Up @@ -348,7 +353,7 @@ export default class Keploy {
//@ts-ignore
const requestUrl = `${tc.HttpReq?.URL.substr(1)}`;

await client.makeHttpRequestRaw<object>(
await client.makeHttpRequestRaw(
new Request()
.setHttpHeader("KEPLOY_TEST_ID", tc.id)
//@ts-ignore
Expand Down

0 comments on commit 88691f5

Please sign in to comment.