Merge pull request #1001 from bluewave-labs/feat/be/settings-service-tests
feat/be/settings service tests
This commit is contained in:
3 files changed
+141
-9
No files matched your search
@@ -1,4 +1,3 @@
|
||||
import AppSettings from "../db/models/AppSettings.js";
|
||||
const SERVICE_NAME = "SettingsService";
|
||||
const envConfig = {
|
||||
logLevel: undefined,
|
||||
@@ -30,7 +29,8 @@ class SettingsService {
|
||||
* Constructs a new SettingsService
|
||||
* @constructor
|
||||
* @throws {Error}
|
||||
*/ constructor() {
|
||||
*/ constructor(appSettings) {
|
||||
this.appSettings = appSettings;
|
||||
this.settings = { ...envConfig };
|
||||
}
|
||||
/**
|
||||
@@ -40,7 +40,7 @@ class SettingsService {
|
||||
* @throws Will throw an error if settings are not found in the database or if settings have not been loaded.
|
||||
*/ async loadSettings() {
|
||||
try {
|
||||
const dbSettings = await AppSettings.findOne();
|
||||
const dbSettings = await this.appSettings.findOne();
|
||||
if (!this.settings) {
|
||||
throw new Error("Settings not found");
|
||||
}
|
||||
@@ -51,10 +51,6 @@ class SettingsService {
|
||||
this.settings[key] = dbSettings[key];
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.settings) {
|
||||
throw new Error("Settings not found");
|
||||
}
|
||||
return this.settings;
|
||||
} catch (error) {
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
|
||||
Reference in new issue
Block a user