fix: keep absent brief SMS content empty

This commit is contained in:
hectorzhao
2026-09-03 09:37:24 +08:00
parent fe5b25a7e4
commit 068b8047dd
4 changed files with 13 additions and 9 deletions
@@ -95,8 +95,10 @@ export class ReportChannelExportService {
const values = fields.map(
(field) => resolveExportValue(item.snapshot, field.code, field.name) ?? field.defaultValue ?? '',
);
const smsContentIndex = fields.findIndex((field) => field.name.trim() === '短信内容');
const smsContentValue = smsContentIndex >= 0 ? values[smsContentIndex] : '';
const smsContentField = fields.find((field) => field.name.trim() === '短信内容');
const smsContentValue = smsContentField
? resolveExportValue(item.snapshot, smsContentField.code, smsContentField.name) ?? ''
: '';
const smsContent = isFileRef(smsContentValue) ? '' : String(smsContentValue ?? '');
const missing = fields.filter((field, index) => field.required && !hasValue(values[index]));
const missingReason =
@@ -149,7 +149,7 @@ describe('ReportMaterialsService', () => {
]);
});
it('expands one selected signature to every routed channel and embeds images in each XLSX', async () => {
it('expands one selected signature to every routed channel, embeds images and snapshots the first material SMS content', async () => {
const uploadedWorkbooks: Buffer[] = [];
let batchItemSequence = 0;
let exportSequence = 0;
@@ -189,6 +189,8 @@ describe('ReportMaterialsService', () => {
drainageInfo: {
signatureReportValues: {
license: { fileObjectId: 'image-1', fileName: 'license.png', contentType: 'image/png' },
sms_content_primary: '第一条短信内容',
sms_content_secondary: '第二条短信内容',
},
},
tenant: { name: '测试企业' },
@@ -223,7 +225,7 @@ describe('ReportMaterialsService', () => {
),
},
channelReportField: {
findMany: jest.fn().mockResolvedValue([
findMany: jest.fn().mockImplementation(({ where }: { where: { channelId: string } }) => Promise.resolve([
{
code: 'sign',
name: '短信签名',
@@ -247,7 +249,7 @@ describe('ReportMaterialsService', () => {
defaultValue: null,
},
{
code: 'sms_content_primary',
code: where.channelId === 'channel-b' ? 'sms_content_missing' : 'sms_content_primary',
name: '短信内容',
exportName: '短信内容一',
required: false,
@@ -268,7 +270,7 @@ describe('ReportMaterialsService', () => {
transform: null,
defaultValue: '第二条短信内容',
},
]),
])),
},
channelSignatureReportTask: {
findMany: jest.fn().mockResolvedValue([]),
@@ -331,7 +333,7 @@ describe('ReportMaterialsService', () => {
snapshot: expect.objectContaining({
briefSmsContentByChannel: {
'channel-a': '第一条短信内容',
'channel-b': '第一条短信内容',
'channel-b': '',
},
}),
},