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