2022-04-21 13:08:36 +00:00
|
|
|
import { getRegionalModels, models } from 'models';
|
2022-04-18 11:29:20 +00:00
|
|
|
import { getSchemas } from 'schemas';
|
2022-10-31 07:33:50 +00:00
|
|
|
import test from 'tape';
|
|
|
|
import { getTestFyo } from 'tests/helpers';
|
2022-04-07 13:38:17 +00:00
|
|
|
|
2022-10-31 07:33:50 +00:00
|
|
|
test('Fyo Init', async (t) => {
|
|
|
|
const fyo = getTestFyo();
|
|
|
|
t.equal(Object.keys(fyo.schemaMap).length, 0, 'zero schemas');
|
2022-04-07 13:38:17 +00:00
|
|
|
|
2022-10-31 07:33:50 +00:00
|
|
|
await fyo.db.createNewDatabase(':memory:', 'in');
|
|
|
|
await fyo.initializeAndRegister({}, {});
|
2022-04-18 11:29:20 +00:00
|
|
|
|
2022-10-31 07:33:50 +00:00
|
|
|
t.equal(Object.keys(fyo.schemaMap).length > 0, true, 'non zero schemas');
|
|
|
|
await fyo.close();
|
2022-04-07 13:38:17 +00:00
|
|
|
});
|
2022-04-18 11:29:20 +00:00
|
|
|
|
2022-10-31 07:33:50 +00:00
|
|
|
test('Fyo Docs', async (t) => {
|
2022-04-18 11:29:20 +00:00
|
|
|
const countryCode = 'in';
|
2022-10-31 07:33:50 +00:00
|
|
|
const fyo = getTestFyo();
|
2023-08-03 07:48:14 +00:00
|
|
|
const schemaMap = getSchemas(countryCode, []);
|
2022-10-31 07:33:50 +00:00
|
|
|
const regionalModels = await getRegionalModels(countryCode);
|
|
|
|
await fyo.db.createNewDatabase(':memory:', countryCode);
|
|
|
|
await fyo.initializeAndRegister(models, regionalModels);
|
|
|
|
|
|
|
|
for (const schemaName in schemaMap) {
|
|
|
|
const schema = schemaMap[schemaName];
|
|
|
|
if (schema?.isSingle) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-04-18 11:29:20 +00:00
|
|
|
|
2022-10-31 07:33:50 +00:00
|
|
|
const doc = fyo.doc.getNewDoc(schemaName);
|
|
|
|
t.equal(doc.schemaName, schemaName, `equal schemaNames: ${schemaName}`);
|
|
|
|
}
|
2022-04-20 06:38:47 +00:00
|
|
|
|
2022-10-31 07:33:50 +00:00
|
|
|
await fyo.close();
|
2022-04-18 11:29:20 +00:00
|
|
|
});
|