Feat: es modules (#139)
* All file imports change from commonjs to es-module * Improved plex error responses back from api * Converted viewHistory to es module * Es-module requires file extension, updated all imports * Fix esmodule not having __dirname defined in scope * Replace dynamic-require with fs readFileSync * Short message service module function is exported as default * Resolved lint issues & ignore import/extension rule until typescript * All tests file imports changed from commonjs to es-module * Import json fixtures with new helper
This commit was merged in pull request #139.
This commit is contained in:
@@ -1,78 +1,77 @@
|
||||
const assert = require("assert");
|
||||
const Config = require("../../../src/config/configuration");
|
||||
import assert from "assert";
|
||||
import Configuration from "../../../src/config/configuration.js";
|
||||
|
||||
const configuration = Configuration.getInstance();
|
||||
|
||||
let backedUpEnvironmentVariables;
|
||||
let backedUpConfigFields;
|
||||
|
||||
describe("Config", () => {
|
||||
beforeEach(() => {
|
||||
this.backedUpEnvironmentVariables = { ...process.env };
|
||||
this.backedUpConfigFields = { ...Config.getInstance().fields };
|
||||
backedUpEnvironmentVariables = { ...process.env };
|
||||
backedUpConfigFields = { ...configuration.fields };
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
process.env = this.backedUpEnvironmentVariables;
|
||||
Config.getInstance().fields = this.backedUpConfigFields;
|
||||
process.env = backedUpEnvironmentVariables;
|
||||
configuration.fields = backedUpConfigFields;
|
||||
});
|
||||
|
||||
it("should retrieve section and option from config file", () => {
|
||||
Config.getInstance().fields = { webserver: { port: 1337 } };
|
||||
assert.equal(Config.getInstance().get("webserver", "port"), 1337);
|
||||
configuration.fields = { webserver: { port: 1337 } };
|
||||
assert.equal(configuration.get("webserver", "port"), 1337);
|
||||
});
|
||||
|
||||
it("should resolve to environment variables if option is filtered with env", () => {
|
||||
Config.getInstance().fields = {
|
||||
configuration.fields = {
|
||||
webserver: { port: "env|SEASONED_WEBSERVER_PORT" }
|
||||
};
|
||||
process.env.SEASONED_WEBSERVER_PORT = "1338";
|
||||
assert.equal(Config.getInstance().get("webserver", "port"), 1338);
|
||||
assert.equal(configuration.get("webserver", "port"), 1338);
|
||||
});
|
||||
|
||||
it("raises an exception if the environment variable does not exist", () => {
|
||||
Config.getInstance().fields = { webserver: { port: "env|DOES_NOT_EXIST" } };
|
||||
configuration.fields = { webserver: { port: "env|DOES_NOT_EXIST" } };
|
||||
process.env.SEASONED_WEBSERVER_PORT = "1338";
|
||||
assert.throws(() => Config.getInstance().get("webserver", "port"), /empty/);
|
||||
assert.throws(() => configuration.get("webserver", "port"), /empty/);
|
||||
});
|
||||
|
||||
it("raises an exception if the environment variable is empty", () => {
|
||||
Config.getInstance().fields = {
|
||||
configuration.fields = {
|
||||
webserver: { port: "env|SEASONED_WEBSERVER_PORT" }
|
||||
};
|
||||
process.env.SEASONED_WEBSERVER_PORT = "";
|
||||
assert.throws(() => Config.getInstance().get("webserver", "port"), /empty/);
|
||||
assert.throws(() => configuration.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/
|
||||
);
|
||||
configuration.fields = { webserver: { port: "1338" } };
|
||||
assert.throws(() => configuration.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" } };
|
||||
configuration.fields = { webserver: { port: "1338" } };
|
||||
assert.throws(
|
||||
() => Config.getInstance().get("webserver", "woops"),
|
||||
() => configuration.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]
|
||||
);
|
||||
configuration.fields = { bouncer: { whitelist: [1, 2, 3] } };
|
||||
assert.deepEqual(configuration.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);
|
||||
configuration.fields = { webserver: { port: "base64|MTMzOA==" } };
|
||||
assert.equal(configuration.get("webserver", "port"), 1338);
|
||||
});
|
||||
|
||||
it("decodes environment variable as base64 if BASE64= is before the variable", () => {
|
||||
Config.getInstance().fields = {
|
||||
configuration.fields = {
|
||||
webserver: { port: "env|base64|SEASONED_WEBSERVER_PORT" }
|
||||
};
|
||||
process.env.SEASONED_WEBSERVER_PORT = "MTMzOA==";
|
||||
assert.equal(Config.getInstance().get("webserver", "port"), 1338);
|
||||
assert.equal(configuration.get("webserver", "port"), 1338);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const assert = require("assert");
|
||||
const Field = require("../../../src/config/field");
|
||||
import assert from "assert";
|
||||
import Field from "../../../src/config/field.js";
|
||||
|
||||
describe("Field", () => {
|
||||
it("should return an array if it is an array", () => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const assert = require("assert");
|
||||
const Filters = require("../../../src/config/filters");
|
||||
import assert from "assert";
|
||||
import Filters from "../../../src/config/filters.js";
|
||||
|
||||
describe("Filters", () => {
|
||||
it("should extract base64 as filter if it is at start of string followed by pipe", () => {
|
||||
|
||||
@@ -1,38 +1,36 @@
|
||||
const assert = require("assert");
|
||||
// const convertTmdbToMovie = require('src/tmdb/convertTmdbToMovie');
|
||||
const { Movie } = require("../../../src/tmdb/types");
|
||||
const bladeRunnerQuerySuccess = require("../../fixtures/blade_runner_2049-info-success-response.json");
|
||||
import assert from "assert";
|
||||
// import convertTmdbToMovie = require('src/tmdb/convertTmdbToMovie');
|
||||
import { Movie } from "../../../src/tmdb/types.js";
|
||||
import readFixtureContents from "../../helpers/importFixture.js";
|
||||
|
||||
const bladeRunnerQuerySuccess = readFixtureContents(
|
||||
"blade_runner_2049-info-success-response.json"
|
||||
);
|
||||
|
||||
let bladeRunnerTmdbMovie;
|
||||
|
||||
describe("Convert tmdb movieInfo to movie", () => {
|
||||
beforeEach(() => {
|
||||
[this.bladeRunnerTmdbMovie] = bladeRunnerQuerySuccess;
|
||||
[bladeRunnerTmdbMovie] = bladeRunnerQuerySuccess;
|
||||
});
|
||||
|
||||
it("should translate the tmdb release date to movie year", () => {
|
||||
const bladeRunner = Movie.convertFromTmdbResponse(
|
||||
this.bladeRunnerTmdbMovie
|
||||
);
|
||||
const bladeRunner = Movie.convertFromTmdbResponse(bladeRunnerTmdbMovie);
|
||||
assert.strictEqual(bladeRunner.year, 2017);
|
||||
});
|
||||
|
||||
it("should translate the tmdb release date to instance of Date", () => {
|
||||
const bladeRunner = Movie.convertFromTmdbResponse(
|
||||
this.bladeRunnerTmdbMovie
|
||||
);
|
||||
const bladeRunner = Movie.convertFromTmdbResponse(bladeRunnerTmdbMovie);
|
||||
assert(bladeRunner.releaseDate instanceof Date);
|
||||
});
|
||||
|
||||
it("should translate the tmdb title to title", () => {
|
||||
const bladeRunner = Movie.convertFromTmdbResponse(
|
||||
this.bladeRunnerTmdbMovie
|
||||
);
|
||||
const bladeRunner = Movie.convertFromTmdbResponse(bladeRunnerTmdbMovie);
|
||||
assert.equal(bladeRunner.title, "Blade Runner 2049");
|
||||
});
|
||||
|
||||
it("should translate the tmdb vote_average to rating", () => {
|
||||
const bladeRunner = Movie.convertFromTmdbResponse(
|
||||
this.bladeRunnerTmdbMovie
|
||||
);
|
||||
const bladeRunner = Movie.convertFromTmdbResponse(bladeRunnerTmdbMovie);
|
||||
assert.equal(bladeRunner.rating, 7.3);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
const assert = require('assert');
|
||||
// const Movie = require('src/movie/movie');
|
||||
const TMDB = require('src/tmdb/tmdb');
|
||||
const Cache = require('src/tmdb/cache');
|
||||
const SqliteDatabase = require('src/database/sqliteDatabase');
|
||||
const tmdbMock = require('test/helpers/tmdbMock');
|
||||
import assert 'assert';
|
||||
// import require('src/movie/movie.js';
|
||||
import TMDB 'src/tmdb/tmdb.js';
|
||||
import Cache 'src/tmdb/cache.js';
|
||||
import SqliteDatabase 'src/database/sqliteDatabase.js';
|
||||
import tmdbMock 'test/helpers/tmdbMock.js';
|
||||
|
||||
const emptyQuerySuccess = require('tests/fixtures/empty-query-success-response.json');
|
||||
const interstellarQuerySuccess = require('tests/fixtures/arrival-info-success-response.json');
|
||||
const popularMovieSuccessResponse = require('tests/fixtures/popular-movies-success-response.json');
|
||||
import emptyQuerySuccess 'tests/fixtures/empty-query-success-response.json';
|
||||
import interstellarQuerySuccess 'tests/fixture/arrival-info-success-response.json');
|
||||
import popularMovieSuccessResponse 'tests/fixture/popular-movies-success-response.json');
|
||||
|
||||
describe('TMDB', function test() {
|
||||
beforeEach(() => {
|
||||
|
||||
Reference in New Issue
Block a user