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 was merged in pull request #138.
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

21
src/cache/redis.js vendored
View File

@@ -1,6 +1,7 @@
const configuration = require("../config/configuration").getInstance();
let client;
const mockCache = {};
try {
const redis = require("redis"); // eslint-disable-line global-require
@@ -8,7 +9,6 @@ try {
const host = configuration.get("redis", "host");
const port = configuration.get("redis", "port");
console.log(`redis://${host}:${port}`); // eslint-disable-line no-console
client = redis.createClient({
url: `redis://${host}:${port}`
});
@@ -20,13 +20,18 @@ try {
console.error("Unable to connect to redis, setting up redis-mock."); // eslint-disable-line no-console
client = {
get(command) {
console.log(`redis-dummy get: ${command}`); // eslint-disable-line no-console
return Promise.resolve();
get(key, callback) {
console.log(`redis-dummy get: ${key}`); // eslint-disable-line no-console
const hit = mockCache[key];
return Promise.resolve().then(callback(null, hit));
},
set(command) {
console.log(`redis-dummy set: ${command}`); // eslint-disable-line no-console
return Promise.resolve();
set(key, json, callback) {
console.log(`redis-dummy set: ${key}`); // eslint-disable-line no-console
mockCache[key] = JSON.stringify(json);
return Promise.resolve().then(callback(null, "OK"));
},
expire(key, TTL) {
console.log(`redis-dummy expire: ${key} with TTL ${TTL}`); // eslint-disable-line no-console
}
};
});
@@ -39,7 +44,7 @@ function set(key, value, TTL = 10800) {
client.set(key, json, (error, reply) => {
if (reply === "OK") {
// successfully set value with key, now set TTL for key
client.expire(key, TTL, e => {
client.expire(key, TTL, "NX", e => {
if (e)
// eslint-disable-next-line no-console
console.error(