feat: migrate backend to cosmiconfig

This commit is contained in:
2023-04-25 15:54:06 +02:00
parent d8c79256c9
commit 0a76427ba8
70 changed files with 1786 additions and 1635 deletions

View File

@@ -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 () {