2022-04-24 06:48:44 +00:00
|
|
|
import { assertDoesNotThrow } from 'backend/database/tests/helpers';
|
2023-08-03 07:48:14 +00:00
|
|
|
import { DateTime } from 'luxon';
|
2022-04-24 06:48:44 +00:00
|
|
|
import setupInstance from 'src/setup/setupInstance';
|
2022-04-25 06:33:31 +00:00
|
|
|
import { SetupWizardOptions } from 'src/setup/types';
|
2022-10-31 07:33:50 +00:00
|
|
|
import test from 'tape';
|
2022-04-25 06:33:31 +00:00
|
|
|
import { getValueMapFromList } from 'utils';
|
2022-10-31 07:33:50 +00:00
|
|
|
import {
|
|
|
|
getTestDbPath,
|
|
|
|
getTestFyo,
|
2023-06-27 07:40:04 +00:00
|
|
|
getTestSetupWizardOptions,
|
2022-10-31 07:33:50 +00:00
|
|
|
} from './helpers';
|
2022-04-24 06:48:44 +00:00
|
|
|
|
2022-10-31 07:33:50 +00:00
|
|
|
const dbPath = getTestDbPath();
|
|
|
|
const setupOptions = getTestSetupWizardOptions();
|
|
|
|
const fyo = getTestFyo();
|
2022-04-25 06:33:31 +00:00
|
|
|
|
2022-10-31 07:33:50 +00:00
|
|
|
test('setupInstance', async () => {
|
|
|
|
await assertDoesNotThrow(async () => {
|
|
|
|
await setupInstance(dbPath, setupOptions, fyo);
|
|
|
|
}, 'setup instance failed');
|
|
|
|
});
|
2022-04-24 06:48:44 +00:00
|
|
|
|
2022-10-31 07:33:50 +00:00
|
|
|
test('check setup Singles', async (t) => {
|
|
|
|
const setupFields = [
|
|
|
|
'companyName',
|
|
|
|
'country',
|
|
|
|
'fullname',
|
|
|
|
'email',
|
|
|
|
'bankName',
|
|
|
|
'fiscalYearStart',
|
|
|
|
'fiscalYearEnd',
|
|
|
|
'currency',
|
|
|
|
];
|
2022-04-25 06:33:31 +00:00
|
|
|
|
2022-10-31 07:33:50 +00:00
|
|
|
const setupSingles = await fyo.db.getSingleValues(...setupFields);
|
|
|
|
const singlesMap = getValueMapFromList(setupSingles, 'fieldname', 'value');
|
2022-04-25 06:33:31 +00:00
|
|
|
|
2022-10-31 07:33:50 +00:00
|
|
|
for (const field of setupFields) {
|
|
|
|
let dbValue = singlesMap[field];
|
|
|
|
const optionsValue = setupOptions[field as keyof SetupWizardOptions];
|
2022-04-25 06:33:31 +00:00
|
|
|
|
2022-10-31 07:33:50 +00:00
|
|
|
if (dbValue instanceof Date) {
|
2023-08-03 07:48:14 +00:00
|
|
|
dbValue = DateTime.fromJSDate(dbValue).toISODate();
|
2022-10-31 07:33:50 +00:00
|
|
|
}
|
2022-04-25 06:33:31 +00:00
|
|
|
|
2022-10-31 07:33:50 +00:00
|
|
|
t.equal(
|
|
|
|
dbValue as string,
|
|
|
|
optionsValue,
|
|
|
|
`${field}: (${dbValue}, ${optionsValue})`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2022-04-25 06:33:31 +00:00
|
|
|
|
2022-10-31 07:33:50 +00:00
|
|
|
test('check null singles', async (t) => {
|
|
|
|
const nullFields = ['gstin', 'logo', 'phone', 'address'];
|
|
|
|
const nullSingles = await fyo.db.getSingleValues(...nullFields);
|
2022-04-25 06:33:31 +00:00
|
|
|
|
2022-10-31 07:33:50 +00:00
|
|
|
t.equal(
|
|
|
|
nullSingles.length,
|
|
|
|
0,
|
|
|
|
`null singles: ${JSON.stringify(nullSingles)}`
|
|
|
|
);
|
|
|
|
});
|
2022-04-25 06:33:31 +00:00
|
|
|
|
2022-10-31 07:33:50 +00:00
|
|
|
test.onFinish(async () => {
|
|
|
|
await fyo.close();
|
2022-04-24 06:48:44 +00:00
|
|
|
});
|