Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import {AxiosResponse} from "axios";
interface httpClientConfig {
baseURL?: string;
{% if authMethods != null -%}
channelAccessToken: string;
{% for authMethod in authMethods %}
{% if authMethod.isBasicBearer %}
channelAccessToken: string;
{% else %}
{% endif %}
{% endfor %}
{% endif -%}
// TODO support defaultHeaders?
}
Expand All @@ -37,7 +42,12 @@ export class {{operations.classname}} {
this.httpClient = new HTTPClient({
defaultHeaders: {
{% if authMethods != null -%}
Authorization: "Bearer " + config.channelAccessToken,
{% for authMethod in authMethods %}
{% if authMethod.isBasicBearer %}
Authorization: "Bearer " + config.channelAccessToken,
{% else %}
{% endif %}
{% endfor %}
{% endif -%}
},
responseParser: this.parseHTTPResponse.bind(this),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ describe("{{operations.classname}}", () => {

const client = new {{operations.classname}}({
{% if authMethods != null -%}
channelAccessToken: channel_access_token,
{% for authMethod in authMethods %}
{% if authMethod.isBasicBearer %}
channelAccessToken: channel_access_token,
{% else %}
{% endif %}
{% endfor %}
{% endif -%}
});

Expand All @@ -48,10 +53,20 @@ describe("{{operations.classname}}", () => {
requestCount++;

{% if authMethods != null -%}
equal(
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);
{% for authMethod in authMethods %}
{% if authMethod.isBasicBearer %}
equal(
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);
{% else %}
equal(
request.headers.has("Authorization"),
false,
"Authorization header should not be present"
);
{% endif %}
{% endfor %}
{% endif -%}
equal(
request.headers.get("User-Agent"),
Expand Down
2 changes: 2 additions & 0 deletions lib/insight/api/insightClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import { AxiosResponse } from "axios";

interface httpClientConfig {
baseURL?: string;

channelAccessToken: string;

// TODO support defaultHeaders?
}

Expand Down
5 changes: 5 additions & 0 deletions lib/insight/tests/api/InsightClientTest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe("InsightClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -70,6 +71,7 @@ describe("InsightClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -100,6 +102,7 @@ describe("InsightClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -131,6 +134,7 @@ describe("InsightClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -162,6 +166,7 @@ describe("InsightClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down
2 changes: 2 additions & 0 deletions lib/liff/api/liffClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import { AxiosResponse } from "axios";

interface httpClientConfig {
baseURL?: string;

channelAccessToken: string;

// TODO support defaultHeaders?
}

Expand Down
4 changes: 4 additions & 0 deletions lib/liff/tests/api/LiffClientTest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe("LiffClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -72,6 +73,7 @@ describe("LiffClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -99,6 +101,7 @@ describe("LiffClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -126,6 +129,7 @@ describe("LiffClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down
2 changes: 2 additions & 0 deletions lib/manage-audience/api/manageAudienceBlobClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import { AxiosResponse } from "axios";

interface httpClientConfig {
baseURL?: string;

channelAccessToken: string;

// TODO support defaultHeaders?
}

Expand Down
2 changes: 2 additions & 0 deletions lib/manage-audience/api/manageAudienceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ import { AxiosResponse } from "axios";

interface httpClientConfig {
baseURL?: string;

channelAccessToken: string;

// TODO support defaultHeaders?
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe("ManageAudienceBlobClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -76,6 +77,7 @@ describe("ManageAudienceBlobClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down
11 changes: 11 additions & 0 deletions lib/manage-audience/tests/api/ManageAudienceClientTest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe("ManageAudienceClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -84,6 +85,7 @@ describe("ManageAudienceClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -111,6 +113,7 @@ describe("ManageAudienceClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -138,6 +141,7 @@ describe("ManageAudienceClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -165,6 +169,7 @@ describe("ManageAudienceClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -196,6 +201,7 @@ describe("ManageAudienceClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -227,6 +233,7 @@ describe("ManageAudienceClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -254,6 +261,7 @@ describe("ManageAudienceClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -281,6 +289,7 @@ describe("ManageAudienceClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -318,6 +327,7 @@ describe("ManageAudienceClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -349,6 +359,7 @@ describe("ManageAudienceClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down
2 changes: 2 additions & 0 deletions lib/messaging-api/api/messagingApiBlobClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import { AxiosResponse } from "axios";

interface httpClientConfig {
baseURL?: string;

channelAccessToken: string;

// TODO support defaultHeaders?
}

Expand Down
2 changes: 2 additions & 0 deletions lib/messaging-api/api/messagingApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ import { AxiosResponse } from "axios";

interface httpClientConfig {
baseURL?: string;

channelAccessToken: string;

// TODO support defaultHeaders?
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe("MessagingApiBlobClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -74,6 +75,7 @@ describe("MessagingApiBlobClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -105,6 +107,7 @@ describe("MessagingApiBlobClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -136,6 +139,7 @@ describe("MessagingApiBlobClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down Expand Up @@ -167,6 +171,7 @@ describe("MessagingApiBlobClient", () => {
request.headers.get("Authorization"),
`Bearer ${channel_access_token}`,
);

equal(request.headers.get("User-Agent"), `${pkg.name}/${pkg.version}`);

return HttpResponse.json({});
Expand Down
Loading