Files
opendata/test/test.handelsregister.ts
T

69 lines
2.6 KiB
TypeScript

import { expect, tap } from '@git.zone/tstest/tapbundle';
import * as opendata from '../ts/index.js'
import * as paths from '../ts/paths.js';
import * as plugins from '../ts/plugins.js';
import { BusinessRecord } from '../ts/classes.businessrecord.js';
// Test configuration - explicit paths required
const testNogitDir = plugins.path.join(paths.packageDir, '.nogit');
const testDownloadDir = plugins.path.join(testNogitDir, 'downloads');
const testGermanBusinessDataDir = plugins.path.join(testNogitDir, 'germanbusinessdata');
const testOutputDir = plugins.path.join(testNogitDir, 'testoutput');
let testOpenDataInstance: opendata.OpenData;
let handelsregisterStarted = false;
let handelsregisterSkipReason = 'Handelsregister integration requirements are unavailable.';
tap.test('first test', async () => {
testOpenDataInstance = new opendata.OpenData({
nogitDir: testNogitDir,
downloadDir: testDownloadDir,
germanBusinessDataDir: testGermanBusinessDataDir
});
expect(testOpenDataInstance).toBeInstanceOf(opendata.OpenData);
});
tap.test('should start the instance', async () => {
try {
await testOpenDataInstance.start();
handelsregisterStarted = true;
} catch (error) {
handelsregisterSkipReason = `Skipping Handelsregister integration tests: ${plugins.getErrorMessage(error)}`;
console.warn(handelsregisterSkipReason);
}
});
const resultsSearch = tap.test('should get the data for a company', async (toolsArg) => {
toolsArg.skipIf(!handelsregisterStarted, handelsregisterSkipReason);
const result = await testOpenDataInstance.handelsregister.searchCompany('LADR', 20);
console.log(result);
return result;
});
tap.test('should get the data for a specific company', async (toolsArg) => {
toolsArg.skipIf(!handelsregisterStarted, handelsregisterSkipReason);
const searchResults = await resultsSearch.testResultPromise as BusinessRecord['data'][];
let testCompany: BusinessRecord['data']['germanParsedRegistration'] = searchResults[0].germanParsedRegistration;
console.log(`trying to find specific company with:`);
console.log(testCompany);
const result = await testOpenDataInstance.handelsregister.getSpecificCompany(testCompany);
console.log(result);
await plugins.smartfs.directory(testOutputDir).create();
await Promise.all(result.files.map(async (file) => {
await file.writeToDiskAtPath(
plugins.path.join(testOutputDir, plugins.path.basename(file.path))
);
}));
});
tap.test('should stop the instance', async (toolsArg) => {
toolsArg.skipIf(!handelsregisterStarted, handelsregisterSkipReason);
await testOpenDataInstance.stop();
});
export default tap.start()