From 51edd5d6d441db923cc4b6874acb8caa6325c92f Mon Sep 17 00:00:00 2001 From: Max Edell Date: Tue, 3 Mar 2026 19:27:26 -0800 Subject: [PATCH 1/2] fix: handle brand new sheets --- src/actions/processor/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/processor/index.js b/src/actions/processor/index.js index a258a84..49685c8 100644 --- a/src/actions/processor/index.js +++ b/src/actions/processor/index.js @@ -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); From 07aeaddee3bd390e2e4943ae34f4a82da984d3f5 Mon Sep 17 00:00:00 2001 From: Max Edell Date: Tue, 3 Mar 2026 19:38:52 -0800 Subject: [PATCH 2/2] chore: fix test --- test/processor.test.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/test/processor.test.js b/test/processor.test.js index cfe84f1..e96b39b 100644 --- a/test/processor.test.js +++ b/test/processor.test.js @@ -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' })], + }), + }), + }), + ); }); });