mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-08 22:42:54 +00:00
test: add test for fixed side effects
This commit is contained in:
@@ -32,6 +32,7 @@ import * as chai from 'chai';
|
|||||||
import {expect} from 'chai';
|
import {expect} from 'chai';
|
||||||
import * as chaiAsPromised from 'chai-as-promised';
|
import * as chaiAsPromised from 'chai-as-promised';
|
||||||
import * as chaiSpies from 'chai-spies';
|
import * as chaiSpies from 'chai-spies';
|
||||||
|
import clone = require('fast-clone');
|
||||||
import {readdir, readFile} from 'fs';
|
import {readdir, readFile} from 'fs';
|
||||||
import {suite, test} from 'mocha-typescript';
|
import {suite, test} from 'mocha-typescript';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
@@ -66,7 +67,7 @@ const httpClient = new HttpClient();
|
|||||||
*/
|
*/
|
||||||
function doesContainThings<T extends SCThingWithoutReferences>(thing: T): boolean {
|
function doesContainThings<T extends SCThingWithoutReferences>(thing: T): boolean {
|
||||||
/* tslint:disable-next-line:only-arrow-functions */
|
/* tslint:disable-next-line:only-arrow-functions */
|
||||||
return traverse(thing).reduce(function(sum, item) {
|
return traverse(thing).reduce(function (sum, item) {
|
||||||
if (this.isRoot) {
|
if (this.isRoot) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -348,16 +349,30 @@ export class ConnectorClientSpec {
|
|||||||
const testInstances = await asyncPool(5, testFiles, async (testFile) => {
|
const testInstances = await asyncPool(5, testFiles, async (testFile) => {
|
||||||
const buffer = await readFilePromisified(join(pathToTestFiles, testFile));
|
const buffer = await readFilePromisified(join(pathToTestFiles, testFile));
|
||||||
const content = JSON.parse(buffer.toString());
|
const content = JSON.parse(buffer.toString());
|
||||||
|
|
||||||
return content.instance;
|
return content.instance;
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const testInstance of testInstances) {
|
for (const testInstance of testInstances) {
|
||||||
|
|
||||||
|
const checkInstance = clone(testInstance);
|
||||||
const testInstanceWithoutReferences = ConnectorClient.removeReferences(testInstance);
|
const testInstanceWithoutReferences = ConnectorClient.removeReferences(testInstance);
|
||||||
expect(doesContainThings(testInstanceWithoutReferences)).to.be.equal(false, JSON.stringify(
|
|
||||||
[testInstance, testInstanceWithoutReferences],
|
expect(doesContainThings(testInstanceWithoutReferences)).to.be
|
||||||
null,
|
.equal(false, JSON.stringify(
|
||||||
2,
|
[testInstance, testInstanceWithoutReferences],
|
||||||
));
|
null,
|
||||||
|
2,
|
||||||
|
));
|
||||||
|
expect((testInstanceWithoutReferences as any).origin).to.be
|
||||||
|
.equal(undefined, JSON.stringify(
|
||||||
|
[testInstance, testInstanceWithoutReferences],
|
||||||
|
null,
|
||||||
|
2,
|
||||||
|
));
|
||||||
|
expect(testInstance).to.be.deep
|
||||||
|
.equal(checkInstance,
|
||||||
|
'Removing the references of a thing could have side effects because no deep copy is used');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user