2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 03:19:01 +00:00
books/tests/testSetupInstance.spec.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

79 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-04-25 06:33:31 +00:00
import * as assert from 'assert';
import { DatabaseManager } from 'backend/database/manager';
import { assertDoesNotThrow } from 'backend/database/tests/helpers';
import { Fyo } from 'fyo';
import { DummyAuthDemux } from 'fyo/tests/helpers';
import 'mocha';
import setupInstance from 'src/setup/setupInstance';
2022-04-25 06:33:31 +00:00
import { SetupWizardOptions } from 'src/setup/types';
import { getValueMapFromList } from 'utils';
import { getTestDbPath, getTestSetupWizardOptions } from './helpers';
describe('setupInstance', function () {
2022-04-25 06:33:31 +00:00
const dbPath = getTestDbPath();
const setupOptions = getTestSetupWizardOptions();
let fyo: Fyo;
this.beforeAll(function () {
fyo = new Fyo({
DatabaseDemux: DatabaseManager,
AuthDemux: DummyAuthDemux,
isTest: true,
isElectron: false,
});
});
this.afterAll(async function () {
await fyo.close();
});
specify('setupInstance', async function () {
await assertDoesNotThrow(async () => {
2022-04-25 06:33:31 +00:00
await setupInstance(dbPath, setupOptions, fyo);
}, 'setup instance failed');
});
2022-04-25 06:33:31 +00:00
specify('check setup Singles', async function () {
const setupFields = [
'companyName',
'country',
'fullname',
'email',
'bankName',
'fiscalYearStart',
'fiscalYearEnd',
'currency',
];
const setupSingles = await fyo.db.getSingleValues(...setupFields);
const singlesMap = getValueMapFromList(setupSingles, 'fieldname', 'value');
for (const field of setupFields) {
let dbValue = singlesMap[field];
const optionsValue = setupOptions[field as keyof SetupWizardOptions];
if (dbValue instanceof Date) {
dbValue = dbValue.toISOString().split('T')[0];
}
assert.strictEqual(
dbValue as string,
optionsValue,
`${field} mismatch (${dbValue},${optionsValue})`
);
2022-04-25 06:33:31 +00:00
}
});
specify('check null singles', async function () {
const nullFields = ['gstin', 'logo', 'phone', 'address'];
const nullSingles = await fyo.db.getSingleValues(...nullFields);
assert.strictEqual(
nullSingles.length,
0,
`null singles found ${JSON.stringify(nullSingles)}`
);
});
});