From 47946cbf34fcab7a3025084f5c0dfccf03f0021a Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Thu, 24 Oct 2024 10:04:22 +0800 Subject: [PATCH] Uncomment out expect statement --- Client/src/App.jsx | 17 +++- Client/src/Features/Settings/settingsSlice.js | 1 + Client/src/Utils/NetworkService.js | 81 ++++++++++--------- Server/tests/services/jobQueue.test.js | 3 +- 4 files changed, 60 insertions(+), 42 deletions(-) diff --git a/Client/src/App.jsx b/Client/src/App.jsx index 98772ecca..ed97b67f9 100644 --- a/Client/src/App.jsx +++ b/Client/src/App.jsx @@ -36,7 +36,7 @@ import { useSelector } from "react-redux"; import { CssBaseline } from "@mui/material"; import { useEffect } from "react"; import { useDispatch } from "react-redux"; -import { getAppSettings } from "./Features/Settings/settingsSlice"; +import { getAppSettings, updateAppSettings } from "./Features/Settings/settingsSlice"; import { logger } from "./Utils/Logger"; // Import the logger import { networkService } from "./main"; function App() { @@ -66,6 +66,21 @@ function App() { }; }, []); + useEffect(() => { + const thing = async () => { + const action = await dispatch( + updateAppSettings({ authToken, settings: { apiBaseUrl: "test" } }) + ); + + if (action.payload.success) { + console.log(action.payload.data); + } else { + console.log(action); + } + }; + thing(); + }, [dispatch, authToken]); + return ( diff --git a/Client/src/Features/Settings/settingsSlice.js b/Client/src/Features/Settings/settingsSlice.js index 283a8502d..e5cd6e8b8 100644 --- a/Client/src/Features/Settings/settingsSlice.js +++ b/Client/src/Features/Settings/settingsSlice.js @@ -49,6 +49,7 @@ export const updateAppSettings = createAsyncThunk( systemEmailAddress: settings.systemEmailAddress, systemEmailPassword: settings.systemEmailPassword, }; + console.log(parsedSettings); const res = await networkService.updateAppSettings({ settings: parsedSettings, authToken, diff --git a/Client/src/Utils/NetworkService.js b/Client/src/Utils/NetworkService.js index 5571d40ff..287cba4b4 100644 --- a/Client/src/Utils/NetworkService.js +++ b/Client/src/Utils/NetworkService.js @@ -13,6 +13,7 @@ class NetworkService { this.setBaseUrl(baseURL); this.unsubscribe = store.subscribe(() => { const state = store.getState(); + console.log(state.settings.apiBaseUrl); if (BASE_URL !== undefined) { baseURL = BASE_URL; } else if (state?.settings?.apiBaseUrl ?? null) { @@ -87,48 +88,48 @@ class NetworkService { }, }); } - - /** - * - * ************************************ - * Check the endpoint resolution - * ************************************ - * - * @async - * @param {Object} config - The configuration object. - * @param {string} config.authToken - The authorization token to be used in the request header. - * @param {Object} config.monitorURL - The monitor url to be sent in the request body. - * @returns {Promise} The response from the axios POST request. - */ - async checkEndpointResolution(config) { - const { authToken, monitorURL } = config; - const params = new URLSearchParams(); - - if (monitorURL) params.append("monitorURL", monitorURL); - return this.axiosInstance.get(`/monitors/resolution/url?${params.toString()}`, { - headers: { - Authorization: `Bearer ${authToken}`, - "Content-Type": "application/json", - } - }) - } + /** + * + * ************************************ + * Check the endpoint resolution + * ************************************ + * + * @async + * @param {Object} config - The configuration object. + * @param {string} config.authToken - The authorization token to be used in the request header. + * @param {Object} config.monitorURL - The monitor url to be sent in the request body. + * @returns {Promise} The response from the axios POST request. + */ + async checkEndpointResolution(config) { + const { authToken, monitorURL } = config; + const params = new URLSearchParams(); - /** - * - * ************************************ - * Gets monitors and summary of stats by TeamID - * ************************************ - * - * @async - * @param {Object} config - The configuration object. - * @param {string} config.authToken - The authorization token to be used in the request header. - * @param {string} config.teamId - Team ID - * @param {Array} config.types - Array of monitor types - * @returns {Promise} The response from the axios POST request. - */ - async getMonitorsAndSummaryByTeamId(config) { - const params = new URLSearchParams(); + if (monitorURL) params.append("monitorURL", monitorURL); + + return this.axiosInstance.get(`/monitors/resolution/url?${params.toString()}`, { + headers: { + Authorization: `Bearer ${authToken}`, + "Content-Type": "application/json", + }, + }); + } + + /** + * + * ************************************ + * Gets monitors and summary of stats by TeamID + * ************************************ + * + * @async + * @param {Object} config - The configuration object. + * @param {string} config.authToken - The authorization token to be used in the request header. + * @param {string} config.teamId - Team ID + * @param {Array} config.types - Array of monitor types + * @returns {Promise} The response from the axios POST request. + */ + async getMonitorsAndSummaryByTeamId(config) { + const params = new URLSearchParams(); if (config.types) { config.types.forEach((type) => { diff --git a/Server/tests/services/jobQueue.test.js b/Server/tests/services/jobQueue.test.js index c3824f05d..dfb2f749c 100644 --- a/Server/tests/services/jobQueue.test.js +++ b/Server/tests/services/jobQueue.test.js @@ -1,5 +1,6 @@ import sinon from "sinon"; import JobQueue from "../../service/jobQueue.js"; +import { log } from "console"; class QueueStub { constructor(queueName, options) { @@ -202,7 +203,7 @@ describe("JobQueue", () => { ); const worker = jobQueue.createWorker(); await worker.workerTask(); - // expect(networkService.getStatus.calledOnce).to.be.false; + expect(networkService.getStatus.calledOnce).to.be.true; }); }); describe("getWorkerStats", () => {