-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: Don't overwrite req with parsedReq * fix: Update schema, add tests
- Loading branch information
1 parent
4e29137
commit cde4cd5
Showing
8 changed files
with
97 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,8 +32,23 @@ describe("Create reminder event webhook", () => { | |
it("returns a 400 if a required value is missing", async () => { | ||
const missingCreatedAt = { createdAt: null, payload: {} }; | ||
const missingPayload = { createdAt: new Date(), payload: null }; | ||
|
||
for (const body of [missingCreatedAt, missingPayload]) { | ||
const missingEmail = { | ||
createdAt: new Date(), | ||
payload: { sessionId: "abc123" }, | ||
}; | ||
const missingSessionId = { | ||
createdAt: new Date(), | ||
payload: { email: "[email protected]" }, | ||
}; | ||
|
||
const invalidRequestBodies = [ | ||
missingCreatedAt, | ||
missingPayload, | ||
missingEmail, | ||
missingSessionId, | ||
]; | ||
|
||
for (const body of invalidRequestBodies) { | ||
await post(ENDPOINT) | ||
.set({ Authorization: process.env.HASURA_PLANX_API_KEY }) | ||
.send(body) | ||
|
@@ -46,7 +61,10 @@ describe("Create reminder event webhook", () => { | |
}); | ||
|
||
it("returns a 200 on successful event setup", async () => { | ||
const body = { createdAt: new Date(), payload: { sessionId: "123" } }; | ||
const body = { | ||
createdAt: new Date(), | ||
payload: { sessionId: "123", email: "[email protected]" }, | ||
}; | ||
mockedCreateScheduledEvent.mockResolvedValue(mockScheduledEventResponse); | ||
|
||
await post(ENDPOINT) | ||
|
@@ -64,7 +82,10 @@ describe("Create reminder event webhook", () => { | |
}); | ||
|
||
it("passes the correct arguments along to createScheduledEvent", async () => { | ||
const body = { createdAt: new Date(), payload: { sessionId: "123" } }; | ||
const body = { | ||
createdAt: new Date(), | ||
payload: { sessionId: "123", email: "[email protected]" }, | ||
}; | ||
mockedCreateScheduledEvent.mockResolvedValue(mockScheduledEventResponse); | ||
|
||
await post(ENDPOINT) | ||
|
@@ -96,7 +117,10 @@ describe("Create reminder event webhook", () => { | |
}); | ||
|
||
it("returns a 500 on event setup failure", async () => { | ||
const body = { createdAt: new Date(), payload: { sessionId: "123" } }; | ||
const body = { | ||
createdAt: new Date(), | ||
payload: { sessionId: "123", email: "[email protected]" }, | ||
}; | ||
mockedCreateScheduledEvent.mockRejectedValue(new Error("Failed!")); | ||
|
||
await post(ENDPOINT) | ||
|
@@ -143,20 +167,27 @@ describe("Create expiry event webhook", () => { | |
}); | ||
|
||
it("returns a 200 on successful event setup", async () => { | ||
const body = { createdAt: new Date(), payload: { sessionId: "123" } }; | ||
const body = { | ||
createdAt: new Date(), | ||
payload: { sessionId: "123", email: "[email protected]" }, | ||
}; | ||
mockedCreateScheduledEvent.mockResolvedValue(mockScheduledEventResponse); | ||
|
||
await post(ENDPOINT) | ||
.set({ Authorization: process.env.HASURA_PLANX_API_KEY }) | ||
.send(body) | ||
.expect(200) | ||
.then((response) => { | ||
// expect(mockedCreateScheduledEvent).toHaveBeenCalledWith(body.p) | ||
expect(response.body).toStrictEqual([mockScheduledEventResponse]); | ||
}); | ||
}); | ||
|
||
it("passes the correct arguments along to createScheduledEvent", async () => { | ||
const body = { createdAt: new Date(), payload: { sessionId: "123" } }; | ||
const body = { | ||
createdAt: new Date(), | ||
payload: { sessionId: "123", email: "[email protected]" }, | ||
}; | ||
mockedCreateScheduledEvent.mockResolvedValue(mockScheduledEventResponse); | ||
|
||
await post(ENDPOINT) | ||
|
@@ -173,7 +204,10 @@ describe("Create expiry event webhook", () => { | |
}); | ||
|
||
it("returns a 500 on event setup failure", async () => { | ||
const body = { createdAt: new Date(), payload: { sessionId: "123" } }; | ||
const body = { | ||
createdAt: new Date(), | ||
payload: { sessionId: "123", email: "[email protected]" }, | ||
}; | ||
mockedCreateScheduledEvent.mockRejectedValue(new Error("Failed!")); | ||
|
||
await post(ENDPOINT) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters