test: add test email adapter, use for all tests by default (#6120)
This commit is contained in:
@@ -101,7 +101,7 @@ export default joi.object({
|
||||
validate: joi.func().required(),
|
||||
})
|
||||
.unknown(),
|
||||
email: joi.object(),
|
||||
email: joi.alternatives().try(joi.object(), joi.func()),
|
||||
endpoints: endpointsSchema,
|
||||
globals: joi.array(),
|
||||
graphQL: joi.object().keys({
|
||||
|
||||
@@ -34,6 +34,7 @@ import sharp from 'sharp'
|
||||
|
||||
import { reInitEndpoint } from './helpers/reInit.js'
|
||||
import { localAPIEndpoint } from './helpers/sdk/endpoint.js'
|
||||
import { testEmailAdapter } from './testEmailAdapter.js'
|
||||
// process.env.PAYLOAD_DATABASE = 'postgres'
|
||||
|
||||
export async function buildConfigWithDefaults(
|
||||
@@ -74,23 +75,7 @@ export async function buildConfigWithDefaults(
|
||||
const config: Config = {
|
||||
db: databaseAdapters[process.env.PAYLOAD_DATABASE || 'mongodb'],
|
||||
secret: 'TEST_SECRET',
|
||||
//editor: slateEditor({}),
|
||||
// editor: slateEditor({
|
||||
// admin: {
|
||||
// upload: {
|
||||
// collections: {
|
||||
// media: {
|
||||
// fields: [
|
||||
// {
|
||||
// name: 'alt',
|
||||
// type: 'text',
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }),
|
||||
email: testEmailAdapter,
|
||||
endpoints: [localAPIEndpoint, reInitEndpoint],
|
||||
editor: lexicalEditor({
|
||||
features: [
|
||||
|
||||
38
test/testEmailAdapter.ts
Normal file
38
test/testEmailAdapter.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import type { EmailAdapter, SendEmailOptions } from 'payload/config'
|
||||
|
||||
/**
|
||||
* Logs all emails to stdout
|
||||
*/
|
||||
export const testEmailAdapter: EmailAdapter<void> = ({ payload }) => ({
|
||||
name: 'test-email-adapter',
|
||||
defaultFromAddress: 'dev@payloadcms.com',
|
||||
defaultFromName: 'Payload Test',
|
||||
sendEmail: async (message) => {
|
||||
const stringifiedTo = getStringifiedToAddress(message)
|
||||
const res = `Test email to: '${stringifiedTo}', Subject: '${message.subject}'`
|
||||
payload.logger.info({ msg: res, content: message })
|
||||
return Promise.resolve()
|
||||
},
|
||||
})
|
||||
|
||||
export function getStringifiedToAddress(message: SendEmailOptions): string | undefined {
|
||||
let stringifiedTo: string | undefined
|
||||
|
||||
if (typeof message.to === 'string') {
|
||||
stringifiedTo = message.to
|
||||
} else if (Array.isArray(message.to)) {
|
||||
stringifiedTo = message.to
|
||||
.map((to) => {
|
||||
if (typeof to === 'string') {
|
||||
return to
|
||||
} else if (to.address) {
|
||||
return to.address
|
||||
}
|
||||
return ''
|
||||
})
|
||||
.join(', ')
|
||||
} else if (message.to.address) {
|
||||
stringifiedTo = message.to.address
|
||||
}
|
||||
return stringifiedTo
|
||||
}
|
||||
Reference in New Issue
Block a user