2022-04-11 07:15:35 +00:00
|
|
|
import * as assert from 'assert';
|
2022-04-07 13:38:17 +00:00
|
|
|
import 'mocha';
|
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-04-19 05:59:36 +00:00
|
|
|
import { Fyo } from '..';
|
2022-04-18 06:42:56 +00:00
|
|
|
import { DatabaseManager } from '../../backend/database/manager';
|
2022-04-18 11:29:20 +00:00
|
|
|
import { DummyAuthDemux } from './helpers';
|
2022-04-07 13:38:17 +00:00
|
|
|
|
2022-04-19 05:59:36 +00:00
|
|
|
describe('Fyo Init', function () {
|
|
|
|
const fyo = new Fyo({
|
2022-04-18 11:29:20 +00:00
|
|
|
DatabaseDemux: DatabaseManager,
|
|
|
|
AuthDemux: DummyAuthDemux,
|
|
|
|
isTest: true,
|
|
|
|
isElectron: false,
|
|
|
|
});
|
2022-04-07 13:38:17 +00:00
|
|
|
|
|
|
|
specify('Init', async function () {
|
2022-04-11 07:15:35 +00:00
|
|
|
assert.strictEqual(
|
2022-04-19 05:59:36 +00:00
|
|
|
Object.keys(fyo.schemaMap).length,
|
2022-04-11 07:15:35 +00:00
|
|
|
0,
|
|
|
|
'zero schemas one'
|
|
|
|
);
|
2022-04-18 11:29:20 +00:00
|
|
|
|
2022-04-11 07:15:35 +00:00
|
|
|
assert.strictEqual(
|
2022-04-19 05:59:36 +00:00
|
|
|
Object.keys(fyo.schemaMap).length,
|
2022-04-11 07:15:35 +00:00
|
|
|
0,
|
|
|
|
'zero schemas two'
|
|
|
|
);
|
|
|
|
|
2022-04-19 05:59:36 +00:00
|
|
|
await fyo.db.createNewDatabase(':memory:', 'in');
|
|
|
|
await fyo.initializeAndRegister({}, {});
|
2022-04-11 07:15:35 +00:00
|
|
|
assert.strictEqual(
|
2022-04-19 05:59:36 +00:00
|
|
|
Object.keys(fyo.schemaMap).length > 0,
|
2022-04-11 07:15:35 +00:00
|
|
|
true,
|
|
|
|
'non zero schemas'
|
|
|
|
);
|
2022-07-30 11:03:09 +00:00
|
|
|
await fyo.db.purgeCache();
|
2022-04-07 13:38:17 +00:00
|
|
|
});
|
|
|
|
});
|
2022-04-18 11:29:20 +00:00
|
|
|
|
2022-04-19 05:59:36 +00:00
|
|
|
describe('Fyo Docs', function () {
|
2022-04-18 11:29:20 +00:00
|
|
|
const countryCode = 'in';
|
2022-04-19 05:59:36 +00:00
|
|
|
let fyo: Fyo;
|
2022-04-20 06:38:47 +00:00
|
|
|
const schemaMap = getSchemas(countryCode);
|
2022-04-18 11:29:20 +00:00
|
|
|
this.beforeEach(async function () {
|
2022-04-19 05:59:36 +00:00
|
|
|
fyo = new Fyo({
|
2022-04-18 11:29:20 +00:00
|
|
|
DatabaseDemux: DatabaseManager,
|
|
|
|
isTest: true,
|
|
|
|
isElectron: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const regionalModels = await getRegionalModels(countryCode);
|
2022-04-19 05:59:36 +00:00
|
|
|
await fyo.db.createNewDatabase(':memory:', countryCode);
|
|
|
|
await fyo.initializeAndRegister(models, regionalModels);
|
2022-04-18 11:29:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.afterEach(async function () {
|
2022-04-19 05:59:36 +00:00
|
|
|
await fyo.close();
|
2022-04-18 11:29:20 +00:00
|
|
|
});
|
|
|
|
|
2022-04-24 06:48:44 +00:00
|
|
|
specify('getNewDoc', async function () {
|
2022-04-20 06:38:47 +00:00
|
|
|
for (const schemaName in schemaMap) {
|
|
|
|
const schema = schemaMap[schemaName];
|
|
|
|
if (schema?.isSingle) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-04-24 06:48:44 +00:00
|
|
|
const doc = fyo.doc.getNewDoc(schemaName);
|
2022-04-20 06:38:47 +00:00
|
|
|
}
|
2022-04-18 11:29:20 +00:00
|
|
|
});
|
|
|
|
});
|