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

@@ -44,7 +44,7 @@ describe('Bulk routes', async function () {
it('should create bulk', async function () {
const {status, body, error} = await testApp
.post(bulkRoute.urlFragment)
.post(bulkRoute.urlPath)
.set('Content-Type', 'application/json')
.send(request);
@@ -56,13 +56,13 @@ describe('Bulk routes', async function () {
it('should return (throw) error if a bulk with the provided UID cannot be found when adding to a bulk', async function () {
await testApp
.post(bulkRoute.urlFragment)
.post(bulkRoute.urlPath)
.set('Content-Type', 'application/json')
.send(request);
const bulkAddRouteUrlFragment = bulkAddRoute.urlFragment.toLocaleLowerCase().replace(':uid', 'a-wrong-uid');
const bulkAddRouteurlPath = bulkAddRoute.urlPath.toLocaleLowerCase().replace(':uid', 'a-wrong-uid');
const {status} = await testApp
.post(bulkAddRouteUrlFragment)
.post(bulkAddRouteurlPath)
.set('Content-Type', 'application/json')
.send(book);
@@ -71,13 +71,13 @@ describe('Bulk routes', async function () {
it('should add to a created bulk', async function () {
const response = await testApp
.post(bulkRoute.urlFragment)
.post(bulkRoute.urlPath)
.set('Content-Type', 'application/json')
.send(request);
const bulkAddRouteUrlFragment = bulkAddRoute.urlFragment.toLocaleLowerCase().replace(':uid', response.body.uid);
const bulkAddRouteurlPath = bulkAddRoute.urlPath.toLocaleLowerCase().replace(':uid', response.body.uid);
const {status, body} = await testApp
.post(bulkAddRouteUrlFragment)
.post(bulkAddRouteurlPath)
.set('Content-Type', 'application/json')
.send(book);
@@ -87,13 +87,13 @@ describe('Bulk routes', async function () {
it('should return (throw) error if a bulk with the provided UID cannot be found when closing a bulk (done)', async function () {
await testApp
.post(bulkRoute.urlFragment)
.post(bulkRoute.urlPath)
.set('Content-Type', 'application/json')
.send(request);
const bulkDoneRouteUrlFragment = bulkDoneRoute.urlFragment.toLocaleLowerCase().replace(':uid', 'a-wrong-uid');
const bulkDoneRouteurlPath = bulkDoneRoute.urlPath.toLocaleLowerCase().replace(':uid', 'a-wrong-uid');
const {status} = await testApp
.post(bulkDoneRouteUrlFragment)
.post(bulkDoneRouteurlPath)
.set('Content-Type', 'application/json')
.send({});
@@ -102,13 +102,13 @@ describe('Bulk routes', async function () {
it ('should close the bulk (done)', async function () {
const response = await testApp
.post(bulkRoute.urlFragment)
.post(bulkRoute.urlPath)
.set('Content-Type', 'application/json')
.send(request);
const bulkDoneRouteUrlFragment = bulkDoneRoute.urlFragment.toLocaleLowerCase().replace(':uid', response.body.uid);
const bulkDoneRouteurlPath = bulkDoneRoute.urlPath.toLocaleLowerCase().replace(':uid', response.body.uid);
const response2 = await testApp
.post(bulkDoneRouteUrlFragment)
.post(bulkDoneRouteurlPath)
.set('Content-Type', 'application/json')
.send({});

View File

@@ -27,7 +27,7 @@ describe('Index route', async function () {
const request: SCIndexRequest = {};
const response = await testApp
.post(indexRoute.urlFragment)
.post(indexRoute.urlPath)
.set('Content-Type', 'application/json')
.send(request);
@@ -35,5 +35,6 @@ describe('Index route', async function () {
expect(response.status).to.equal(indexRoute.statusCodeSuccess);
expect(response.body).to.haveOwnProperty('app');
expect(response.body).to.haveOwnProperty('backend');
expect(response.body).to.haveOwnProperty('auth');
});
});

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);

View File

@@ -56,7 +56,7 @@ describe('Create route', async function () {
requestBodyName: 'fooBodyName',
responseBodyName: 'barBodyName',
statusCodeSuccess: statusCodeSuccess,
urlFragment: '/foo',
urlPath: '/foo',
};
handler = (_request, _app) => {
return Promise.resolve(bodySuccess);
@@ -84,7 +84,7 @@ describe('Create route', async function () {
const response = await supertest(app)
// use method other than defined ("get" is not the method of the route)
.get(routeClass.urlFragment)
.get(routeClass.urlPath)
.send();
expect(response.status).to.be.equal(methodNotAllowedError.statusCode);
@@ -98,7 +98,7 @@ describe('Create route', async function () {
app.use(router);
const response = await supertest(app)
.post(routeClass.urlFragment)
.post(routeClass.urlPath)
.send();
expect(response.status).to.be.equal(statusCodeSuccess);
@@ -116,7 +116,7 @@ describe('Create route', async function () {
validatorStub.withArgs(body, routeClass.requestBodyName).returns({errors: [new Error('Foo Error')]});
const response = await startApp
.post(routeClass.urlFragment)
.post(routeClass.urlPath)
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
.send(body);
@@ -134,7 +134,7 @@ describe('Create route', async function () {
validatorStub.withArgs(bodySuccess, routeClass.responseBodyName).returns({errors: [new Error('Foo Error')]});
const response = await startApp
.post(routeClass.urlFragment)
.post(routeClass.urlPath)
.send();
expect(response.status).to.be.equal(internalServerError.statusCode);
@@ -174,7 +174,7 @@ describe('Create route', async function () {
sandbox.stub(validator, 'validate').returns({errors:[]});
const response = await startApp
.post(routeClass.urlFragment)
.post(routeClass.urlPath)
.send();
expect(response.status).to.be.equal(internalServerError.statusCode);
@@ -209,7 +209,7 @@ describe('Create route', async function () {
sandbox.stub(validator, 'validate').returns({errors:[]});
const response = await startApp
.post(routeClass.urlFragment)
.post(routeClass.urlPath)
.send();
expect(response.status).to.be.equal(fooErrorResponse.statusCode);

View File

@@ -50,7 +50,7 @@ describe('Search route', async function () {
describe('Basic POST /search', async function() {
it('should accept empty JSON object', async function () {
const {status} = await testApp
.post(searchRoute.urlFragment)
.post(searchRoute.urlPath)
.set('Accept', 'application/json')
.send({});
@@ -59,7 +59,7 @@ describe('Search route', async function () {
it('should accept valid search request', async function () {
const {status} = await testApp
.post(searchRoute.urlFragment)
.post(searchRoute.urlPath)
.set('Accept', 'application/json')
.send({
query: 'Some search terms'
@@ -70,7 +70,7 @@ describe('Search route', async function () {
it('should respond with bad request on invalid search request (body)', async function () {
const {status} = await testApp
.post(searchRoute.urlFragment)
.post(searchRoute.urlPath)
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
.send({
@@ -84,7 +84,7 @@ describe('Search route', async function () {
describe('Basic POST /multi/search', async function() {
it('should respond with bad request on invalid search request (empty JSON object as body)', async function () {
const {status} = await testApp
.post(multiSearchRoute.urlFragment)
.post(multiSearchRoute.urlPath)
.set('Accept', 'application/json')
.send({});
@@ -93,7 +93,7 @@ describe('Search route', async function () {
it('should accept valid search request', async function () {
const {status} = await testApp
.post(multiSearchRoute.urlFragment)
.post(multiSearchRoute.urlPath)
.set('Accept', 'application/json')
.send({
one: { query: 'Some search terms for one search'},
@@ -108,7 +108,7 @@ describe('Search route', async function () {
sandbox.stub(configFile.backend, 'maxMultiSearchRouteQueries').value(2);
const {status} = await testApp
.post(multiSearchRoute.urlFragment)
.post(multiSearchRoute.urlPath)
.set('Content-Type', 'application/json')
.send({
one: {},

View File

@@ -28,12 +28,12 @@ describe('Thing update route', async function () {
const thingUpdateRoute = new SCThingUpdateRoute();
it('should update a thing', async function () {
const thingUpdateRouteUrlFragment = thingUpdateRoute.urlFragment.toLocaleLowerCase()
const thingUpdateRouteurlPath = thingUpdateRoute.urlPath.toLocaleLowerCase()
.replace(':type', book.type)
.replace(':uid', book.uid);
const {status} = await testApp
.put(thingUpdateRouteUrlFragment)
.put(thingUpdateRouteurlPath)
.set('Content-Type', 'application/json')
.send(book);