testing for sending files via smtp
This commit is contained in:
parent
40d575ee58
commit
99f2b3e7fd
|
@ -50,6 +50,7 @@ describe("test the outgoing webhook action", () => {
|
||||||
cc: "cc",
|
cc: "cc",
|
||||||
bcc: "bcc",
|
bcc: "bcc",
|
||||||
addInvite: true,
|
addInvite: true,
|
||||||
|
attachments: "attachment1,attachment2",
|
||||||
...invite,
|
...invite,
|
||||||
}
|
}
|
||||||
let resp = generateResponse(inputs.to, inputs.from)
|
let resp = generateResponse(inputs.to, inputs.from)
|
||||||
|
@ -69,6 +70,7 @@ describe("test the outgoing webhook action", () => {
|
||||||
bcc: "bcc",
|
bcc: "bcc",
|
||||||
invite,
|
invite,
|
||||||
automation: true,
|
automation: true,
|
||||||
|
attachments: ["attachment1", "attachment2"],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
const mockS3 = {
|
|
||||||
headBucket: jest.fn().mockReturnThis(),
|
|
||||||
deleteObject: jest.fn().mockReturnThis(),
|
|
||||||
deleteObjects: jest.fn().mockReturnThis(),
|
|
||||||
createBucket: jest.fn().mockReturnThis(),
|
|
||||||
listObjects: jest.fn().mockReturnThis(),
|
|
||||||
promise: jest.fn().mockReturnThis(),
|
|
||||||
catch: jest.fn(),
|
|
||||||
}
|
|
||||||
|
|
||||||
const AWS = {
|
|
||||||
S3: jest.fn(() => mockS3),
|
|
||||||
}
|
|
||||||
|
|
||||||
export default AWS
|
|
|
@ -1,7 +1,11 @@
|
||||||
jest.unmock("node-fetch")
|
jest.unmock("node-fetch")
|
||||||
import { TestConfiguration } from "../../../../tests"
|
import { TestConfiguration } from "../../../../tests"
|
||||||
import { EmailTemplatePurpose } from "../../../../constants"
|
import { EmailTemplatePurpose } from "../../../../constants"
|
||||||
|
import { objectStoreTestProviders, mocks } from "@budibase/backend-core/tests"
|
||||||
|
import { objectStore } from "@budibase/backend-core"
|
||||||
|
import env from "../../../../environment"
|
||||||
|
import tk from "timekeeper"
|
||||||
|
jest.unmock("aws-sdk")
|
||||||
const nodemailer = require("nodemailer")
|
const nodemailer = require("nodemailer")
|
||||||
const fetch = require("node-fetch")
|
const fetch = require("node-fetch")
|
||||||
|
|
||||||
|
@ -12,14 +16,16 @@ describe("/api/global/email", () => {
|
||||||
const config = new TestConfiguration()
|
const config = new TestConfiguration()
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
await objectStoreTestProviders.minio.start()
|
||||||
await config.beforeAll()
|
await config.beforeAll()
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
|
await objectStoreTestProviders.minio.stop()
|
||||||
await config.afterAll()
|
await config.afterAll()
|
||||||
})
|
})
|
||||||
|
|
||||||
async function sendRealEmail(purpose: string) {
|
async function sendRealEmail(purpose: string, attachments?: string[]) {
|
||||||
let response, text
|
let response, text
|
||||||
try {
|
try {
|
||||||
const timeout = () =>
|
const timeout = () =>
|
||||||
|
@ -35,8 +41,14 @@ describe("/api/global/email", () => {
|
||||||
)
|
)
|
||||||
await Promise.race([config.saveEtherealSmtpConfig(), timeout()])
|
await Promise.race([config.saveEtherealSmtpConfig(), timeout()])
|
||||||
await Promise.race([config.saveSettingsConfig(), timeout()])
|
await Promise.race([config.saveSettingsConfig(), timeout()])
|
||||||
|
let res
|
||||||
const res = await config.api.emails.sendEmail(purpose).timeout(20000)
|
if (attachments) {
|
||||||
|
res = await config.api.emails
|
||||||
|
.sendEmail(purpose, attachments)
|
||||||
|
.timeout(20000)
|
||||||
|
} else {
|
||||||
|
res = await config.api.emails.sendEmail(purpose).timeout(20000)
|
||||||
|
}
|
||||||
// ethereal hiccup, can't test right now
|
// ethereal hiccup, can't test right now
|
||||||
if (res.status >= 300) {
|
if (res.status >= 300) {
|
||||||
return
|
return
|
||||||
|
@ -81,4 +93,19 @@ describe("/api/global/email", () => {
|
||||||
it("should be able to send a password recovery email", async () => {
|
it("should be able to send a password recovery email", async () => {
|
||||||
await sendRealEmail(EmailTemplatePurpose.PASSWORD_RECOVERY)
|
await sendRealEmail(EmailTemplatePurpose.PASSWORD_RECOVERY)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should be able to send an email with attachments", async () => {
|
||||||
|
tk.reset()
|
||||||
|
let bucket = "test-bucket"
|
||||||
|
let filename = "test.txt"
|
||||||
|
await objectStore.upload({
|
||||||
|
bucket,
|
||||||
|
filename,
|
||||||
|
body: Buffer.from("test data"),
|
||||||
|
})
|
||||||
|
tk.freeze(mocks.date.MOCK_DATE)
|
||||||
|
let presignedUrl = await objectStore.getPresignedUrl(bucket, filename, 600)
|
||||||
|
|
||||||
|
await sendRealEmail(EmailTemplatePurpose.WELCOME, [presignedUrl])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,11 +6,12 @@ export class EmailAPI extends TestAPI {
|
||||||
super(config)
|
super(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
sendEmail = (purpose: string) => {
|
sendEmail = (purpose: string, attachments?: string[]) => {
|
||||||
return this.request
|
return this.request
|
||||||
.post(`/api/global/email/send`)
|
.post(`/api/global/email/send`)
|
||||||
.send({
|
.send({
|
||||||
email: "test@example.com",
|
email: "test@example.com",
|
||||||
|
attachments,
|
||||||
purpose,
|
purpose,
|
||||||
tenantId: this.config.getTenantId(),
|
tenantId: this.config.getTenantId(),
|
||||||
userId: this.config.user?._id!,
|
userId: this.config.user?._id!,
|
||||||
|
|
|
@ -4,8 +4,8 @@ process.env.JWT_SECRET = "test-jwtsecret"
|
||||||
process.env.LOG_LEVEL = process.env.LOG_LEVEL || "error"
|
process.env.LOG_LEVEL = process.env.LOG_LEVEL || "error"
|
||||||
process.env.MULTI_TENANCY = "1"
|
process.env.MULTI_TENANCY = "1"
|
||||||
process.env.MINIO_URL = "http://localhost"
|
process.env.MINIO_URL = "http://localhost"
|
||||||
process.env.MINIO_ACCESS_KEY = "test"
|
process.env.MINIO_ACCESS_KEY = "budibase"
|
||||||
process.env.MINIO_SECRET_KEY = "test"
|
process.env.MINIO_SECRET_KEY = "budibase"
|
||||||
process.env.PLATFORM_URL = "http://localhost:10000"
|
process.env.PLATFORM_URL = "http://localhost:10000"
|
||||||
process.env.INTERNAL_API_KEY = "tet"
|
process.env.INTERNAL_API_KEY = "tet"
|
||||||
process.env.DISABLE_ACCOUNT_PORTAL = "0"
|
process.env.DISABLE_ACCOUNT_PORTAL = "0"
|
||||||
|
|
|
@ -62,8 +62,8 @@ export function smtpEthereal(): SMTPConfig {
|
||||||
from: "testfrom@example.com",
|
from: "testfrom@example.com",
|
||||||
secure: false,
|
secure: false,
|
||||||
auth: {
|
auth: {
|
||||||
user: "wyatt.zulauf29@ethereal.email",
|
user: "mortimer.leuschke@ethereal.email",
|
||||||
pass: "tEwDtHBWWxusVWAPfa",
|
pass: "5hSjsPbzRv7gEUsfzx",
|
||||||
},
|
},
|
||||||
connectionTimeout: 1000, // must be less than the jest default of 5000
|
connectionTimeout: 1000, // must be less than the jest default of 5000
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue