67 lines
2.2 KiB
TypeScript
67 lines
2.2 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');
|
|
|
|
let testOpenDataInstance: opendata.OpenData;
|
|
let openDataStarted = false;
|
|
let openDataSkipReason = 'OpenData 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();
|
|
openDataStarted = true;
|
|
} catch (error) {
|
|
openDataSkipReason = `Skipping OpenData integration tests: ${plugins.getErrorMessage(error)}`;
|
|
console.warn(openDataSkipReason);
|
|
}
|
|
})
|
|
|
|
tap.test('should persist business records using local smartdb', async (toolsArg) => {
|
|
toolsArg.skipIf(!openDataStarted, openDataSkipReason);
|
|
|
|
const businessRecord = new testOpenDataInstance.CBusinessRecord();
|
|
businessRecord.id = await testOpenDataInstance.CBusinessRecord.getNewId();
|
|
businessRecord.data.name = `Test Company ${plugins.smartunique.uniSimple()}`;
|
|
businessRecord.data.germanParsedRegistration = {
|
|
court: 'Bremen',
|
|
type: 'HRB',
|
|
number: `${Date.now()}`,
|
|
};
|
|
|
|
await businessRecord.save();
|
|
|
|
const storedRecord = await BusinessRecord.getInstance({
|
|
id: businessRecord.id,
|
|
});
|
|
|
|
expect(storedRecord.id).toEqual(businessRecord.id);
|
|
expect(storedRecord.data.name).toEqual(businessRecord.data.name);
|
|
expect(storedRecord.data.germanParsedRegistration).toEqual(
|
|
businessRecord.data.germanParsedRegistration
|
|
);
|
|
});
|
|
|
|
tap.test('should stop the instance', async (toolsArg) => {
|
|
toolsArg.skipIf(!openDataStarted, openDataSkipReason);
|
|
await testOpenDataInstance.stop();
|
|
});
|
|
|
|
export default tap.start()
|