Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/actions/processor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function appendToSheet(ctx, sheet, record, sheetName = 'private-data') {
// if all properties of the first record are empty, it's a new sheet with no data
// use the ordered record as the header row to avoid an empty row between the header and data
// otherwise, append the ordered record to the data array
if (Object.values(dest.data[0]).every((value) => value === '')) {
if (Object.values(dest.data[0] ?? {}).every((value) => value === '')) {
dest.data[0] = orderedRecord;
} else {
dest.data.push(orderedRecord);
Expand Down
19 changes: 15 additions & 4 deletions test/processor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,24 @@ describe('processor action', () => {
});

test('uses deadletter path when folder has no entries', async () => {
mockMakeContext.mockResolvedValue(makeCtx());
const ctx = makeCtx();
mockMakeContext.mockResolvedValue(ctx);
mockListFolder.mockResolvedValue([]);

const result = await main({});
// empty entries → deadletter path; also means new sheet (INITIAL_SHEET)
// which has an empty data array, causing appendToSheet to error
expect(result.error.statusCode).toBe(500);
expect(result.statusCode).toBe(200);
expect(mockUpdateSheet).toHaveBeenCalledWith(
ctx,
`/incoming/deadletter/contact-us/${YEAR}.json`,
expect.objectContaining({
':private': expect.objectContaining({
'private-data': expect.objectContaining({
total: 1,
data: [expect.objectContaining({ name: 'John' })],
}),
}),
}),
);
});
});

Expand Down
Loading