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

View File

@@ -1,4 +1,3 @@
const fetch = require("node-fetch");
const convertPlexToMovie = require("./convertPlexToMovie");
const convertPlexToShow = require("./convertPlexToShow");
const convertPlexToEpisode = require("./convertPlexToEpisode");

View File

@@ -1,4 +1,3 @@
const rp = require("request-promise");
const convertPlexToSeasoned = require("./convertPlexToSeasoned");
const convertPlexToStream = require("./convertPlexToStream");
@@ -35,8 +34,9 @@ function mapResults(response) {
}
class PlexRepository {
constructor(plexIP) {
constructor(plexIP, plexToken) {
this.plexIP = plexIP;
this.plexToken = plexToken;
}
inPlex(_tmdbResult) {
@@ -56,19 +56,17 @@ class PlexRepository {
}
search(query) {
const queryUri = encodeURIComponent(query);
const uri = encodeURI(
`http://${this.plexIP}:32400/search?query=${queryUri}`
const url = encodeURI(
`http://${this.plexIP}:32400/search?query=${encodeURIComponent(
query
)}&X-Plex-Token=${this.plexToken}`
);
const options = {
uri,
headers: {
Accept: "application/json"
},
json: true
headers: { Accept: "application/json" }
};
return rp(options)
return fetch(url, options)
.then(resp => resp.json())
.then(result => mapResults(result))
.then(([mappedResults, resultCount]) => ({
results: mappedResults,
@@ -77,15 +75,13 @@ class PlexRepository {
}
nowPlaying() {
const url = `http://${this.plexIP}:32400/status/sessions?X-Plex-Token=${this.plexToken}`;
const options = {
uri: `http://${this.plexIP}:32400/status/sessions`,
headers: {
Accept: "application/json"
},
json: true
headers: { Accept: "application/json" }
};
return rp(options)
return fetch(url, options)
.then(resp => resp.json())
.then(result => {
if (result.MediaContainer.size > 0) {
const playing =

View File

@@ -3,7 +3,10 @@ const configuration = require("../config/configuration").getInstance();
const TMDB = require("../tmdb/tmdb");
const establishedDatabase = require("../database/database");
const plexRepository = new PlexRepository(configuration.get("plex", "ip"));
const plexRepository = new PlexRepository(
configuration.get("plex", "ip"),
configuration.get("plex", "token")
);
const tmdb = new TMDB(configuration.get("tmdb", "apiKey"));
class RequestRepository {