2
0
mirror of https://github.com/frappe/books.git synced 2024-11-14 09:24:04 +00:00
books/tests/testSetupInstance.spec.ts

67 lines
1.6 KiB
TypeScript
Raw Normal View History

import { assertDoesNotThrow } from 'backend/database/tests/helpers';
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,
getTestSetupWizardOptions
} from './helpers';
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-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) {
dbValue = dbValue.toISOString().split('T')[0];
}
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();
});