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

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
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with
* 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 {expect} from 'chai';
import {suite, test} from 'mocha-typescript';
@@ -30,11 +30,11 @@ export class MinimalConnectorSpec {
this.connector = new MinimalConnector();
}
static validateThings(things: SCMessage[]) {
things.forEach((thing: SCMessage) => {
static validateThings(things: SCThings[]) {
things.forEach((thing: SCThings) => {
// validate thing
expect(MinimalConnectorSpec.validator.validate(thing,'SCMessage').errors).to.have.lengthOf(0, JSON.stringify({
errors: MinimalConnectorSpec.validator.validate(thing,'SCMessage').errors,
expect(MinimalConnectorSpec.validator.validateThing(thing).errors).to.have.lengthOf(0, JSON.stringify({
errors: MinimalConnectorSpec.validator.validateThing(thing).errors,
thing: thing,
}));
});
@@ -42,7 +42,7 @@ export class MinimalConnectorSpec {
@test
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) {
MinimalConnectorSpec.validateThings(items);
}