Files
openstapps/test/index.spec.ts
2019-02-07 16:13:11 +01:00

52 lines
1.7 KiB
TypeScript

/*
* 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.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* 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 {SCThings} from '@openstapps/core';
import {Validator} from '@openstapps/core-tools/lib/validate';
import {expect} from 'chai';
import {suite, test} from 'mocha-typescript';
import {MinimalConnector} from '../src';
@suite
export class MinimalConnectorSpec {
private static connector: MinimalConnector;
private static validator: Validator;
static async before() {
this.validator = new Validator();
await this.validator.addSchemas('./node_modules/@openstapps/core/lib/schema');
this.connector = new MinimalConnector();
}
static validateThings(things: SCThings[]) {
things.forEach((thing: SCThings) => {
// validate thing
expect(MinimalConnectorSpec.validator.validateThing(thing).errors).to.have.lengthOf(0, JSON.stringify({
errors: MinimalConnectorSpec.validator.validateThing(thing).errors,
thing: thing,
}));
});
}
@test
getSampleThings() {
return MinimalConnectorSpec.connector.getItems().then(<T extends SCThings>(items: T[]) => {
if (items.length > 0) {
MinimalConnectorSpec.validateThings(items);
}
});
}
}