Skip to content

Commit

Permalink
Merge pull request #300 from agiledev-students-fall2023/Sprint/4/spik…
Browse files Browse the repository at this point in the history
…e/299

Sprint/4/spike/299
  • Loading branch information
basil-ahmed authored Nov 30, 2023
2 parents 96a7b96 + 2e394cf commit 9a712aa
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 334 deletions.
1 change: 0 additions & 1 deletion back-end/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import url from "url";
import path from "path";
import login from "./src/routes/login.js";
import studentIssues from "./src/routes/studentIssues.js";
import studentIssueViewDetails from "./src/routes/studentIssueViewDetails.js";
import studentIssueUpdate from "./src/routes/studentIssueUpdate.js";
import adminIssues from "./src/routes/adminIssues.js";
import adminIssueViewDetails from "./src/routes/adminIssueViewDetails.js";
Expand Down
4 changes: 2 additions & 2 deletions back-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"description": "The back-end of your project will live in this directory.",
"main": "index.js",
"scripts": {
"test": "NODE_ENV=test mocha test/**/*.test.js",
"test": "mocha test/**/*.test.js",
"start": "node server.js",
"dev": "nodemon server.js",
"lint": "eslint **/*.js",
"coverage": "NODE_ENV=test c8 mocha test/**/*.test.js"
"coverage": "c8 mocha test/**/*.test.js"
},
"keywords": [],
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion back-end/src/controllers/adminIssuesHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export async function issueRetrievalHandler(req, res) {
const { paramName } = req.params;

try {
// Check if issues exist for the department
const issues = await IssueModel.find({ "departments": paramName });

res.json(issues);
} catch (error) {
console.error("Error retrieving data:", error.message);
Expand Down
24 changes: 9 additions & 15 deletions back-end/src/controllers/studentIssueViewDetailsHandler.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
import Issue from '../../models/issueModel.js';

// The function retrieves all the issues related to this student
export async function studentIssueViewDetailsHandler(req, res) {
const { paramName } = req.params;
const { studentNetID } = req.params;
const { paramName } = req.params; // Get the issue index from request params
const { studentNetID } = req.params; // Get the studentNetID from request params

// Check if studentNetID is missing or invalid
if (!studentNetID) {
return res.status(400).send("Missing or invalid studentNetID.");
}

// Check if paramName (issue index) is missing or invalid
if (!paramName) {
return res.status(400).send("Missing or invalid issue index.");
}

try {
// Query the database to find issues that match both studentNetID and index
const response = await Issue.find({ studentNetID: studentNetID, index: paramName });

const response = await Issue.find({ index: paramName });

// Check if any data is returned for the student
// Check if no matching issues are found
if (!response || response.length === 0) {
return res.status(500).send("No issues found for the given studentNetID.");
}

// Check if the specific issue index exists
if (response.length === 0) {
return res.status(500).send("Issue with the given index not found.");
return res.status(500).send("No issues found for the given studentNetID and index.");
}

res.json(response); // Send only the data that matches the specific issue index
res.json(response);
} catch (error) {
// Log the error and send an appropriate response
console.error("Error retrieving data:", error.message);
res.status(500).send("An error occurred while retrieving the data.");
}
Expand Down
106 changes: 0 additions & 106 deletions back-end/test/adminIssueRetrieval.test.js

This file was deleted.

39 changes: 39 additions & 0 deletions back-end/test/adminIssues.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* eslint-disable */
import chai, { assert } from "chai";
import IssueModel from "../models/issueModel.js";
import chaiHttp from "chai-http";
import server from "../app.js";

chai.use(chaiHttp);

process.env.NODE_ENV = "test";

// Integration tests for the adminIssues.js file
describe("Integration Tests for Admin Issue Handler Endpoint", () => {
describe("GET /api/issues/admin/:paramName", () => {
it("should retrieve all issues for a valid admin user", async () => {
const paramName = "admin";
const res = await chai
.request(server)
.get(`/api/issues/admin/${paramName}`);
// Check that the response is correct
assert.equal(res.status, 200);
// Check that the response is an array
assert.isArray(res.body);
// Check that the response is the same length as the number of issues
const userIssues = await IssueModel.find({ "departments": paramName });
// Check that the response is the same length as the number of issues of that user
assert.equal(res.body.length, userIssues.length);
});

it("should handle errors gracefully for an invalid admin user", async () => {
const paramName = "invalid";
const res = await chai
.request(server)
.get(`/api/issues/admin/${paramName}`);
assert.equal(res.status, 200);
assert.deepEqual(res.body, []);
});
});
});
/* eslint-enable */
13 changes: 0 additions & 13 deletions back-end/test/dummy.test.js

This file was deleted.

2 changes: 2 additions & 0 deletions back-end/test/login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import chaiHttp from "chai-http";
import server from "../app.js";

chai.use(chaiHttp);
process.env.NODE_ENV = "test";

// Integration tests for the login.js file
describe("Integration Tests for Login Endpoints", () => {
// Check student login
Expand Down
Loading

0 comments on commit 9a712aa

Please sign in to comment.