From 9860ece25c565c957d1f5869155e42c6ea2abfd5 Mon Sep 17 00:00:00 2001 From: Matt Fancher <142915944+FancMa01@users.noreply.github.com> Date: Tue, 30 Jan 2024 09:01:09 -0700 Subject: [PATCH] Bug fixes --- .../orbitMonitoring/OrbitMonitoringModal.jsx | 2 +- server/routes/orbit/read.js | 63 +++++-------------- server/tests/unit/orbit.test.js | 8 ++- 3 files changed, 21 insertions(+), 52 deletions(-) diff --git a/client-reactjs/src/components/application/orbitMonitoring/OrbitMonitoringModal.jsx b/client-reactjs/src/components/application/orbitMonitoring/OrbitMonitoringModal.jsx index 3fa0a8fe8..5b6c6dbe0 100644 --- a/client-reactjs/src/components/application/orbitMonitoring/OrbitMonitoringModal.jsx +++ b/client-reactjs/src/components/application/orbitMonitoring/OrbitMonitoringModal.jsx @@ -248,7 +248,7 @@ const OrbitMonitoringModal = ({ try { const payload = { method: 'GET', header: authHeader() }; setFetchingOrbitDetails(true); - const response = await fetch(`/api/orbit/${applicationId}/${id}`, payload); + const response = await fetch(`/api/orbit/getOne/${applicationId}/${id}`, payload); if (!response.ok) handleError(response); const data = await response.json(); diff --git a/server/routes/orbit/read.js b/server/routes/orbit/read.js index 3d99a910f..c86b0c5f0 100644 --- a/server/routes/orbit/read.js +++ b/server/routes/orbit/read.js @@ -180,7 +180,7 @@ router.get( //get all router.get( - "/all/:application_id", + "/allMonitoring/:application_id", [param("application_id").isUUID(4).withMessage("Invalid application id")], async (req, res) => { const errors = validationResult(req).formatWith( @@ -191,7 +191,7 @@ router.get( return res.status(422).json({ success: false, errors: errors.array() }); const { application_id } = req.params; if (!application_id) throw Error("Invalid app ID"); - const result = await orbitBuilds.findAll({ + const result = await orbitMonitoring.findAll({ where: { application_id, }, @@ -219,6 +219,7 @@ router.get( validatorUtil.errorFormatter ); try { + console.log(errors); if (!errors.isEmpty()) return res.status(422).json({ success: false, errors: errors.array() }); const { application_id, keyword } = req.params; @@ -471,6 +472,8 @@ router.put( } ); +// EVERYTHING ABOVE THIS WORKS WITH APP ID VALIDATION + // Pause or start monitoring router.put( "/togglestatus/:id", @@ -551,57 +554,22 @@ router.delete( } ); -//get filtered orbit builds -- NOT USED -// router.get("/filteredBuilds", async (req, res) => { -// try { -// const { queryData } = req.query; - -// const { status, dateRange, applicationId } = JSON.parse(queryData); - -// const query = { -// application_id: applicationId, -// metaData: { -// status: { [Op.in]: status }, -// }, -// }; - -// if (dateRange) { -// let minDate = moment(dateRange[0]).format("YYYY-MM-DD HH:mm:ss"); -// let maxDate = moment(dateRange[1]).format("YYYY-MM-DD HH:mm:ss"); - -// const range = [minDate, maxDate]; -// query.metaData.lastRun = { [Op.between]: range }; -// } - -// const results = await orbitBuilds.findAll({ -// where: query, -// order: [["metaData.lastRun", "DESC"]], -// raw: true, -// }); - -// res.status(200).send(results); -// } catch (err) { -// console.error(err); -// } -// }); - router.get( - "/:application_id/:id", + "/getOne/:application_id/:id", [param("id").isUUID(4).withMessage("Invalid orbit id")], [param("application_id").isUUID(4).withMessage("Invalid application id")], async (req, res) => { + const errors = validationResult(req).formatWith( + validatorUtil.errorFormatter + ); try { - const errors = validationResult(req).formatWith( - validatorUtil.errorFormatter - ); - if (!errors.isEmpty()) return res.status(422).json({ success: false, errors: errors.array() }); - const { id } = req.params; + const { id, application_id } = req.params; const result = await orbitMonitoring.findOne({ - where: { id }, + where: { id, application_id }, raw: true, }); @@ -617,11 +585,10 @@ router.get( "/getWorkunits/:application_id", [param("application_id").isUUID(4).withMessage("Invalid application id")], async (req, res) => { + const errors = validationResult(req).formatWith( + validatorUtil.errorFormatter + ); try { - const errors = validationResult(req).formatWith( - validatorUtil.errorFormatter - ); - if (!errors.isEmpty()) return res.status(422).json({ success: false, errors: errors.array() }); @@ -660,8 +627,6 @@ router.get( } ); -//------------------ above is tested - //refresh data, grab new builds router.post( "/updateList/:application_id", diff --git a/server/tests/unit/orbit.test.js b/server/tests/unit/orbit.test.js index 289e82cce..5e48298ff 100644 --- a/server/tests/unit/orbit.test.js +++ b/server/tests/unit/orbit.test.js @@ -212,13 +212,17 @@ describe("Integration Tests", () => { }); test("Get one", async () => { - response = await request(app).get(`/api/orbit/${application_id}/${id}`); + response = await request(app).get( + `/api/orbit/getOne/${application_id}/${id}` + ); expect(orbitMonitoring.findOne).toHaveBeenCalledTimes(1); expect(response.status).toBe(200); }); test("Get one - Bad ID", async () => { - response = await request(app).get(`/api/orbit/${badApplicationId}/${id}`); + response = await request(app).get( + `/api/orbit/getOne/${badApplicationId}/${id}` + ); expect(orbitMonitoring.findOne).toHaveBeenCalledTimes(0); expect(response.status).toBe(422); expect(response.body.success).toBe(false);