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,9 +1,7 @@
const Cache = require('src/tmdb/cache');
const SqliteDatabase = require('src/database/sqliteDatabase');
const redisCache = require("../../src/cache/redis");
function createCacheEntry(key, value) {
const cache = new Cache();
return cache.set(key, value);
return redisCache.set(key, value);
}
module.exports = createCacheEntry;

View File

@@ -1,5 +1,5 @@
const User = require('src/user/user');
const Token = require('src/user/token');
const User = require("../../src/user/user");
const Token = require("../../src/user/token");
function createToken(username, secret) {
const user = new User(username);

View File

@@ -1,11 +1,11 @@
const User = require('src/user/user');
const UserSecurity = require('src/user/userSecurity');
const User = require("../../src/user/user");
const UserSecurity = require("../../src/user/userSecurity");
function createUser(username, password) {
const userSecurity = new UserSecurity();
const user = new User(username)
const user = new User(username);
return Promise.resolve(userSecurity.createNewUser(user, password))
return userSecurity.createNewUser(user, password);
}
module.exports = createUser;
module.exports = createUser;

View File

@@ -1,9 +1,22 @@
const establishedDatabase = require('src/database/database');
// class EstablishedDatabase {
// constructor() {}
function resetDatabase() {
return Promise.resolve()
.then(() => establishedDatabase.tearDown())
.then(() => establishedDatabase.setUp())
// tearDown() {
// console.log("mock teardown");
// }
// setup() {
// console.log("mock setup");
// }
// }
const establishedDatabase = require("../../src/database/database");
// const establishedDatabase = new EstablishedDatabase();
function resetDatabase() {
return Promise.resolve()
.then(() => establishedDatabase.tearDown())
.then(() => establishedDatabase.setUp());
}
module.exports = resetDatabase;

View File

@@ -1,16 +1,15 @@
const tmdbMock = () => ({
error: null,
response: null,
searchMovie(query, callback) {
callback(this.error, this.response);
},
movieInfo(query, callback) {
callback(this.error, this.response);
},
miscPopularMovies(callback) {
console.log('miscPopMovies callback', callback)
callback(this.error, this.response);
},
error: null,
response: null,
searchMovie(query, callback) {
callback(this.error, this.response);
},
movieInfo(query, callback) {
callback(this.error, this.response);
},
miscPopularMovies(callback) {
callback(this.error, this.response);
}
});
module.exports = tmdbMock;