Fix: Tests lint and src folder (#138)

* Automaticly fixable eslint issues, mostly 3 -> 2 space indentation

* fix: updated plex_userid to camelcase

* Linted and some consistency refactor on middleware

* eslint uses ecmaversion 2020 & allow empty catch rule

* Started linting source files

* Fixed eslint errors & improved a lot of error handling

* Set 2 eslint rules as warning temporarly

* Updated all import statements to be relative

* Updated mocha & nyc, resolved all lint issues in tests/

* Updated mocha & nyc. Removed production config. Updated gitignore

* Updated test commands to omit system tests, no exit code

* Updated test configuration w/ missing keys

* Chai modules defined in package.json & resolved linting errors

* Dockerfile copies development.example -> production.json. Simplified commands

* All api calls from tests use same chaiHttp implementation

Removes a list of fetch alternatives after being replaced by chaiHttp:
 - request
 - request-promise
 - supertest
 - supertest-as-promised

* Tests should use redis (mock) cache, not tmdb sqlite cache

* Disabled test asADeveloperIWantTheServerToStart

* Re-enable tests/system

* Use chaiHttp in asAUserIWantToRequestAMovie.

* Fixed redis expire & mock implmentation

* Replaced all fetch alternatives from source code and package.json

* Pass error from tmdb api back to client as errorMessage

* Updated authentication middleware to handle checks consitenctly

* Prevent assert error when checking request status, returns success 200

* Resolved merge conflicts

* Only build and publish docker container when branch master
This commit is contained in:
2022-08-20 17:41:46 +02:00
committed by GitHub
parent 1815a429b0
commit 628ed52012
44 changed files with 1248 additions and 1592 deletions

View File

@@ -1,63 +1,78 @@
const assert = require('assert');
const Config = require('src/config/configuration.js');
const assert = require("assert");
const Config = require("../../../src/config/configuration");
describe('Config', () => {
before(() => {
this.backedUpEnvironmentVariables = Object.assign({}, process.env);
this.backedUpConfigFields = Object.assign({}, Config.getInstance().fields);
describe("Config", () => {
beforeEach(() => {
this.backedUpEnvironmentVariables = { ...process.env };
this.backedUpConfigFields = { ...Config.getInstance().fields };
});
after(() => {
afterEach(() => {
process.env = this.backedUpEnvironmentVariables;
Config.getInstance().fields = this.backedUpConfigFields;
});
it('should retrieve section and option from config file', () => {
Config.getInstance().fields = { 'webserver': { 'port': 1337 } };
assert.equal(Config.getInstance().get('webserver', 'port'), 1337);
it("should retrieve section and option from config file", () => {
Config.getInstance().fields = { webserver: { port: 1337 } };
assert.equal(Config.getInstance().get("webserver", "port"), 1337);
});
it('should resolve to environment variables if option is filtered with env', () => {
Config.getInstance().fields = { 'webserver': { 'port': 'env|SEASONED_WEBSERVER_PORT' } };
process.env.SEASONED_WEBSERVER_PORT = '1338';
assert.equal(Config.getInstance().get('webserver', 'port'), 1338);
it("should resolve to environment variables if option is filtered with env", () => {
Config.getInstance().fields = {
webserver: { port: "env|SEASONED_WEBSERVER_PORT" }
};
process.env.SEASONED_WEBSERVER_PORT = "1338";
assert.equal(Config.getInstance().get("webserver", "port"), 1338);
});
it('raises an exception if the environment variable does not exist', () => {
Config.getInstance().fields = { 'webserver': { 'port': 'env|DOES_NOT_EXIST' } };
process.env.SEASONED_WEBSERVER_PORT = '1338';
assert.throws(() => Config.getInstance().get('webserver', 'port'), /empty/);
it("raises an exception if the environment variable does not exist", () => {
Config.getInstance().fields = { webserver: { port: "env|DOES_NOT_EXIST" } };
process.env.SEASONED_WEBSERVER_PORT = "1338";
assert.throws(() => Config.getInstance().get("webserver", "port"), /empty/);
});
it('raises an exception if the environment variable is empty', () => {
Config.getInstance().fields = { 'webserver': { 'port': 'env|SEASONED_WEBSERVER_PORT' } };
process.env.SEASONED_WEBSERVER_PORT = '';
assert.throws(() => Config.getInstance().get('webserver', 'port'), /empty/);
it("raises an exception if the environment variable is empty", () => {
Config.getInstance().fields = {
webserver: { port: "env|SEASONED_WEBSERVER_PORT" }
};
process.env.SEASONED_WEBSERVER_PORT = "";
assert.throws(() => Config.getInstance().get("webserver", "port"), /empty/);
});
it('raises an exception if the section does not exist in the file', () => {
Config.getInstance().fields = { 'webserver': { 'port': '1338' } };
assert.throws(() => Config.getInstance().get('woops', 'port'), /does not exist/);
it("raises an exception if the section does not exist in the file", () => {
Config.getInstance().fields = { webserver: { port: "1338" } };
assert.throws(
() => Config.getInstance().get("woops", "port"),
/does not exist/
);
});
it('raises an exception if the option does not exist in the file', () => {
Config.getInstance().fields = { 'webserver': { 'port': '1338' } };
assert.throws(() => Config.getInstance().get('webserver', 'woops'), /does not exist/);
it("raises an exception if the option does not exist in the file", () => {
Config.getInstance().fields = { webserver: { port: "1338" } };
assert.throws(
() => Config.getInstance().get("webserver", "woops"),
/does not exist/
);
});
it('returns an array if field is an array', () => {
Config.getInstance().fields = { 'bouncer': { 'whitelist': [1, 2, 3] } };
assert.deepEqual(Config.getInstance().get('bouncer', 'whitelist'), [1, 2, 3]);
it("returns an array if field is an array", () => {
Config.getInstance().fields = { bouncer: { whitelist: [1, 2, 3] } };
assert.deepEqual(
Config.getInstance().get("bouncer", "whitelist"),
[1, 2, 3]
);
});
it('decodes field as base64 if base64| is before the variable', () => {
Config.getInstance().fields = { 'webserver': { 'port': 'base64|MTMzOA==' } };
assert.equal(Config.getInstance().get('webserver', 'port'), 1338);
it("decodes field as base64 if base64| is before the variable", () => {
Config.getInstance().fields = { webserver: { port: "base64|MTMzOA==" } };
assert.equal(Config.getInstance().get("webserver", "port"), 1338);
});
it('decodes environment variable as base64 if BASE64= is before the variable', () => {
Config.getInstance().fields = { 'webserver': { 'port': 'env|base64|SEASONED_WEBSERVER_PORT' } };
process.env.SEASONED_WEBSERVER_PORT = 'MTMzOA==';
assert.equal(Config.getInstance().get('webserver', 'port'), 1338);
it("decodes environment variable as base64 if BASE64= is before the variable", () => {
Config.getInstance().fields = {
webserver: { port: "env|base64|SEASONED_WEBSERVER_PORT" }
};
process.env.SEASONED_WEBSERVER_PORT = "MTMzOA==";
assert.equal(Config.getInstance().get("webserver", "port"), 1338);
});
});