50 lines
1.9 KiB
JavaScript
50 lines
1.9 KiB
JavaScript
import { test, expect } from '@playwright/test';
|
|
import { adminPath, apiPost, ensureDataSource, ensureMailshot, cleanupByNames } from './helpers.mjs';
|
|
|
|
test('run/test pages: load and failure-path API assertions', async ({ page, request }) => {
|
|
const uniq = `${Date.now()}_${Math.floor(Math.random() * 100000)}`;
|
|
const dsName = `e2e_run_ds_${uniq}`;
|
|
const purpose = `e2e_run_ms_${uniq}`;
|
|
|
|
try {
|
|
await ensureDataSource(request, dsName, 'contacts');
|
|
await ensureMailshot(request, {
|
|
Purpose: purpose,
|
|
DataSource: dsName,
|
|
CC: '',
|
|
BCC: '',
|
|
Subject: 'Subj {{ contacts.id }}',
|
|
Message: '<p>Hi {{ contacts.id }}</p>',
|
|
PDFAttachment: '<p>PDF</p>',
|
|
AttachmentNames: '[]',
|
|
PDFFilenameDerivedFrom: '',
|
|
RecipientEmailField: 'contacts.contact_email_1',
|
|
ReplyTo: ''
|
|
});
|
|
|
|
await page.goto(adminPath('feca-mailshots-run'));
|
|
await expect(page.getByRole('heading', { name: 'Run Mailshot' })).toBeVisible();
|
|
|
|
await page.goto(adminPath('feca-mailshots-test'));
|
|
await expect(page.getByRole('heading', { name: 'Mailshot Test' })).toBeVisible();
|
|
|
|
const runInvalid = await apiPost(request, 'feca_mailshots_run_api', 'run_mailshot', { mailshot_id: '0' });
|
|
expect(runInvalid.ok).toBeFalsy();
|
|
expect(String((runInvalid.errors || []).join(' | ') || runInvalid.error || '')).toContain('Missing mail credentials');
|
|
|
|
const sendBlank = await apiPost(request, 'feca_mailshots_test_api', 'send_test', {
|
|
mailshot_id: '1',
|
|
recipient_index: '0',
|
|
test_email: ''
|
|
});
|
|
expect(sendBlank.ok).toBeFalsy();
|
|
expect(String((sendBlank.errors || []).join(' | ') || sendBlank.error || '')).toContain('Test email address is required');
|
|
} finally {
|
|
try {
|
|
await cleanupByNames(request, { dataSourceNames: [dsName], mailshotPurposes: [purpose] });
|
|
} catch {
|
|
// best effort
|
|
}
|
|
}
|
|
});
|