@netlify/plugin-emails
Advanced tools
Comparing version
@@ -164,3 +164,3 @@ "use strict"; | ||
return { | ||
statusCode: 400, | ||
statusCode: 200, | ||
body: ` | ||
@@ -211,8 +211,19 @@ <html> | ||
return { | ||
statusCode: 400, | ||
body: JSON.stringify({ | ||
message: `Preview path is not a valid email path - preview path received: ${emailPath}`, | ||
}), | ||
statusCode: 200, | ||
body: ` | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="https://netlify-integration-emails.netlify.app/main.css"> | ||
<script> | ||
missingTemplate = ${JSON.stringify(true)} | ||
siteId = ${JSON.stringify(process.env.SITE_ID)} | ||
templateName = ${JSON.stringify(emailPath)} | ||
</script> | ||
<script defer src='https://netlify-integration-emails.netlify.app/index.js'></script> | ||
</head> | ||
<div id='app'></div> | ||
</html> | ||
`, | ||
headers: { | ||
"Content-Type": "text/plain", | ||
"Content-Type": "text/html", | ||
}, | ||
@@ -226,8 +237,19 @@ }; | ||
return { | ||
statusCode: 400, | ||
body: JSON.stringify({ | ||
message: `No email template found for preview path - preview path received: ${emailPath}`, | ||
}), | ||
statusCode: 200, | ||
body: ` | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="https://netlify-integration-emails.netlify.app/main.css"> | ||
<script> | ||
missingTemplate = ${JSON.stringify(true)} | ||
siteId = ${JSON.stringify(process.env.SITE_ID)} | ||
templateName = ${JSON.stringify(emailPath)} | ||
</script> | ||
<script defer src='https://netlify-integration-emails.netlify.app/index.js'></script> | ||
</head> | ||
<div id='app'></div> | ||
</html> | ||
`, | ||
headers: { | ||
"Content-Type": "text/plain", | ||
"Content-Type": "text/html", | ||
}, | ||
@@ -234,0 +256,0 @@ }; |
{ | ||
"name": "@netlify/plugin-emails", | ||
"version": "0.4.4-preview", | ||
"version": "0.4.5-preview", | ||
"description": "A build plugin that creates an email handler and processes requests to send emails", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -245,3 +245,3 @@ import { Handler } from "@netlify/functions"; | ||
return { | ||
statusCode: 400, | ||
statusCode: 200, | ||
body: ` | ||
@@ -303,8 +303,19 @@ <html> | ||
return { | ||
statusCode: 400, | ||
body: JSON.stringify({ | ||
message: `Preview path is not a valid email path - preview path received: ${emailPath}`, | ||
}), | ||
statusCode: 200, | ||
body: ` | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="https://netlify-integration-emails.netlify.app/main.css"> | ||
<script> | ||
missingTemplate = ${JSON.stringify(true)} | ||
siteId = ${JSON.stringify(process.env.SITE_ID)} | ||
templateName = ${JSON.stringify(emailPath)} | ||
</script> | ||
<script defer src='https://netlify-integration-emails.netlify.app/index.js'></script> | ||
</head> | ||
<div id='app'></div> | ||
</html> | ||
`, | ||
headers: { | ||
"Content-Type": "text/plain", | ||
"Content-Type": "text/html", | ||
}, | ||
@@ -324,8 +335,19 @@ }; | ||
return { | ||
statusCode: 400, | ||
body: JSON.stringify({ | ||
message: `No email template found for preview path - preview path received: ${emailPath}`, | ||
}), | ||
statusCode: 200, | ||
body: ` | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="https://netlify-integration-emails.netlify.app/main.css"> | ||
<script> | ||
missingTemplate = ${JSON.stringify(true)} | ||
siteId = ${JSON.stringify(process.env.SITE_ID)} | ||
templateName = ${JSON.stringify(emailPath)} | ||
</script> | ||
<script defer src='https://netlify-integration-emails.netlify.app/index.js'></script> | ||
</head> | ||
<div id='app'></div> | ||
</html> | ||
`, | ||
headers: { | ||
"Content-Type": "text/plain", | ||
"Content-Type": "text/html", | ||
}, | ||
@@ -332,0 +354,0 @@ }; |
@@ -54,3 +54,3 @@ import { describe, beforeEach, vi, it, expect, afterEach } from "vitest"; | ||
expect(response.statusCode).toBe(400); | ||
expect(response.statusCode).toBe(200); | ||
@@ -69,2 +69,61 @@ expect(response.body).toContain( | ||
it("should return the preview UI when template directory is not found", async () => { | ||
process.env.NETLIFY_EMAILS_SECRET = "test-secret"; | ||
process.env.NETLIFY_EMAILS_DIRECTORY = "./fixtures/emails"; | ||
process.env.NETLIFY_EMAILS_PROVIDER = "sendgrid"; | ||
process.env.NETLIFY_EMAILS_PROVIDER_API_KEY = "some-key"; | ||
const response = (await handler( | ||
{ | ||
rawUrl: | ||
"http://localhost:8888/.netlify/functions/emails/does-not-exist", | ||
httpMethod: "GET", | ||
} as unknown as Event, | ||
{} as unknown as Context | ||
)) as Response; | ||
const templateName = response.body?.match(/templateName = "(.*)"/)?.[1]; | ||
const missingTemplatBool = response.body?.match( | ||
/missingTemplate = (.*)/ | ||
)?.[1]; | ||
expect(response.statusCode).toBe(200); | ||
expect(response.body).toContain( | ||
"<script defer src='https://netlify-integration-emails.netlify.app/index.js'>" | ||
); | ||
expect(templateName).toBe("does-not-exist"); | ||
expect(missingTemplatBool).toBe("true"); | ||
}); | ||
it("should return the preview UI when template file is not found", async () => { | ||
process.env.NETLIFY_EMAILS_SECRET = "test-secret"; | ||
process.env.NETLIFY_EMAILS_DIRECTORY = "./fixtures/emails"; | ||
process.env.NETLIFY_EMAILS_PROVIDER = "sendgrid"; | ||
process.env.NETLIFY_EMAILS_PROVIDER_API_KEY = "some-key"; | ||
const response = (await handler( | ||
{ | ||
rawUrl: "http://localhost:8888/.netlify/functions/emails/error", | ||
httpMethod: "GET", | ||
} as unknown as Event, | ||
{} as unknown as Context | ||
)) as Response; | ||
const templateName = response.body?.match(/templateName = "(.*)"/)?.[1]; | ||
const missingTemplatBool = response.body?.match( | ||
/missingTemplate = (.*)/ | ||
)?.[1]; | ||
expect(response.statusCode).toBe(200); | ||
expect(response.body).toContain( | ||
"<script defer src='https://netlify-integration-emails.netlify.app/index.js'>" | ||
); | ||
expect(templateName).toBe("error"); | ||
expect(missingTemplatBool).toBe("true"); | ||
}); | ||
it("should return the preview UI", async () => { | ||
@@ -71,0 +130,0 @@ process.env.NETLIFY_EMAILS_SECRET = "test-secret"; |
71125
5.62%1814
5.28%29
7.41%