Skip to content

Commit

Permalink
Add authToken to webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
perrin4869 committed Aug 18, 2020
1 parent 5541f38 commit ebdaea6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/resources/WebHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ export type WebHooksListParams = CRUDPaginationParams;
export interface WebHookCreateParams<Trigger = WebHookTrigger> {
triggers: Trigger[];
url: string;
authToken?: string;
}
export interface WebHookUpdateParams<Trigger = WebHookTrigger> {
triggers?: Trigger[];
url?: string;
authToken?: string;
}

/* Response */
Expand All @@ -44,6 +46,7 @@ export interface WebHookItem<Trigger = WebHookTrigger> {
storeId: string;
triggers: Trigger[];
url: string;
authToken?: string;
createdOn: string;
}

Expand Down
20 changes: 20 additions & 0 deletions test/specs/webhooks.specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ describe("Web Hooks", () => {
}
});

it("should get response with auth token", async () => {
fetchMock.post(recordBasePathMatcher, {
status: 201,
body: recordData,
headers: { "Content-Type": "application/json" },
});

const data: WebHookCreateParams = {
triggers: [WebHookTrigger.CHARGE_FINISHED],
url: "http://fake.com",
authToken: "Bearer mytoken",
};

const asserts = [webHooks.create(data), webHooks.create(data, null, null, uuid())];

for (const assert of asserts) {
await expect(assert).to.eventually.eql(recordData);
}
});

it("should return validation error if data is invalid", async () => {
const asserts: [Partial<WebHookCreateParams>, RequestError][] = [
[{}, createRequestError(["triggers"])],
Expand Down

0 comments on commit ebdaea6

Please sign in to comment.