From 4030bef7a8f1f2da96174f1e3208ae7133dd4d15 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Tue, 8 Apr 2025 15:31:29 +0000 Subject: [PATCH] fix(tests & jsonl): Improve test structure and refine JSONL parsing for incomplete data --- changelog.md | 6 ++++++ test/test.handelsregister.ts | 42 ++++++++++++++++++++++++++++++++++++ test/test.ts | 23 -------------------- ts/00_commitinfo_data.ts | 2 +- ts/classes.jsonldata.ts | 5 +++-- 5 files changed, 52 insertions(+), 26 deletions(-) create mode 100644 test/test.handelsregister.ts diff --git a/changelog.md b/changelog.md index b340adb..30fc946 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 2025-04-08 - 1.4.6 - fix(tests & jsonl) +Improve test structure and refine JSONL parsing for incomplete data + +- Refactored test files to remove redundant get-specific-company tests in test.ts and added missing tests in test.handelsregister.ts +- Updated JSONL data processor to conditionally parse remaining data when available + ## 2025-04-05 - 1.4.5 - fix(metadata) Update repository, bugs, and homepage URLs to code.foss.global diff --git a/test/test.handelsregister.ts b/test/test.handelsregister.ts new file mode 100644 index 0000000..2b824f6 --- /dev/null +++ b/test/test.handelsregister.ts @@ -0,0 +1,42 @@ +import { expect, expectAsync, tap } from '@push.rocks/tapbundle'; +import * as opendata from '../ts/index.js' + +import { BusinessRecord } from '../ts/classes.businessrecord.js'; + +let testOpenDataInstance: opendata.OpenData; + +tap.test('first test', async () => { + testOpenDataInstance = new opendata.OpenData(); + expect(testOpenDataInstance).toBeInstanceOf(opendata.OpenData); +}); + +tap.test('should start the instance', async () => { + await testOpenDataInstance.start(); +}); + +const resultsSearch = tap.test('should get the data for a company', async () => { + const result = await testOpenDataInstance.handelsregister.searchCompany('LADR', 20); + console.log(result); + return result; +}); + +tap.test('should get the data for a specific company', async () => { + let testCompany: BusinessRecord['data']['germanParsedRegistration'] = (await resultsSearch.testResultPromise)[0]['germanParsedRegistration']; + console.log(`trying to find specific company with:`); + console.log(testCompany); + const result = await testOpenDataInstance.handelsregister.getSpecificCompany(testCompany); + console.log(result); + + result.files.map(async (file) => { + await file.writeToDir('./.nogit/testoutput'); + }); + + +}); + +tap.test('should stop the instance', async () => { + await testOpenDataInstance.stop(); +}); + + +tap.start() diff --git a/test/test.ts b/test/test.ts index 0f04614..34a4238 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,7 +1,4 @@ import { expect, expectAsync, tap } from '@push.rocks/tapbundle'; - -import { tapNodeTools } from '@push.rocks/tapbundle/node'; - import * as opendata from '../ts/index.js' import { BusinessRecord } from '../ts/classes.businessrecord.js'; @@ -21,26 +18,6 @@ tap.test('should build initial data', async () => { await testOpenDataInstance.buildInitialDb(); }); -const resultsSearch = tap.test('should get the data for a company', async () => { - const result = await testOpenDataInstance.handelsregister.searchCompany('LADR', 20); - console.log(result); - return result; -}); - -tap.test('should get the data for a specific company', async () => { - let testCompany: BusinessRecord['data']['germanParsedRegistration'] = (await resultsSearch.testResultPromise)[7]['germanParsedRegistration']; - console.log(`trying to find specific company with:`); - console.log(testCompany); - const result = await testOpenDataInstance.handelsregister.getSpecificCompany(testCompany); - console.log(result); - - result.files.map(async (file) => { - await file.writeToDir('./.nogit/testoutput'); - }); - - -}); - tap.test('should stop the instance', async () => { await testOpenDataInstance.stop(); }); diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 32c2468..ab02266 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@fin.cx/opendata', - version: '1.4.5', + version: '1.4.6', description: 'A TypeScript library for accessing, managing, and updating open business data, focused on German companies and integrating with MongoDB.' } diff --git a/ts/classes.jsonldata.ts b/ts/classes.jsonldata.ts index 4158cb5..55b4478 100644 --- a/ts/classes.jsonldata.ts +++ b/ts/classes.jsonldata.ts @@ -96,8 +96,9 @@ export class JsonlDataProcessor { }, finalFunction: async (streamToolsArg) => { console.log(`finished processing ${totalRecordsCounter} records.`); - if (!nextRest) return; - JSON.parse(nextRest); + if (nextRest) { + JSON.parse(nextRest); + }; done.resolve(); }, })