-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix resend integration headers (#219)
* fix: resend integration headers content-type header wasn't being sent, so resend couldn't process the request. But the integration worked before. So I am suspecting that QStash used to set a default content header but it doesn't anymore. To fix the issue, I added a utility to properly merge the headers and added tests to make sure that we don't miss this behavior. * fix: add method option to providers
- Loading branch information
Showing
8 changed files
with
131 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,9 @@ describe("email", () => { | |
const resendToken = nanoid(); | ||
const client = new Client({ baseUrl: MOCK_QSTASH_SERVER_URL, token: qstashToken }); | ||
|
||
const header = "my-header"; | ||
const headerValue = "my-header-value"; | ||
|
||
test("should use resend", async () => { | ||
await mockQStashServer({ | ||
execute: async () => { | ||
|
@@ -17,6 +20,9 @@ describe("email", () => { | |
name: "email", | ||
provider: resend({ token: resendToken }), | ||
}, | ||
headers: { | ||
[header]: headerValue, | ||
}, | ||
body: { | ||
from: "Acme <[email protected]>", | ||
to: ["[email protected]"], | ||
|
@@ -42,6 +48,9 @@ describe("email", () => { | |
headers: { | ||
authorization: `Bearer ${qstashToken}`, | ||
"upstash-forward-authorization": `Bearer ${resendToken}`, | ||
"content-type": "application/json", | ||
[`upstash-forward-${header}`]: headerValue, | ||
"upstash-method": "POST", | ||
}, | ||
}, | ||
}); | ||
|
@@ -55,6 +64,70 @@ describe("email", () => { | |
name: "email", | ||
provider: resend({ token: resendToken, batch: true }), | ||
}, | ||
headers: { | ||
[header]: headerValue, | ||
}, | ||
body: [ | ||
{ | ||
from: "Acme <[email protected]>", | ||
to: ["[email protected]"], | ||
subject: "hello world", | ||
html: "<h1>it works!</h1>", | ||
}, | ||
{ | ||
from: "Acme <[email protected]>", | ||
to: ["[email protected]"], | ||
subject: "world hello", | ||
html: "<p>it works!</p>", | ||
}, | ||
], | ||
}); | ||
}, | ||
responseFields: { | ||
body: { messageId: "msgId" }, | ||
status: 200, | ||
}, | ||
receivesRequest: { | ||
method: "POST", | ||
token: qstashToken, | ||
url: "http://localhost:8080/v2/publish/https://api.resend.com/emails/batch", | ||
body: [ | ||
{ | ||
from: "Acme <[email protected]>", | ||
to: ["[email protected]"], | ||
subject: "hello world", | ||
html: "<h1>it works!</h1>", | ||
}, | ||
{ | ||
from: "Acme <[email protected]>", | ||
to: ["[email protected]"], | ||
subject: "world hello", | ||
html: "<p>it works!</p>", | ||
}, | ||
], | ||
headers: { | ||
authorization: `Bearer ${qstashToken}`, | ||
"upstash-forward-authorization": `Bearer ${resendToken}`, | ||
"content-type": "application/json", | ||
[`upstash-forward-${header}`]: headerValue, | ||
"upstash-method": "POST", | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
test("should be able to overwrite method", async () => { | ||
await mockQStashServer({ | ||
execute: async () => { | ||
await client.publishJSON({ | ||
api: { | ||
name: "email", | ||
provider: resend({ token: resendToken, batch: true }), | ||
}, | ||
headers: { | ||
[header]: headerValue, | ||
}, | ||
method: "PUT", | ||
body: [ | ||
{ | ||
from: "Acme <[email protected]>", | ||
|
@@ -96,6 +169,9 @@ describe("email", () => { | |
headers: { | ||
authorization: `Bearer ${qstashToken}`, | ||
"upstash-forward-authorization": `Bearer ${resendToken}`, | ||
"content-type": "application/json", | ||
[`upstash-forward-${header}`]: headerValue, | ||
"upstash-method": "PUT", | ||
}, | ||
}, | ||
}); | ||
|
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