refactor: provide a generic test class

This commit is contained in:
Michel Jonathan Schmitz
2019-02-07 16:13:11 +01:00
parent 87f812c857
commit 15ae7e5bd8
5 changed files with 26 additions and 13 deletions

19
package-lock.json generated
View File

@@ -161,6 +161,19 @@
"moment": "2.24.0", "moment": "2.24.0",
"request": "2.88.0", "request": "2.88.0",
"uuid": "3.3.2" "uuid": "3.3.2"
},
"dependencies": {
"@openstapps/core": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/@openstapps/core/-/core-0.3.0.tgz",
"integrity": "sha512-ljGYPWXiG4JMV2ZaJQmYK6hQbiXlRPAZwYzcMBTI5m/9Y6tXudawiCDP8EFcZj6OXCQ2tnkEP7Bhwic7flu2Eg==",
"requires": {
"@types/geojson": "1.0.6",
"@types/json-patch": "0.0.30",
"json-patch": "0.7.0",
"jsonschema": "1.2.4"
}
}
} }
}, },
"@openstapps/configuration": { "@openstapps/configuration": {
@@ -215,9 +228,9 @@
} }
}, },
"@openstapps/core-tools": { "@openstapps/core-tools": {
"version": "0.2.0", "version": "0.3.0",
"resolved": "https://registry.npmjs.org/@openstapps/core-tools/-/core-tools-0.2.0.tgz", "resolved": "https://registry.npmjs.org/@openstapps/core-tools/-/core-tools-0.3.0.tgz",
"integrity": "sha512-sDRibFLdJP0K2eLx8wNHVYjizwKP2t5iZpnsBQGnybppAjOPXlDPwdJuDi6OGo0A0QSW/eiqdnDmAGnlh0a32Q==", "integrity": "sha512-8swLstFYUsbFQ0FfdSp1YTVIMYrspPYllh/DnviEpNlZcoa9o3QAxdJr/B8K8YdI06SEvmqyt5uHNw5d7noOlw==",
"dev": true, "dev": true,
"requires": { "requires": {
"@openstapps/logger": "0.0.3", "@openstapps/logger": "0.0.3",

View File

@@ -34,7 +34,7 @@
}, },
"devDependencies": { "devDependencies": {
"@openstapps/configuration": "0.5.1", "@openstapps/configuration": "0.5.1",
"@openstapps/core-tools": "0.2.0", "@openstapps/core-tools": "0.3.0",
"@types/chai": "4.1.7", "@types/chai": "4.1.7",
"@types/mocha": "5.2.5", "@types/mocha": "5.2.5",
"@types/node": "10.12.18", "@types/node": "10.12.18",

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018 StApps * Copyright (C) 2018-2019 StApps
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free * under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3. * Software Foundation, version 3.

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018 StApps * Copyright (C) 2018-2019 StApps
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free * under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3. * Software Foundation, version 3.

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018 StApps * Copyright (C) 2018-2019 StApps
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free * under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3. * Software Foundation, version 3.
@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import {SCMessage} from '@openstapps/core'; import {SCThings} from '@openstapps/core';
import {Validator} from '@openstapps/core-tools/lib/validate'; import {Validator} from '@openstapps/core-tools/lib/validate';
import {expect} from 'chai'; import {expect} from 'chai';
import {suite, test} from 'mocha-typescript'; import {suite, test} from 'mocha-typescript';
@@ -30,11 +30,11 @@ export class MinimalConnectorSpec {
this.connector = new MinimalConnector(); this.connector = new MinimalConnector();
} }
static validateThings(things: SCMessage[]) { static validateThings(things: SCThings[]) {
things.forEach((thing: SCMessage) => { things.forEach((thing: SCThings) => {
// validate thing // validate thing
expect(MinimalConnectorSpec.validator.validate(thing,'SCMessage').errors).to.have.lengthOf(0, JSON.stringify({ expect(MinimalConnectorSpec.validator.validateThing(thing).errors).to.have.lengthOf(0, JSON.stringify({
errors: MinimalConnectorSpec.validator.validate(thing,'SCMessage').errors, errors: MinimalConnectorSpec.validator.validateThing(thing).errors,
thing: thing, thing: thing,
})); }));
}); });
@@ -42,7 +42,7 @@ export class MinimalConnectorSpec {
@test @test
getSampleThings() { getSampleThings() {
return MinimalConnectorSpec.connector.getItems().then(<T extends SCMessage>(items: T[]) => { return MinimalConnectorSpec.connector.getItems().then(<T extends SCThings>(items: T[]) => {
if (items.length > 0) { if (items.length > 0) {
MinimalConnectorSpec.validateThings(items); MinimalConnectorSpec.validateThings(items);
} }