Skip to content

Commit

Permalink
add test case for HTTPFetchClient
Browse files Browse the repository at this point in the history
  • Loading branch information
tokuhirom committed Feb 28, 2024
1 parent b713ea5 commit c074990
Show file tree
Hide file tree
Showing 13 changed files with 297 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export class {{operations.classname}} {
});
}

private parseHTTPResponse(response: Response) {
private async parseHTTPResponse(response: Response) {
const { LINE_REQUEST_ID_HTTP_HEADER_NAME } = Types;
let resBody: Record<string, any> = {
...response.json(),
...await response.json(),
};
if (response.headers.get(LINE_REQUEST_ID_HTTP_HEADER_NAME)) {
resBody[LINE_REQUEST_ID_HTTP_HEADER_NAME] =
Expand Down
4 changes: 2 additions & 2 deletions lib/channel-access-token/api/channelAccessTokenClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export class ChannelAccessTokenClient {
});
}

private parseHTTPResponse(response: Response) {
private async parseHTTPResponse(response: Response) {
const { LINE_REQUEST_ID_HTTP_HEADER_NAME } = Types;
let resBody: Record<string, any> = {
...response.json(),
...(await response.json()),
};
if (response.headers.get(LINE_REQUEST_ID_HTTP_HEADER_NAME)) {
resBody[LINE_REQUEST_ID_HTTP_HEADER_NAME] = response.headers.get(
Expand Down
5 changes: 2 additions & 3 deletions lib/http-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export interface FetchRequestConfig {
interface httpFetchClientConfig {
baseURL: string;
defaultHeaders: Record<string, string>;
responseParser: <T>(res: Response) => T;
responseParser: <T>(res: Response) => Promise<T>;
}

export default class HTTPFetchClient {
private readonly baseURL: string;
private readonly defaultHeaders: Record<string, string>;
private readonly responseParser: <T>(res: Response) => T;
private readonly responseParser: <T>(res: Response) => Promise<T>;

constructor(config: httpFetchClientConfig) {
this.baseURL = config.baseURL;
Expand Down Expand Up @@ -136,7 +136,6 @@ export default class HTTPFetchClient {
this.checkResponseStatus(response);
return response.json();
}

public async postBinaryContent<T>(url: string, body: Blob): Promise<T> {
const response = await fetch(this.baseURL + url, {
method: "POST",
Expand Down
4 changes: 2 additions & 2 deletions lib/insight/api/insightClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ export class InsightClient {
});
}

private parseHTTPResponse(response: Response) {
private async parseHTTPResponse(response: Response) {
const { LINE_REQUEST_ID_HTTP_HEADER_NAME } = Types;
let resBody: Record<string, any> = {
...response.json(),
...(await response.json()),
};
if (response.headers.get(LINE_REQUEST_ID_HTTP_HEADER_NAME)) {
resBody[LINE_REQUEST_ID_HTTP_HEADER_NAME] = response.headers.get(
Expand Down
4 changes: 2 additions & 2 deletions lib/liff/api/liffClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ export class LiffClient {
});
}

private parseHTTPResponse(response: Response) {
private async parseHTTPResponse(response: Response) {
const { LINE_REQUEST_ID_HTTP_HEADER_NAME } = Types;
let resBody: Record<string, any> = {
...response.json(),
...(await response.json()),
};
if (response.headers.get(LINE_REQUEST_ID_HTTP_HEADER_NAME)) {
resBody[LINE_REQUEST_ID_HTTP_HEADER_NAME] = response.headers.get(
Expand Down
4 changes: 2 additions & 2 deletions lib/manage-audience/api/manageAudienceBlobClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export class ManageAudienceBlobClient {
});
}

private parseHTTPResponse(response: Response) {
private async parseHTTPResponse(response: Response) {
const { LINE_REQUEST_ID_HTTP_HEADER_NAME } = Types;
let resBody: Record<string, any> = {
...response.json(),
...(await response.json()),
};
if (response.headers.get(LINE_REQUEST_ID_HTTP_HEADER_NAME)) {
resBody[LINE_REQUEST_ID_HTTP_HEADER_NAME] = response.headers.get(
Expand Down
4 changes: 2 additions & 2 deletions lib/manage-audience/api/manageAudienceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ export class ManageAudienceClient {
});
}

private parseHTTPResponse(response: Response) {
private async parseHTTPResponse(response: Response) {
const { LINE_REQUEST_ID_HTTP_HEADER_NAME } = Types;
let resBody: Record<string, any> = {
...response.json(),
...(await response.json()),
};
if (response.headers.get(LINE_REQUEST_ID_HTTP_HEADER_NAME)) {
resBody[LINE_REQUEST_ID_HTTP_HEADER_NAME] = response.headers.get(
Expand Down
4 changes: 2 additions & 2 deletions lib/messaging-api/api/messagingApiBlobClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export class MessagingApiBlobClient {
});
}

private parseHTTPResponse(response: Response) {
private async parseHTTPResponse(response: Response) {
const { LINE_REQUEST_ID_HTTP_HEADER_NAME } = Types;
let resBody: Record<string, any> = {
...response.json(),
...(await response.json()),
};
if (response.headers.get(LINE_REQUEST_ID_HTTP_HEADER_NAME)) {
resBody[LINE_REQUEST_ID_HTTP_HEADER_NAME] = response.headers.get(
Expand Down
4 changes: 2 additions & 2 deletions lib/messaging-api/api/messagingApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ export class MessagingApiClient {
});
}

private parseHTTPResponse(response: Response) {
private async parseHTTPResponse(response: Response) {
const { LINE_REQUEST_ID_HTTP_HEADER_NAME } = Types;
let resBody: Record<string, any> = {
...response.json(),
...(await response.json()),
};
if (response.headers.get(LINE_REQUEST_ID_HTTP_HEADER_NAME)) {
resBody[LINE_REQUEST_ID_HTTP_HEADER_NAME] = response.headers.get(
Expand Down
4 changes: 2 additions & 2 deletions lib/module-attach/api/lineModuleAttachClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export class LineModuleAttachClient {
});
}

private parseHTTPResponse(response: Response) {
private async parseHTTPResponse(response: Response) {
const { LINE_REQUEST_ID_HTTP_HEADER_NAME } = Types;
let resBody: Record<string, any> = {
...response.json(),
...(await response.json()),
};
if (response.headers.get(LINE_REQUEST_ID_HTTP_HEADER_NAME)) {
resBody[LINE_REQUEST_ID_HTTP_HEADER_NAME] = response.headers.get(
Expand Down
4 changes: 2 additions & 2 deletions lib/module/api/lineModuleClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export class LineModuleClient {
});
}

private parseHTTPResponse(response: Response) {
private async parseHTTPResponse(response: Response) {
const { LINE_REQUEST_ID_HTTP_HEADER_NAME } = Types;
let resBody: Record<string, any> = {
...response.json(),
...(await response.json()),
};
if (response.headers.get(LINE_REQUEST_ID_HTTP_HEADER_NAME)) {
resBody[LINE_REQUEST_ID_HTTP_HEADER_NAME] = response.headers.get(
Expand Down
4 changes: 2 additions & 2 deletions lib/shop/api/shopClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export class ShopClient {
});
}

private parseHTTPResponse(response: Response) {
private async parseHTTPResponse(response: Response) {
const { LINE_REQUEST_ID_HTTP_HEADER_NAME } = Types;
let resBody: Record<string, any> = {
...response.json(),
...(await response.json()),
};
if (response.headers.get(LINE_REQUEST_ID_HTTP_HEADER_NAME)) {
resBody[LINE_REQUEST_ID_HTTP_HEADER_NAME] = response.headers.get(
Expand Down

0 comments on commit c074990

Please sign in to comment.