refactor: include latest changes from core#145

This commit is contained in:
Rainer Killinger
2022-01-21 15:30:23 +01:00
parent 482dec345c
commit 9d8fe643a5
13 changed files with 316 additions and 260 deletions

View File

@@ -20,7 +20,7 @@ import {
SCPluginRemove, SCValidationErrorResponse,
} from '@openstapps/core';
import nock from 'nock';
import {plugins} from '../../src/common';
import {configFile, plugins} from '../../src/common';
import {pluginRegisterHandler} from '../../src/routes/plugin-register-route';
import {expect, use} from 'chai';
import chaiAsPromised from 'chai-as-promised';
@@ -45,13 +45,16 @@ describe('Plugin registration', async function () {
after(function () {
// remove plugins
plugins.clear();
configFile.app.features = {};
});
it('should register a plugin', async function () {
// register one plugin
const response = await pluginRegisterHandler(registerAddRequest, {});
expect(response).to.deep.equal(bodySuccess) && expect(plugins.size).to.equal(1);
expect(response).to.deep.equal(bodySuccess)
&& expect(plugins.size).to.equal(1)
&& expect(configFile.app.features.plugins!['Foo Plugin']).to.not.be.empty;
});
it('should allow re-registering the same plugin', async function () {
@@ -62,7 +65,8 @@ describe('Plugin registration', async function () {
const response = await pluginRegisterHandler(registerAddRequest, {});
return expect(response).to.deep.equal(bodySuccess)
&& expect(plugins.size).to.equal(1);
&& expect(plugins.size).to.equal(1)
&& expect(configFile.app.features.plugins!['Foo Plugin']).to.not.be.empty;
});
it('should show an error if a plugin has already been registered', async function () {
@@ -92,7 +96,8 @@ describe('Plugin registration', async function () {
const response = await pluginRegisterHandler(registerRemoveRequest, {});
expect(response).to.deep.equal(bodySuccess)
&& expect(plugins.size).to.equal(0);
&& expect(plugins.size).to.equal(0)
&& expect(configFile.app.features.plugins).to.be.empty;
});
it('should throw a "not found" error when removing a plugin whose registered route does not exist', async function () {
@@ -140,7 +145,7 @@ describe('Plugin registration', async function () {
it('should respond with bad request if when providing invalid request', async function () {
const {status} = await testApp
.post(pluginRegisterRoute.urlFragment)
.post(pluginRegisterRoute.urlPath)
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
.send({foo: 'bar'});
@@ -155,7 +160,7 @@ describe('Plugin registration', async function () {
const registerAddRequestAltered = {...registerAddRequest, plugin: {...registerAddRequest.plugin, name: 'FooBar Plugin'}};
const {status, body} = await testApp
.post(pluginRegisterRoute.urlFragment)
.post(pluginRegisterRoute.urlPath)
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
.send(registerAddRequestAltered);