Skip to content

Commit 88691f5

Browse files
authored
fix: stores correct http response for unique test-ids (#41)
Signed-off-by: re-Tick <jain.ritik.1001@gmail.com>
1 parent 8aaaf00 commit 88691f5

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/client.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import http, { Headers, OptionsOfJSONResponseBody, Response } from "got";
1+
import http, { Headers, Options } from "got";
22

33
export class Request {
44
headers: Headers;
5-
options: OptionsOfJSONResponseBody;
5+
options: Options;
66

77
constructor() {
88
this.headers = { "User-Agent": "keploy-typescript-sdk" };
@@ -32,7 +32,7 @@ export class Request {
3232
url: requestUrl,
3333
method: "GET",
3434
headers: this.headers,
35-
responseType: "json",
35+
responseType: "buffer",
3636
searchParams,
3737
};
3838

@@ -49,7 +49,7 @@ export class Request {
4949
url: requestUrl,
5050
method: "POST",
5151
headers: this.headers,
52-
responseType: "json",
52+
responseType: "buffer",
5353
searchParams,
5454
};
5555

@@ -82,7 +82,7 @@ export class Request {
8282
url: requestUrl,
8383
method: "PUT",
8484
headers: this.headers,
85-
responseType: "json",
85+
responseType: "buffer",
8686
searchParams,
8787
};
8888

@@ -99,7 +99,7 @@ export class Request {
9999
url: requestUrl,
100100
method: "PATCH",
101101
headers: this.headers,
102-
responseType: "json",
102+
responseType: "buffer",
103103
searchParams,
104104
};
105105

@@ -136,14 +136,12 @@ export default class HttpClient {
136136
this.baseUrl = baseUrl;
137137
}
138138

139-
async makeHttpRequest<T>(request: Request): Promise<T> {
139+
async makeHttpRequestRaw(request: Request) {
140140
const options = { ...request.raw(), prefixUrl: this.baseUrl };
141-
return http(options).json();
142-
}
143-
144-
async makeHttpRequestRaw<T>(request: Request): Promise<Response<T>> {
145-
const options = { ...request.raw(), prefixUrl: this.baseUrl };
146-
const resp: Response<T> = await http(options);
147-
return resp;
141+
try {
142+
await http(options);
143+
} catch (error) {
144+
console.log(error);
145+
}
148146
}
149147
}

src/keploy.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,13 @@ export default class Keploy {
153153
return this.responses[id];
154154
}
155155

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

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

351-
await client.makeHttpRequestRaw<object>(
356+
await client.makeHttpRequestRaw(
352357
new Request()
353358
.setHttpHeader("KEPLOY_TEST_ID", tc.id)
354359
//@ts-ignore

0 commit comments

Comments
 (0)