-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
137 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Throw errors when null is not allowed as value | ||
|
||
/* global describe, it */ | ||
|
||
const { Record } = require('../../src/core/record'); | ||
const { FunctionDef } = require('../../src/core/function-def'); | ||
const { UnitDef } = require('../../src/core/unit-def'); | ||
const { expect } = require('chai'); | ||
|
||
describe('Unit tests for wrong null properties.', () => { | ||
it('Set null for aux subproperties', () => { | ||
let rec = (new Record).merge({ | ||
aux: {a: 1, b: 2, c: null} | ||
}); | ||
rec._id = 'x1'; | ||
|
||
// in current version of API is hard to check if there are errors at validation | ||
// we use only checking of empty aux | ||
expect(rec.aux).to.be.deep.equal({}); | ||
}); | ||
|
||
it('Set null for tags', () => { | ||
let rec = (new Record).merge({ | ||
tags: ['eee', 'ttt', null] | ||
}); | ||
rec._id = 'x1'; | ||
|
||
// this is also result of error in validation | ||
expect(rec.tags).to.be.deep.equal([]); | ||
}); | ||
|
||
it('Cannot set null for math FunctionDef', () => { | ||
let fd = new FunctionDef({ | ||
id: 'f1', | ||
math: null | ||
}); | ||
|
||
expect(fd.errored).to.be.true; | ||
}); | ||
|
||
it('Cannot set null for arguments FunctionDef 1', () => { | ||
let fd = new FunctionDef({ | ||
id: 'f1', | ||
arguments: null, | ||
math: '15' | ||
}); | ||
|
||
expect(fd.errored).to.be.true; | ||
}); | ||
|
||
it('Cannot set null for arguments FunctionDef 2', () => { | ||
let fd = new FunctionDef({ | ||
id: 'f1', | ||
arguments: [null, 'x1', 'x2'], | ||
math: 'x1 + x2' | ||
}); | ||
|
||
expect(fd.errored).to.be.true; | ||
}); | ||
|
||
it('Cannot set null for units UnitDef', () => { | ||
let ud = new UnitDef({ | ||
id: 'u1', | ||
units: null | ||
}); | ||
|
||
expect(ud.errored).to.be.true; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// test creation of components with properties set with null | ||
|
||
/* global describe, it */ | ||
const { Record } = require('../../src/core/record'); | ||
const { expect } = require('chai'); | ||
|
||
describe('Unit tests for null properties.', () => { | ||
it('Set all null properties', () => { | ||
let rec = (new Record).merge({ | ||
title: null, | ||
notes: null, | ||
assignments: {start_: null, ode_: null, xxx: null}, | ||
tags: null, | ||
aux: null | ||
}); | ||
rec._id = 'x1'; | ||
|
||
expect(rec.toQ()).to.be.deep.equal({ | ||
class: 'Record', | ||
id: 'x1', | ||
assignments: {} | ||
}); | ||
}); | ||
|
||
it('Set all properties, than delete by null', () => { | ||
let rec = (new Record).merge({ | ||
title: 'Title', | ||
notes: 'Notes', | ||
units: 'mm', | ||
assignments: {start_: 'start', ode_: 'ode', xxx: 'xxx'}, | ||
tags: ['tag1', 'tag2'], | ||
aux: {a: 1, b: 2} | ||
}); | ||
rec._id = 'x1'; | ||
|
||
rec.merge({ | ||
title: null, | ||
notes: null, | ||
units: null, | ||
assignments: {start_: null, ode_: null, xxx: null}, | ||
tags: null, | ||
aux: null | ||
}); | ||
|
||
expect(rec.toQ()).to.be.deep.equal({ | ||
class: 'Record', | ||
id: 'x1', | ||
assignments: {} | ||
}); | ||
}); | ||
}); |