From 2be2bb494d0acb5eb2f731bc9dfcaadc4978c525 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Tue, 28 Nov 2023 16:53:21 +0800 Subject: [PATCH] feat: add test cases Signed-off-by: SuZhou-Joe --- server/utils/csv-parser-helper.test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 server/utils/csv-parser-helper.test.ts diff --git a/server/utils/csv-parser-helper.test.ts b/server/utils/csv-parser-helper.test.ts new file mode 100644 index 00000000..6671ae39 --- /dev/null +++ b/server/utils/csv-parser-helper.test.ts @@ -0,0 +1,21 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { getJsonFromString } from './csv-parser-helper'; + +describe('getJsonFromString', () => { + it('return correct answer', async () => { + expect(await getJsonFromString('title,id\n1,2')).toEqual([ + { + title: '1', + id: '2', + }, + ]); + }); + + it('return empty array when string is not in correct format', async () => { + expect(await getJsonFromString('1,2')).toEqual([]); + }); +});