Co-Authored-By: Claude Fable 5.2 <[email protected]>
27 lines
1.5 KiB
TypeScript
27 lines
1.5 KiB
TypeScript
/**
|
|
* For e2e/mail-relay.spec.ts — LOCAL / CI database only:
|
|
* pnpm payload run e2e/mail-relay-setup.ts the site has no SMTP server and no token: its next e-mail
|
|
* goes to the mail service, enrolling first
|
|
* Afterwards the spec runs e2e/create-test-admin.ts again, which points e-mail back at the tests' SMTP sink.
|
|
*/
|
|
import config from '@payload-config'
|
|
import { RELAY_KV_KEY } from '@intecion/ipal-kit'
|
|
import { isLocalDatabase } from '@intecion/ipal-kit/seed'
|
|
import { getPayload } from 'payload'
|
|
|
|
if (process.env.NODE_ENV === 'production' && !process.env.CI) {throw new Error('Refusing: NODE_ENV=production outside CI.')}
|
|
if (!isLocalDatabase(process.env.DATABASE_URI ?? '')) {throw new Error('Refusing: DATABASE_URI is not a local database.')}
|
|
|
|
const payload = await getPayload({ config })
|
|
await payload.updateGlobal({
|
|
slug: 'site-integrations',
|
|
context: { ipalIntegrationStatus: true },
|
|
data: { emailStatus: { checkedAt: null, code: null, message: null, since: null, state: null }, emailMethod: 'relay', emailTransport: 'smtp', smtpFromAddress: '[email protected]', smtpFromName: 'Example Studio', smtpHost: null, smtpPassword: null, smtpUser: null } as never,
|
|
overrideAccess: true,
|
|
})
|
|
for (const key of await payload.kv.keys()) {
|
|
if (key === RELAY_KV_KEY || key.startsWith(`${RELAY_KV_KEY}:`)) {await payload.kv.delete(key)}
|
|
}
|
|
console.log('[e2e] no SMTP server and no mail-service token: the next e-mail enrols and goes through the mail service')
|
|
process.exit(0)
|