mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 17:12:43 +00:00
feat: migrate backend to cosmiconfig
This commit is contained in:
@@ -21,9 +21,13 @@ import {
|
||||
SCNotFoundErrorResponse,
|
||||
} from '@openstapps/core';
|
||||
import {expect} from 'chai';
|
||||
import {instance as book} from '@openstapps/core/test/resources/indexable/Book.1.json';
|
||||
import {bulk, DEFAULT_TEST_TIMEOUT} from '../common.js';
|
||||
import {testApp} from '../tests-setup.js';
|
||||
import {readFile} from 'fs/promises';
|
||||
|
||||
const book = JSON.parse(
|
||||
await readFile('node_modules/@openstapps/core/test/resources/indexable/Book.1.json', 'utf8'),
|
||||
);
|
||||
|
||||
describe('Bulk routes', async function () {
|
||||
// increase timeout for the suite
|
||||
|
||||
@@ -23,19 +23,24 @@ import {
|
||||
SCValidationErrorResponse,
|
||||
} from '@openstapps/core';
|
||||
import nock from 'nock';
|
||||
import {configFile, plugins} from '../../src/common.js';
|
||||
import {plugins} from '../../src/common.js';
|
||||
import {pluginRegisterHandler} from '../../src/routes/plugin-register-route.js';
|
||||
import {expect, use} from 'chai';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import {instance as registerRequest} from '@openstapps/core/test/resources/PluginRegisterRequest.1.json';
|
||||
import {DEFAULT_TEST_TIMEOUT} from '../common.js';
|
||||
import {testApp} from '../tests-setup.js';
|
||||
import {backendConfig} from '../../src/config.js';
|
||||
import {readFile} from 'fs/promises';
|
||||
|
||||
// for using promises in expectations (to.eventually.be...)
|
||||
use(chaiAsPromised);
|
||||
|
||||
const registerRequest = JSON.parse(
|
||||
await readFile('node_modules/@openstapps/core/test/resources/PluginRegisterRequest.1.json', 'utf8'),
|
||||
);
|
||||
|
||||
// cast it because of "TS2322: Type 'string' is not assignable to type '"add"'"
|
||||
export const registerAddRequest: SCPluginAdd = registerRequest as SCPluginAdd;
|
||||
export const registerAddRequest: SCPluginAdd = registerRequest.instance as SCPluginAdd;
|
||||
|
||||
export const registerRemoveRequest: SCPluginRemove = {
|
||||
action: 'remove',
|
||||
@@ -48,7 +53,7 @@ describe('Plugin registration', async function () {
|
||||
after(function () {
|
||||
// remove plugins
|
||||
plugins.clear();
|
||||
configFile.app.features = {};
|
||||
backendConfig.app.features = {};
|
||||
});
|
||||
|
||||
it('should register a plugin', async function () {
|
||||
@@ -57,7 +62,7 @@ describe('Plugin registration', async function () {
|
||||
|
||||
expect(response).to.deep.equal(bodySuccess) &&
|
||||
expect(plugins.size).to.equal(1) &&
|
||||
expect(configFile.app.features.plugins!['Foo Plugin']).to.not.be.empty;
|
||||
expect(backendConfig.app.features.plugins!['Foo Plugin']).to.not.be.empty;
|
||||
});
|
||||
|
||||
it('should allow re-registering the same plugin', async function () {
|
||||
@@ -70,7 +75,7 @@ describe('Plugin registration', async function () {
|
||||
return (
|
||||
expect(response).to.deep.equal(bodySuccess) &&
|
||||
expect(plugins.size).to.equal(1) &&
|
||||
expect(configFile.app.features.plugins!['Foo Plugin']).to.not.be.empty
|
||||
expect(backendConfig.app.features.plugins!['Foo Plugin']).to.not.be.empty
|
||||
);
|
||||
});
|
||||
|
||||
@@ -102,7 +107,7 @@ describe('Plugin registration', async function () {
|
||||
|
||||
expect(response).to.deep.equal(bodySuccess) &&
|
||||
expect(plugins.size).to.equal(0) &&
|
||||
expect(configFile.app.features.plugins).to.be.empty;
|
||||
expect(backendConfig.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 () {
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
SCRouteHttpVerbs,
|
||||
SCValidationErrorResponse,
|
||||
} from '@openstapps/core';
|
||||
import * as bodyParser from 'body-parser';
|
||||
import bodyParser from 'body-parser';
|
||||
import sinon from 'sinon';
|
||||
import {expect} from 'chai';
|
||||
import {Application} from 'express';
|
||||
|
||||
@@ -21,10 +21,10 @@ import {
|
||||
SCTooManyRequestsErrorResponse,
|
||||
} from '@openstapps/core';
|
||||
import {expect} from 'chai';
|
||||
import {configFile} from '../../src/common.js';
|
||||
import {DEFAULT_TEST_TIMEOUT} from '../common.js';
|
||||
import {testApp} from '../tests-setup.js';
|
||||
import sinon from 'sinon';
|
||||
import {backendConfig} from '../../src/config.js';
|
||||
|
||||
describe('Search route', async function () {
|
||||
// increase timeout for the suite
|
||||
@@ -96,7 +96,7 @@ describe('Search route', async function () {
|
||||
|
||||
it('should respond with too many requests error if the number of sub-queries exceed their max number', async function () {
|
||||
const sandbox = sinon.createSandbox();
|
||||
sandbox.stub(configFile.backend, 'maxMultiSearchRouteQueries').value(2);
|
||||
sandbox.stub(backendConfig.backend, 'maxMultiSearchRouteQueries').value(2);
|
||||
|
||||
const {status} = await testApp
|
||||
.post(multiSearchRoute.urlPath)
|
||||
|
||||
@@ -17,11 +17,15 @@ import {SCThingUpdateRoute} from '@openstapps/core';
|
||||
import chaiAsPromised from 'chai-as-promised';
|
||||
import {bulkStorageMock, DEFAULT_TEST_TIMEOUT} from '../common.js';
|
||||
import {expect, use} from 'chai';
|
||||
import {instance as book} from '@openstapps/core/test/resources/indexable/Book.1.json';
|
||||
import {testApp} from '../tests-setup.js';
|
||||
import {readFile} from 'fs/promises';
|
||||
|
||||
use(chaiAsPromised);
|
||||
|
||||
const book = JSON.parse(
|
||||
await readFile('node_modules/@openstapps/core/test/resources/indexable/Book.1.json', 'utf8'),
|
||||
);
|
||||
|
||||
describe('Thing update route', async function () {
|
||||
// increase timeout for the suite
|
||||
this.timeout(DEFAULT_TEST_TIMEOUT);
|
||||
|
||||
@@ -25,7 +25,7 @@ import {mockReq} from 'sinon-express-mock';
|
||||
import {plugins, validator} from '../../src/common.js';
|
||||
import {virtualPluginRoute} from '../../src/routes/virtual-plugin-route.js';
|
||||
import {DEFAULT_TEST_TIMEOUT, FooError} from '../common.js';
|
||||
import {registerAddRequest} from './plugin-register-route.spec';
|
||||
import {registerAddRequest} from './plugin-register-route.spec.js';
|
||||
import {testApp} from '../tests-setup.js';
|
||||
|
||||
use(chaiAsPromised);
|
||||
@@ -154,12 +154,12 @@ describe('Virtual plugin routes', async function () {
|
||||
plugins.clear();
|
||||
// // restore everything to default methods (remove stubs)
|
||||
sandbox.restore();
|
||||
// clean up request mocks (fixes issue with receiving response from mock from previous test case)
|
||||
// cleanup request mocks (fixes issue with receiving response from mock from previous test case)
|
||||
nock.cleanAll();
|
||||
});
|
||||
|
||||
it('should properly provide the response of a plugin', async function () {
|
||||
// lets simulate that the plugin is already registered
|
||||
// let's simulate that the plugin is already registered
|
||||
plugins.set(registerAddRequest.plugin.route, registerAddRequest.plugin);
|
||||
// mock responses of the plugin, depending on the body sent
|
||||
nock('http://foo.com:1234')
|
||||
@@ -174,20 +174,20 @@ describe('Virtual plugin routes', async function () {
|
||||
.set('Content-Type', 'application/json')
|
||||
.set('Accept', 'application/json')
|
||||
.send({query: 'foo'});
|
||||
expect(fooResponse.status).to.be.equal(OK);
|
||||
expect(fooResponse.body).to.be.deep.equal({result: [{foo: 'foo'}, {bar: 'foo'}]});
|
||||
|
||||
const barResponse = await testApp
|
||||
.post('/foo')
|
||||
.set('Content-Type', 'application/json')
|
||||
.set('Accept', 'application/json')
|
||||
.send({query: 'bar'});
|
||||
|
||||
expect(fooResponse.status).to.be.equal(OK);
|
||||
expect(fooResponse.body).to.be.deep.equal({result: [{foo: 'foo'}, {bar: 'foo'}]});
|
||||
expect(barResponse.status).to.be.equal(OK);
|
||||
expect(barResponse.body).to.be.deep.equal({result: [{foo: 'bar'}, {bar: 'bar'}]});
|
||||
});
|
||||
|
||||
it('should return error response if plugin address is not responding', async function () {
|
||||
// lets simulate that the plugin is already registered
|
||||
// let's simulate that the plugin is already registered
|
||||
plugins.set(registerAddRequest.plugin.route, registerAddRequest.plugin);
|
||||
|
||||
class FooError extends Error {}
|
||||
|
||||
Reference in New Issue
Block a user