Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FancMa01 committed Jan 30, 2024
1 parent 7ef3c69 commit 9860ece
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
63 changes: 14 additions & 49 deletions server/routes/orbit/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
},
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -471,6 +472,8 @@ router.put(
}
);

// EVERYTHING ABOVE THIS WORKS WITH APP ID VALIDATION

// Pause or start monitoring
router.put(
"/togglestatus/:id",
Expand Down Expand Up @@ -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,
});

Expand All @@ -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() });

Expand Down Expand Up @@ -660,8 +627,6 @@ router.get(
}
);

//------------------ above is tested

//refresh data, grab new builds
router.post(
"/updateList/:application_id",
Expand Down
8 changes: 6 additions & 2 deletions server/tests/unit/orbit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9860ece

Please sign in to comment.