feat: tests

This commit is contained in:
2023-04-21 12:08:35 +02:00
parent 8cb9285462
commit d8c79256c9
140 changed files with 2100 additions and 2693 deletions

View File

@@ -16,10 +16,7 @@ import {SCPluginRegisterRequest, SCPluginRegisterResponse, SCPluginRegisterRoute
import chai from 'chai';
import {expect} from 'chai';
import chaiSpies from 'chai-spies';
import {suite, test, timeout} from '@testdeck/mocha';
import {HttpClient} from '../src/http-client.js';
import {HttpClientResponse} from '../src/http-client-interface.js';
import {PluginClient} from '../src/plugin-client.js';
import {HttpClient, HttpClientResponse, PluginClient} from '../src/index.js';
import {TestPlugin} from './plugin-resources/test-plugin.js';
chai.use(chaiSpies);
@@ -27,21 +24,16 @@ chai.use(chaiSpies);
const sandbox = chai.spy.sandbox();
const httpClient = new HttpClient();
const pluginRegisterRoute = new SCPluginRegisterRoute();
const pluginClient = new PluginClient(httpClient, 'http://localhost');
@suite(timeout(10000))
export class PluginClientSpec {
static plugin: TestPlugin;
describe('PluginClient', function () {
this.timeout(10_000);
static async after() {
await this.plugin.close();
}
let plugin: TestPlugin;
static async before() {
this.plugin = new TestPlugin(
beforeEach(async function () {
plugin = new TestPlugin(
4000,
'',
'',
@@ -51,19 +43,19 @@ export class PluginClientSpec {
getSchema: () => {
/***/
},
} as any,
} as never,
'',
'',
'',
);
}
});
async after() {
afterEach(async function () {
await plugin.close();
sandbox.restore();
}
});
@test
async registerPlugin() {
it('should register the plugin', async function () {
sandbox.on(httpClient, 'request', async (): Promise<HttpClientResponse<SCPluginRegisterResponse>> => {
return {
body: {
@@ -76,16 +68,16 @@ export class PluginClientSpec {
expect(httpClient.request).not.to.have.been.called();
await pluginClient.registerPlugin(PluginClientSpec.plugin);
await pluginClient.registerPlugin(plugin);
const request: SCPluginRegisterRequest = {
action: 'add',
plugin: {
address: PluginClientSpec.plugin.fullUrl,
name: PluginClientSpec.plugin.name,
requestSchema: PluginClientSpec.plugin.requestSchema,
responseSchema: PluginClientSpec.plugin.responseSchema,
route: PluginClientSpec.plugin.route,
address: plugin.fullUrl,
name: plugin.name,
requestSchema: plugin.requestSchema,
responseSchema: plugin.responseSchema,
route: plugin.route,
},
};
@@ -97,10 +89,9 @@ export class PluginClientSpec {
method: pluginRegisterRoute.method,
url: new URL(`http://localhost${pluginRegisterRoute.getUrlPath()}`),
});
}
});
@test
async unregisterPlugin() {
it('should unregister the plugin', async function () {
sandbox.on(httpClient, 'request', async (): Promise<HttpClientResponse<SCPluginRegisterResponse>> => {
return {
body: {
@@ -113,11 +104,11 @@ export class PluginClientSpec {
expect(httpClient.request).not.to.have.been.called();
await pluginClient.unregisterPlugin(PluginClientSpec.plugin);
await pluginClient.unregisterPlugin(plugin);
const request: SCPluginRegisterRequest = {
action: 'remove',
route: PluginClientSpec.plugin.route,
route: plugin.route,
};
expect(httpClient.request).to.have.been.first.called.with({
@@ -128,5 +119,5 @@ export class PluginClientSpec {
method: pluginRegisterRoute.method,
url: new URL(`http://localhost${pluginRegisterRoute.getUrlPath()}`),
});
}
}
});
});