mirror of
https://github.com/frappe/books.git
synced 2024-12-23 03:19:01 +00:00
Merge pull request #491 from 18alantom/update-tests
refactor: mocha → tape
This commit is contained in:
commit
f281c891e8
6
.github/workflows/build.yml
vendored
6
.github/workflows/build.yml
vendored
@ -1,10 +1,6 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [$default-branch]
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
pull_request:
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
@ -25,7 +21,7 @@ jobs:
|
||||
- name: Checkout Books
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Books
|
||||
- name: Install Dependencies
|
||||
run: yarn
|
||||
|
||||
- name: Install RPM
|
||||
|
6
.github/workflows/publish.yml
vendored
6
.github/workflows/publish.yml
vendored
@ -14,7 +14,7 @@ jobs:
|
||||
- name: Checkout Books
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Books
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
yarn set version 1.22.18
|
||||
yarn
|
||||
@ -65,7 +65,7 @@ jobs:
|
||||
- name: Checkout Books
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Books
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
yarn set version 1.22.18
|
||||
yarn
|
||||
@ -113,7 +113,7 @@ jobs:
|
||||
- name: Checkout Books
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Books
|
||||
- name: Install Dependencies
|
||||
run: yarn
|
||||
|
||||
- name: Set Error Log Creds
|
||||
|
32
.github/workflows/test.yml
vendored
Normal file
32
.github/workflows/test.yml
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
name: Test
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [$default-branch]
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
pull_request:
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
setup_and_test:
|
||||
runs-on: macos-11
|
||||
steps:
|
||||
- name: Setup node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '16.13.1'
|
||||
|
||||
- name: Set yarn version
|
||||
run: yarn set version 1.22.18
|
||||
|
||||
- name: Checkout Books
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Dependencies
|
||||
run: yarn
|
||||
|
||||
- name: Yarn Tests
|
||||
run: yarn test
|
File diff suppressed because it is too large
Load Diff
@ -1,49 +1,27 @@
|
||||
import * as assert from 'assert';
|
||||
import { DatabaseManager } from 'backend/database/manager';
|
||||
import { assertDoesNotThrow } from 'backend/database/tests/helpers';
|
||||
import { purchaseItemPartyMap } from 'dummy/helpers';
|
||||
import { Fyo } from 'fyo';
|
||||
import { DummyAuthDemux } from 'fyo/tests/helpers';
|
||||
import 'mocha';
|
||||
import { getTestDbPath } from 'tests/helpers';
|
||||
import test from 'tape';
|
||||
import { getTestDbPath, getTestFyo } from 'tests/helpers';
|
||||
import { setupDummyInstance } from '..';
|
||||
|
||||
describe('dummy', function () {
|
||||
const dbPath = getTestDbPath();
|
||||
const dbPath = getTestDbPath();
|
||||
const fyo = getTestFyo();
|
||||
|
||||
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('setupDummyInstance', async function () {
|
||||
await assertDoesNotThrow(async () => {
|
||||
await setupDummyInstance(dbPath, fyo, 1, 25);
|
||||
}, 'setup instance failed');
|
||||
|
||||
for (const item in purchaseItemPartyMap) {
|
||||
assert.strictEqual(
|
||||
await fyo.db.exists('Item', item),
|
||||
true,
|
||||
`not found ${item}`
|
||||
);
|
||||
|
||||
const party = purchaseItemPartyMap[item];
|
||||
assert.strictEqual(
|
||||
await fyo.db.exists('Party', party),
|
||||
true,
|
||||
`not found ${party}`
|
||||
);
|
||||
}
|
||||
}).timeout(120_000);
|
||||
test('setupDummyInstance', async () => {
|
||||
await assertDoesNotThrow(async () => {
|
||||
await setupDummyInstance(dbPath, fyo, 1, 25);
|
||||
}, 'setup instance failed');
|
||||
});
|
||||
|
||||
test('purchaseItemParty Existance', async (t) => {
|
||||
for (const item in purchaseItemPartyMap) {
|
||||
t.ok(await fyo.db.exists('Item', item), `item exists: ${item}`);
|
||||
|
||||
const party = purchaseItemPartyMap[item];
|
||||
t.ok(await fyo.db.exists('Party', party), `party exists: ${party}`);
|
||||
}
|
||||
});
|
||||
|
||||
test.onFinish(async () => {
|
||||
await fyo.close();
|
||||
});
|
||||
|
@ -1,71 +1,36 @@
|
||||
import * as assert from 'assert';
|
||||
import 'mocha';
|
||||
import { getRegionalModels, models } from 'models';
|
||||
import { getSchemas } from 'schemas';
|
||||
import { Fyo } from '..';
|
||||
import { DatabaseManager } from '../../backend/database/manager';
|
||||
import { DummyAuthDemux } from './helpers';
|
||||
import test from 'tape';
|
||||
import { getTestFyo } from 'tests/helpers';
|
||||
|
||||
describe('Fyo Init', function () {
|
||||
const fyo = new Fyo({
|
||||
DatabaseDemux: DatabaseManager,
|
||||
AuthDemux: DummyAuthDemux,
|
||||
isTest: true,
|
||||
isElectron: false,
|
||||
});
|
||||
test('Fyo Init', async (t) => {
|
||||
const fyo = getTestFyo();
|
||||
t.equal(Object.keys(fyo.schemaMap).length, 0, 'zero schemas');
|
||||
|
||||
specify('Init', async function () {
|
||||
assert.strictEqual(
|
||||
Object.keys(fyo.schemaMap).length,
|
||||
0,
|
||||
'zero schemas one'
|
||||
);
|
||||
await fyo.db.createNewDatabase(':memory:', 'in');
|
||||
await fyo.initializeAndRegister({}, {});
|
||||
|
||||
assert.strictEqual(
|
||||
Object.keys(fyo.schemaMap).length,
|
||||
0,
|
||||
'zero schemas two'
|
||||
);
|
||||
|
||||
await fyo.db.createNewDatabase(':memory:', 'in');
|
||||
await fyo.initializeAndRegister({}, {});
|
||||
assert.strictEqual(
|
||||
Object.keys(fyo.schemaMap).length > 0,
|
||||
true,
|
||||
'non zero schemas'
|
||||
);
|
||||
await fyo.db.purgeCache();
|
||||
});
|
||||
t.equal(Object.keys(fyo.schemaMap).length > 0, true, 'non zero schemas');
|
||||
await fyo.close();
|
||||
});
|
||||
|
||||
describe('Fyo Docs', function () {
|
||||
test('Fyo Docs', async (t) => {
|
||||
const countryCode = 'in';
|
||||
let fyo: Fyo;
|
||||
const fyo = getTestFyo();
|
||||
const schemaMap = getSchemas(countryCode);
|
||||
this.beforeEach(async function () {
|
||||
fyo = new Fyo({
|
||||
DatabaseDemux: DatabaseManager,
|
||||
isTest: true,
|
||||
isElectron: false,
|
||||
});
|
||||
const regionalModels = await getRegionalModels(countryCode);
|
||||
await fyo.db.createNewDatabase(':memory:', countryCode);
|
||||
await fyo.initializeAndRegister(models, regionalModels);
|
||||
|
||||
const regionalModels = await getRegionalModels(countryCode);
|
||||
await fyo.db.createNewDatabase(':memory:', countryCode);
|
||||
await fyo.initializeAndRegister(models, regionalModels);
|
||||
});
|
||||
|
||||
this.afterEach(async function () {
|
||||
await fyo.close();
|
||||
});
|
||||
|
||||
specify('getNewDoc', async function () {
|
||||
for (const schemaName in schemaMap) {
|
||||
const schema = schemaMap[schemaName];
|
||||
if (schema?.isSingle) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const doc = fyo.doc.getNewDoc(schemaName);
|
||||
for (const schemaName in schemaMap) {
|
||||
const schema = schemaMap[schemaName];
|
||||
if (schema?.isSingle) {
|
||||
continue;
|
||||
}
|
||||
});
|
||||
|
||||
const doc = fyo.doc.getNewDoc(schemaName);
|
||||
t.equal(doc.schemaName, schemaName, `equal schemaNames: ${schemaName}`);
|
||||
}
|
||||
|
||||
await fyo.close();
|
||||
});
|
||||
|
@ -1,131 +1,84 @@
|
||||
import * as assert from 'assert';
|
||||
import { strictEqual } from 'assert';
|
||||
import Observable from 'fyo/utils/observable';
|
||||
import 'mocha';
|
||||
import test from 'tape';
|
||||
|
||||
enum ObsEvent {
|
||||
A = 'event-a',
|
||||
B = 'event-b',
|
||||
}
|
||||
|
||||
describe('Observable', function () {
|
||||
const obs = new Observable();
|
||||
let counter = 0;
|
||||
const params = { aOne: 18, aTwo: 21, b: 42 };
|
||||
const obs = new Observable();
|
||||
let counter = 0;
|
||||
const params = { aOne: 18, aTwo: 21, b: 42 };
|
||||
|
||||
const listenerAOnce = (value: number) => {
|
||||
assert.strictEqual(params.aOne, value, 'listenerAOnce');
|
||||
};
|
||||
const listenerAOnce = (value: number) => {
|
||||
strictEqual(params.aOne, value, 'listenerAOnce');
|
||||
};
|
||||
|
||||
const listenerAEvery = (value: number) => {
|
||||
if (counter === 0) {
|
||||
assert.strictEqual(params.aOne, value, 'listenerAEvery 0');
|
||||
} else if (counter === 1) {
|
||||
assert.strictEqual(params.aTwo, value, 'listenerAEvery 1');
|
||||
} else {
|
||||
throw new Error("this shouldn't run");
|
||||
}
|
||||
counter += 1;
|
||||
};
|
||||
const listenerAEvery = (value: number) => {
|
||||
if (counter === 0) {
|
||||
strictEqual(params.aOne, value, 'listenerAEvery 0');
|
||||
} else if (counter === 1) {
|
||||
strictEqual(params.aTwo, value, 'listenerAEvery 1');
|
||||
} else {
|
||||
throw new Error("this shouldn't run");
|
||||
}
|
||||
counter += 1;
|
||||
};
|
||||
|
||||
const listenerBOnce = (value: number) => {
|
||||
assert.strictEqual(params.b, value, 'listenerBOnce');
|
||||
};
|
||||
const listenerBOnce = (value: number) => {
|
||||
strictEqual(params.b, value, 'listenerBOnce');
|
||||
};
|
||||
|
||||
specify('set A One', function () {
|
||||
assert.strictEqual(obs.hasListener(ObsEvent.A), false, 'pre');
|
||||
test('set A One', function (t) {
|
||||
t.equal(obs.hasListener(ObsEvent.A), false, 'pre');
|
||||
|
||||
obs.once(ObsEvent.A, listenerAOnce);
|
||||
assert.strictEqual(obs.hasListener(ObsEvent.A), true, 'non specific');
|
||||
assert.strictEqual(
|
||||
obs.hasListener(ObsEvent.A, listenerAOnce),
|
||||
true,
|
||||
'specific once'
|
||||
);
|
||||
assert.strictEqual(
|
||||
obs.hasListener(ObsEvent.A, listenerAEvery),
|
||||
false,
|
||||
'specific every'
|
||||
);
|
||||
});
|
||||
|
||||
specify('set A Two', function () {
|
||||
obs.on(ObsEvent.A, listenerAEvery);
|
||||
assert.strictEqual(obs.hasListener(ObsEvent.A), true, 'non specific');
|
||||
assert.strictEqual(
|
||||
obs.hasListener(ObsEvent.A, listenerAOnce),
|
||||
true,
|
||||
'specific once'
|
||||
);
|
||||
assert.strictEqual(
|
||||
obs.hasListener(ObsEvent.A, listenerAEvery),
|
||||
true,
|
||||
'specific every'
|
||||
);
|
||||
});
|
||||
|
||||
specify('set B', function () {
|
||||
assert.strictEqual(obs.hasListener(ObsEvent.B), false, 'pre');
|
||||
|
||||
obs.once(ObsEvent.B, listenerBOnce);
|
||||
assert.strictEqual(
|
||||
obs.hasListener(ObsEvent.A, listenerBOnce),
|
||||
false,
|
||||
'specific false'
|
||||
);
|
||||
assert.strictEqual(
|
||||
obs.hasListener(ObsEvent.B, listenerBOnce),
|
||||
true,
|
||||
'specific true'
|
||||
);
|
||||
});
|
||||
|
||||
specify('trigger A 0', async function () {
|
||||
await obs.trigger(ObsEvent.A, params.aOne);
|
||||
assert.strictEqual(obs.hasListener(ObsEvent.A), true, 'non specific');
|
||||
assert.strictEqual(
|
||||
obs.hasListener(ObsEvent.A, listenerAOnce),
|
||||
false,
|
||||
'specific'
|
||||
);
|
||||
});
|
||||
|
||||
specify('trigger A 1', async function () {
|
||||
assert.strictEqual(
|
||||
obs.hasListener(ObsEvent.A, listenerAEvery),
|
||||
true,
|
||||
'specific pre'
|
||||
);
|
||||
await obs.trigger(ObsEvent.A, params.aTwo);
|
||||
assert.strictEqual(
|
||||
obs.hasListener(ObsEvent.A, listenerAEvery),
|
||||
true,
|
||||
'specific post'
|
||||
);
|
||||
});
|
||||
|
||||
specify('trigger B', async function () {
|
||||
assert.strictEqual(
|
||||
obs.hasListener(ObsEvent.B, listenerBOnce),
|
||||
true,
|
||||
'specific pre'
|
||||
);
|
||||
await obs.trigger(ObsEvent.B, params.b);
|
||||
assert.strictEqual(
|
||||
obs.hasListener(ObsEvent.B, listenerBOnce),
|
||||
false,
|
||||
'specific post'
|
||||
);
|
||||
});
|
||||
|
||||
specify('remove A', async function () {
|
||||
obs.off(ObsEvent.A, listenerAEvery);
|
||||
assert.strictEqual(
|
||||
obs.hasListener(ObsEvent.A, listenerAEvery),
|
||||
false,
|
||||
'specific pre'
|
||||
);
|
||||
|
||||
assert.strictEqual(counter, 2, 'incorrect counter');
|
||||
await obs.trigger(ObsEvent.A, 777);
|
||||
});
|
||||
obs.once(ObsEvent.A, listenerAOnce);
|
||||
t.equal(obs.hasListener(ObsEvent.A), true, 'non specific');
|
||||
t.equal(obs.hasListener(ObsEvent.A, listenerAOnce), true, 'specific once');
|
||||
t.equal(obs.hasListener(ObsEvent.A, listenerAEvery), false, 'specific every');
|
||||
t.end()
|
||||
});
|
||||
|
||||
test('set A Two', function (t) {
|
||||
obs.on(ObsEvent.A, listenerAEvery);
|
||||
t.equal(obs.hasListener(ObsEvent.A), true, 'non specific');
|
||||
t.equal(obs.hasListener(ObsEvent.A, listenerAOnce), true, 'specific once');
|
||||
t.equal(obs.hasListener(ObsEvent.A, listenerAEvery), true, 'specific every');
|
||||
t.end()
|
||||
});
|
||||
|
||||
test('set B', function (t) {
|
||||
t.equal(obs.hasListener(ObsEvent.B), false, 'pre');
|
||||
|
||||
obs.once(ObsEvent.B, listenerBOnce);
|
||||
t.equal(obs.hasListener(ObsEvent.A, listenerBOnce), false, 'specific false');
|
||||
t.equal(obs.hasListener(ObsEvent.B, listenerBOnce), true, 'specific true');
|
||||
t.end()
|
||||
});
|
||||
|
||||
test('trigger A 0', async function (t) {
|
||||
await obs.trigger(ObsEvent.A, params.aOne);
|
||||
t.equal(obs.hasListener(ObsEvent.A), true, 'non specific');
|
||||
t.equal(obs.hasListener(ObsEvent.A, listenerAOnce), false, 'specific');
|
||||
});
|
||||
|
||||
test('trigger A 1', async function (t) {
|
||||
t.equal(obs.hasListener(ObsEvent.A, listenerAEvery), true, 'specific pre');
|
||||
await obs.trigger(ObsEvent.A, params.aTwo);
|
||||
t.equal(obs.hasListener(ObsEvent.A, listenerAEvery), true, 'specific post');
|
||||
});
|
||||
|
||||
test('trigger B', async function (t) {
|
||||
t.equal(obs.hasListener(ObsEvent.B, listenerBOnce), true, 'specific pre');
|
||||
await obs.trigger(ObsEvent.B, params.b);
|
||||
t.equal(obs.hasListener(ObsEvent.B, listenerBOnce), false, 'specific post');
|
||||
});
|
||||
|
||||
test('remove A', async function (t) {
|
||||
obs.off(ObsEvent.A, listenerAEvery);
|
||||
t.equal(obs.hasListener(ObsEvent.A, listenerAEvery), false, 'specific pre');
|
||||
|
||||
t.equal(counter, 2, 'incorrect counter');
|
||||
await obs.trigger(ObsEvent.A, 777);
|
||||
});
|
||||
|
@ -17,7 +17,7 @@
|
||||
"electron:serve": "vue-cli-service electron:serve",
|
||||
"script:translate": "scripts/runner.sh scripts/generateTranslations.ts",
|
||||
"script:profile": "scripts/profile.sh",
|
||||
"test": "scripts/runner.sh ./node_modules/.bin/mocha ./**/tests/**/*.spec.ts --exit"
|
||||
"test": "scripts/runner.sh ./node_modules/.bin/tape ./**/tests/**/*.spec.ts | tap-spec"
|
||||
},
|
||||
"dependencies": {
|
||||
"@popperjs/core": "^2.10.2",
|
||||
@ -43,6 +43,7 @@
|
||||
"@types/mocha": "^9.1.0",
|
||||
"@types/node": "^17.0.23",
|
||||
"@types/node-fetch": "^2.6.1",
|
||||
"@types/tape": "^4.13.2",
|
||||
"@typescript-eslint/eslint-plugin": "^4.15.1",
|
||||
"@typescript-eslint/parser": "^4.15.1",
|
||||
"@vue/cli-plugin-babel": "^4.5.0",
|
||||
@ -65,11 +66,12 @@
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"eslint-plugin-vue": "^7.0.0",
|
||||
"lint-staged": "^11.2.6",
|
||||
"mocha": "^9.2.2",
|
||||
"postcss": "^8",
|
||||
"prettier": "^2.4.1",
|
||||
"raw-loader": "^4.0.2",
|
||||
"tailwindcss": "npm:@tailwindcss/postcss7-compat",
|
||||
"tap-spec": "^5.0.0",
|
||||
"tape": "^5.6.1",
|
||||
"ts-node": "^10.7.0",
|
||||
"tsconfig-paths": "^3.14.1",
|
||||
"tslib": "^2.3.1",
|
||||
|
@ -1,224 +1,212 @@
|
||||
import * as assert from 'assert';
|
||||
import { cloneDeep, isEqual } from 'lodash';
|
||||
import { describe } from 'mocha';
|
||||
import test from 'tape';
|
||||
import { getMapFromList } from 'utils';
|
||||
import {
|
||||
addMetaFields,
|
||||
cleanSchemas,
|
||||
getAbstractCombinedSchemas,
|
||||
getRegionalCombinedSchemas,
|
||||
setSchemaNameOnFields,
|
||||
setSchemaNameOnFields
|
||||
} from '../index';
|
||||
import { metaSchemas } from '../schemas';
|
||||
import {
|
||||
everyFieldExists,
|
||||
getTestSchemaMap,
|
||||
someFieldExists,
|
||||
subtract,
|
||||
subtract
|
||||
} from './helpers';
|
||||
|
||||
describe('Schema Builder', function () {
|
||||
const { appSchemaMap, regionalSchemaMap } = getTestSchemaMap();
|
||||
describe('Raw Schemas', function () {
|
||||
specify('Meta Properties', function () {
|
||||
assert.strictEqual(appSchemaMap.Party.isAbstract, true);
|
||||
assert.strictEqual(appSchemaMap.Customer.extends, 'Party');
|
||||
assert.strictEqual(appSchemaMap.Account.isTree, true);
|
||||
assert.strictEqual(appSchemaMap.JournalEntryAccount.isChild, true);
|
||||
});
|
||||
|
||||
specify('Field Counts', function () {
|
||||
assert.strictEqual(appSchemaMap.Account.fields?.length, 6);
|
||||
assert.strictEqual(appSchemaMap.JournalEntry.fields?.length, 9);
|
||||
assert.strictEqual(appSchemaMap.JournalEntryAccount.fields?.length, 3);
|
||||
assert.strictEqual(appSchemaMap.Party.fields?.length, 9);
|
||||
assert.strictEqual(appSchemaMap.Customer.fields?.length, undefined);
|
||||
assert.strictEqual(regionalSchemaMap.Party.fields?.length, 2);
|
||||
});
|
||||
|
||||
specify('Quick Edit Field Counts', function () {
|
||||
assert.strictEqual(appSchemaMap.Party.quickEditFields?.length, 5);
|
||||
assert.strictEqual(regionalSchemaMap.Party.quickEditFields?.length, 8);
|
||||
});
|
||||
});
|
||||
|
||||
const regionalCombined = getRegionalCombinedSchemas(
|
||||
appSchemaMap,
|
||||
regionalSchemaMap
|
||||
);
|
||||
describe('Regional Combined Schemas', function () {
|
||||
specify('Field Counts', function () {
|
||||
assert.strictEqual(regionalCombined.Party.fields?.length, 11);
|
||||
});
|
||||
|
||||
specify('Quick Edit Field Counts', function () {
|
||||
assert.strictEqual(regionalSchemaMap.Party.quickEditFields?.length, 8);
|
||||
});
|
||||
|
||||
specify('Schema Equality with App Schemas', function () {
|
||||
assert.strictEqual(
|
||||
isEqual(regionalCombined.Account, appSchemaMap.Account),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
isEqual(regionalCombined.JournalEntry, appSchemaMap.JournalEntry),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
isEqual(
|
||||
regionalCombined.JournalEntryAccount,
|
||||
appSchemaMap.JournalEntryAccount
|
||||
),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
isEqual(regionalCombined.Customer, appSchemaMap.Customer),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
isEqual(regionalCombined.Party, appSchemaMap.Party),
|
||||
false
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
const abstractCombined = cleanSchemas(
|
||||
getAbstractCombinedSchemas(regionalCombined)
|
||||
);
|
||||
describe('Abstract Combined Schemas', function () {
|
||||
specify('Meta Properties', function () {
|
||||
assert.strictEqual(abstractCombined.Customer!.extends, undefined);
|
||||
});
|
||||
|
||||
specify('Abstract Schema Existance', function () {
|
||||
assert.strictEqual(abstractCombined.Party, undefined);
|
||||
});
|
||||
|
||||
specify('Field Counts', function () {
|
||||
assert.strictEqual(abstractCombined.Customer!.fields?.length, 11);
|
||||
});
|
||||
|
||||
specify('Quick Edit Field Counts', function () {
|
||||
assert.strictEqual(abstractCombined.Customer!.quickEditFields?.length, 8);
|
||||
});
|
||||
|
||||
specify('Schema Equality with App Schemas', function () {
|
||||
assert.strictEqual(
|
||||
isEqual(abstractCombined.Account, appSchemaMap.Account),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
isEqual(abstractCombined.JournalEntry, appSchemaMap.JournalEntry),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
isEqual(
|
||||
abstractCombined.JournalEntryAccount,
|
||||
appSchemaMap.JournalEntryAccount
|
||||
),
|
||||
true
|
||||
);
|
||||
assert.strictEqual(
|
||||
isEqual(abstractCombined.Customer, appSchemaMap.Customer),
|
||||
false
|
||||
);
|
||||
});
|
||||
|
||||
specify('Schema Field Existance', function () {
|
||||
assert.strictEqual(
|
||||
everyFieldExists(
|
||||
regionalSchemaMap.Party.quickEditFields ?? [],
|
||||
abstractCombined.Customer!
|
||||
),
|
||||
true
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
let almostFinalSchemas = cloneDeep(abstractCombined);
|
||||
almostFinalSchemas = addMetaFields(almostFinalSchemas);
|
||||
const finalSchemas = setSchemaNameOnFields(almostFinalSchemas);
|
||||
const metaSchemaMap = getMapFromList(metaSchemas, 'name');
|
||||
const baseFieldNames = metaSchemaMap.base.fields!.map((f) => f.fieldname);
|
||||
const childFieldNames = metaSchemaMap.child.fields!.map((f) => f.fieldname);
|
||||
const treeFieldNames = metaSchemaMap.tree.fields!.map((f) => f.fieldname);
|
||||
const submittableFieldNames = metaSchemaMap.submittable.fields!.map(
|
||||
(f) => f.fieldname
|
||||
);
|
||||
const allFieldNames = [
|
||||
...baseFieldNames,
|
||||
...childFieldNames,
|
||||
...treeFieldNames,
|
||||
...submittableFieldNames,
|
||||
];
|
||||
|
||||
describe('Final Schemas', function () {
|
||||
specify('Schema Name Existsance', function () {
|
||||
for (const schemaName in finalSchemas) {
|
||||
for (const field of finalSchemas[schemaName]?.fields!) {
|
||||
assert.strictEqual(field.schemaName, schemaName);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
specify('Schema Field Existance', function () {
|
||||
assert.strictEqual(
|
||||
everyFieldExists(baseFieldNames, finalSchemas.Customer!),
|
||||
true
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
someFieldExists(
|
||||
subtract(allFieldNames, baseFieldNames),
|
||||
finalSchemas.Customer!
|
||||
),
|
||||
false
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
everyFieldExists(
|
||||
[...baseFieldNames, ...submittableFieldNames],
|
||||
finalSchemas.JournalEntry!
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
someFieldExists(
|
||||
subtract(allFieldNames, baseFieldNames, submittableFieldNames),
|
||||
finalSchemas.JournalEntry!
|
||||
),
|
||||
false
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
everyFieldExists(childFieldNames, finalSchemas.JournalEntryAccount!),
|
||||
true
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
someFieldExists(
|
||||
subtract(allFieldNames, childFieldNames),
|
||||
finalSchemas.JournalEntryAccount!
|
||||
),
|
||||
false
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
everyFieldExists(
|
||||
[...treeFieldNames, ...baseFieldNames],
|
||||
finalSchemas.Account!
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
someFieldExists(
|
||||
subtract(allFieldNames, treeFieldNames, baseFieldNames),
|
||||
finalSchemas.Account!
|
||||
),
|
||||
false
|
||||
);
|
||||
});
|
||||
});
|
||||
const { appSchemaMap, regionalSchemaMap } = getTestSchemaMap();
|
||||
test('Meta Properties', function (t) {
|
||||
t.equal(appSchemaMap.Party.isAbstract, true);
|
||||
t.equal(appSchemaMap.Customer.extends, 'Party');
|
||||
t.equal(appSchemaMap.Account.isTree, true);
|
||||
t.equal(appSchemaMap.JournalEntryAccount.isChild, true);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Field Counts', function (t) {
|
||||
t.equal(appSchemaMap.Account.fields?.length, 6);
|
||||
t.equal(appSchemaMap.JournalEntry.fields?.length, 9);
|
||||
t.equal(appSchemaMap.JournalEntryAccount.fields?.length, 3);
|
||||
t.equal(appSchemaMap.Party.fields?.length, 9);
|
||||
t.equal(appSchemaMap.Customer.fields?.length, undefined);
|
||||
t.equal(regionalSchemaMap.Party.fields?.length, 2);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Quick Edit Field Counts', function (t) {
|
||||
t.equal(appSchemaMap.Party.quickEditFields?.length, 5);
|
||||
t.equal(regionalSchemaMap.Party.quickEditFields?.length, 8);
|
||||
t.end();
|
||||
});
|
||||
|
||||
const regionalCombined = getRegionalCombinedSchemas(
|
||||
appSchemaMap,
|
||||
regionalSchemaMap
|
||||
);
|
||||
|
||||
test('Field Counts', function (t) {
|
||||
t.equal(regionalCombined.Party.fields?.length, 11);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Quick Edit Field Counts', function (t) {
|
||||
t.equal(regionalSchemaMap.Party.quickEditFields?.length, 8);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Schema Equality with App Schemas', function (t) {
|
||||
t.equal(isEqual(regionalCombined.Account, appSchemaMap.Account), true);
|
||||
t.equal(
|
||||
isEqual(regionalCombined.JournalEntry, appSchemaMap.JournalEntry),
|
||||
true
|
||||
);
|
||||
t.equal(
|
||||
isEqual(
|
||||
regionalCombined.JournalEntryAccount,
|
||||
appSchemaMap.JournalEntryAccount
|
||||
),
|
||||
true
|
||||
);
|
||||
t.equal(isEqual(regionalCombined.Customer, appSchemaMap.Customer), true);
|
||||
t.equal(isEqual(regionalCombined.Party, appSchemaMap.Party), false);
|
||||
t.end();
|
||||
});
|
||||
|
||||
const abstractCombined = cleanSchemas(
|
||||
getAbstractCombinedSchemas(regionalCombined)
|
||||
);
|
||||
|
||||
test('Meta Properties', function (t) {
|
||||
t.equal(abstractCombined.Customer!.extends, undefined);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Abstract Schema Existance', function (t) {
|
||||
t.equal(abstractCombined.Party, undefined);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Field Counts', function (t) {
|
||||
t.equal(abstractCombined.Customer!.fields?.length, 11);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Quick Edit Field Counts', function (t) {
|
||||
t.equal(abstractCombined.Customer!.quickEditFields?.length, 8);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Schema Equality with App Schemas', function (t) {
|
||||
t.equal(isEqual(abstractCombined.Account, appSchemaMap.Account), true);
|
||||
t.equal(
|
||||
isEqual(abstractCombined.JournalEntry, appSchemaMap.JournalEntry),
|
||||
true
|
||||
);
|
||||
t.equal(
|
||||
isEqual(
|
||||
abstractCombined.JournalEntryAccount,
|
||||
appSchemaMap.JournalEntryAccount
|
||||
),
|
||||
true
|
||||
);
|
||||
t.equal(isEqual(abstractCombined.Customer, appSchemaMap.Customer), false);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Schema Field Existance', function (t) {
|
||||
t.equal(
|
||||
everyFieldExists(
|
||||
regionalSchemaMap.Party.quickEditFields ?? [],
|
||||
abstractCombined.Customer!
|
||||
),
|
||||
true
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
let almostFinalSchemas = cloneDeep(abstractCombined);
|
||||
almostFinalSchemas = addMetaFields(almostFinalSchemas);
|
||||
const finalSchemas = setSchemaNameOnFields(almostFinalSchemas);
|
||||
const metaSchemaMap = getMapFromList(metaSchemas, 'name');
|
||||
const baseFieldNames = metaSchemaMap.base.fields!.map((f) => f.fieldname);
|
||||
const childFieldNames = metaSchemaMap.child.fields!.map((f) => f.fieldname);
|
||||
const treeFieldNames = metaSchemaMap.tree.fields!.map((f) => f.fieldname);
|
||||
const submittableFieldNames = metaSchemaMap.submittable.fields!.map(
|
||||
(f) => f.fieldname
|
||||
);
|
||||
const allFieldNames = [
|
||||
...baseFieldNames,
|
||||
...childFieldNames,
|
||||
...treeFieldNames,
|
||||
...submittableFieldNames,
|
||||
];
|
||||
|
||||
test('Schema Name Existsance', function (t) {
|
||||
for (const schemaName in finalSchemas) {
|
||||
for (const field of finalSchemas[schemaName]?.fields!) {
|
||||
t.equal(field.schemaName, schemaName);
|
||||
}
|
||||
}
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Schema Field Existance', function (t) {
|
||||
t.equal(everyFieldExists(baseFieldNames, finalSchemas.Customer!), true);
|
||||
|
||||
t.equal(
|
||||
someFieldExists(
|
||||
subtract(allFieldNames, baseFieldNames),
|
||||
finalSchemas.Customer!
|
||||
),
|
||||
false
|
||||
);
|
||||
|
||||
t.equal(
|
||||
everyFieldExists(
|
||||
[...baseFieldNames, ...submittableFieldNames],
|
||||
finalSchemas.JournalEntry!
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
t.equal(
|
||||
someFieldExists(
|
||||
subtract(allFieldNames, baseFieldNames, submittableFieldNames),
|
||||
finalSchemas.JournalEntry!
|
||||
),
|
||||
false
|
||||
);
|
||||
|
||||
t.equal(
|
||||
everyFieldExists(childFieldNames, finalSchemas.JournalEntryAccount!),
|
||||
true
|
||||
);
|
||||
|
||||
t.equal(
|
||||
someFieldExists(
|
||||
subtract(allFieldNames, childFieldNames),
|
||||
finalSchemas.JournalEntryAccount!
|
||||
),
|
||||
false
|
||||
);
|
||||
|
||||
t.equal(
|
||||
everyFieldExists(
|
||||
[...treeFieldNames, ...baseFieldNames],
|
||||
finalSchemas.Account!
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
t.equal(
|
||||
someFieldExists(
|
||||
subtract(allFieldNames, treeFieldNames, baseFieldNames),
|
||||
finalSchemas.Account!
|
||||
),
|
||||
false
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
@ -1,4 +1,7 @@
|
||||
import { DatabaseManager } from 'backend/database/manager';
|
||||
import { config } from 'dotenv';
|
||||
import { Fyo } from 'fyo';
|
||||
import { DummyAuthDemux } from 'fyo/tests/helpers';
|
||||
import { SetupWizardOptions } from 'src/setup/types';
|
||||
import { getFiscalYear } from 'utils/misc';
|
||||
|
||||
@ -21,3 +24,12 @@ export function getTestDbPath(dbPath?: string) {
|
||||
config();
|
||||
return dbPath ?? process.env.TEST_DB_PATH ?? ':memory:';
|
||||
}
|
||||
|
||||
export function getTestFyo(): Fyo {
|
||||
return new Fyo({
|
||||
DatabaseDemux: DatabaseManager,
|
||||
AuthDemux: DummyAuthDemux,
|
||||
isTest: true,
|
||||
isElectron: false,
|
||||
});
|
||||
}
|
||||
|
@ -1,78 +1,66 @@
|
||||
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';
|
||||
import { SetupWizardOptions } from 'src/setup/types';
|
||||
import test from 'tape';
|
||||
import { getValueMapFromList } from 'utils';
|
||||
import { getTestDbPath, getTestSetupWizardOptions } from './helpers';
|
||||
import {
|
||||
getTestDbPath,
|
||||
getTestFyo,
|
||||
getTestSetupWizardOptions
|
||||
} from './helpers';
|
||||
|
||||
describe('setupInstance', function () {
|
||||
const dbPath = getTestDbPath();
|
||||
const setupOptions = getTestSetupWizardOptions();
|
||||
const dbPath = getTestDbPath();
|
||||
const setupOptions = getTestSetupWizardOptions();
|
||||
const fyo = getTestFyo();
|
||||
|
||||
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 () => {
|
||||
await setupInstance(dbPath, setupOptions, fyo);
|
||||
}, 'setup instance failed');
|
||||
});
|
||||
|
||||
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})`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
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)}`
|
||||
);
|
||||
});
|
||||
test('setupInstance', async () => {
|
||||
await assertDoesNotThrow(async () => {
|
||||
await setupInstance(dbPath, setupOptions, fyo);
|
||||
}, 'setup instance failed');
|
||||
});
|
||||
|
||||
test('check setup Singles', async (t) => {
|
||||
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];
|
||||
}
|
||||
|
||||
t.equal(
|
||||
dbValue as string,
|
||||
optionsValue,
|
||||
`${field}: (${dbValue}, ${optionsValue})`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('check null singles', async (t) => {
|
||||
const nullFields = ['gstin', 'logo', 'phone', 'address'];
|
||||
const nullSingles = await fyo.db.getSingleValues(...nullFields);
|
||||
|
||||
t.equal(
|
||||
nullSingles.length,
|
||||
0,
|
||||
`null singles: ${JSON.stringify(nullSingles)}`
|
||||
);
|
||||
});
|
||||
|
||||
test.onFinish(async () => {
|
||||
await fyo.close();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user