From b761669aca050c7622ecee457af0b5d0ba2646fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A0=95=EA=B7=BC?= Date: Thu, 14 May 2026 18:17:36 +0900 Subject: [PATCH] test: cover JSON import payload validation --- src/import/json.test.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/import/json.test.ts b/src/import/json.test.ts index 04b4ed1..5fc1733 100644 --- a/src/import/json.test.ts +++ b/src/import/json.test.ts @@ -106,6 +106,40 @@ describe('JSON Import Module', () => { expect(jsonResponse.error).toBe('No file uploaded') }) + it('should reject JSON payloads without a data array', async () => { + const invalidPayloads = [ + {}, + { data: null }, + { data: { id: 1, name: 'Alice' } }, + ] + + for (const payload of invalidPayloads) { + const request = new Request('http://localhost', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(payload), + }) + + const response = await importTableFromJsonRoute( + 'users', + request, + mockDataSource, + mockConfig + ) + + expect(response.status).toBe(400) + const jsonResponse = (await response.json()) as { + error?: string + result?: any + } + expect(jsonResponse.error).toBe( + 'Invalid JSON format. Expected an object with "data" array and optional "columnMapping".' + ) + } + + expect(executeOperation).not.toHaveBeenCalled() + }) + it('should successfully insert valid JSON data into the table', async () => { vi.mocked(executeOperation).mockResolvedValue([])