Skip to content

Commit

Permalink
Merge branch 'Sprint/4/spike/295'
Browse files Browse the repository at this point in the history
  • Loading branch information
swostikpati committed Nov 30, 2023
2 parents 446c00f + 35ee9f3 commit 96a7b96
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 198 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ We decided to rotate the assignment of the following roles for each sprint.
* **Product Owner:** Basil Ahmed
* **Scrum Master:** Nada Elsharkawy

### Sprint 4
* **Product Owner:** Avinash Gyawali
* **Scrum Master:** Swostik Pati

## About
### Product Vision Statement
The NYUAD Issue Resolution Platform is envisioned as a transformative solution that streamlines and revolutionizes the way NYU Abu Dhabi students and administrative departments interact and resolve issues. Our vision is to create a transparent, efficient, and user-friendly web application that serves as a central hub for issue tracking and resolution. The platform will bridge the communication gap between students and departments, offering real-time insights, accountability, and enhanced collaboration.
Expand Down
2 changes: 1 addition & 1 deletion back-end/src/controllers/createIssueHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function createIssueHandler(req, res) {
description: req.body.issueDesc,
attachments: attachments,
departments: req.body.deptTagged.includes(',') ? req.body.deptTagged.split(',') : [req.body.deptTagged],
comments: [null],
comments: [],
dateCreated: issueDateCreated,
timeCreated: issueTimeCreated,
currentStatus:'Open',
Expand Down
23 changes: 0 additions & 23 deletions back-end/src/controllers/loginHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@ import bcrypt from "bcryptjs";
import User from "../../models/UserModel.js";
import jwt from "jsonwebtoken";

// Previous Hardcoded values
// const student = { username: "s", password: "1" };
// const admin = { username: "a", password: "1" };

export async function loginStudentHandler(req, res) {
// previous implementation
// if (
// req.body.username === student.username &&
// req.body.password === student.password
// ) {
// res.status(200).json({ authenticated: true });
// } else {
// res.status(200).json({ authenticated: false });
// }

try {
const { username, password } = req.body;
// for case insensitive search
Expand Down Expand Up @@ -54,15 +40,6 @@ export async function loginStudentHandler(req, res) {
}

export async function loginAdminHandler(req, res) {
// if (
// req.body.username === admin.username &&
// req.body.password === admin.password
// ) {
// res.json({ authenticated: true });
// } else {
// res.json({ authenticated: false });
// }

try {
const { username, password } = req.body;
// for case insensitive search
Expand Down
10 changes: 10 additions & 0 deletions back-end/src/controllers/studentIssuesHandler.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import IssueModel from '../../models/issueModel.js';
import User from "../../models/UserModel.js";

export async function issueRetrievalHandler(req, res) {
const { paramName } = req.params;

try {
// Check if user exists
const user = await User.findOne({
netId: paramName
});
// If user does not exist, return error
if (!user) { res.status(500).send("User does not exist.");}
// If user exists, return all issues for that user
else {
const issues = await IssueModel.find({ "studentNetID": paramName });
res.json(issues);
}
} catch (error) {
console.error("Error retrieving data:", error.message);
res.status(500).send("An error occurred while retrieving the data.");
Expand Down
94 changes: 26 additions & 68 deletions back-end/test/login.test.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,29 @@
/* eslint-disable */

import chai, { assert } from "chai";
import sinon from "sinon";
import {
loginStudentHandler,
loginAdminHandler
} from "../src/controllers/loginHandler.js";

// Unit Testing
describe("Unit Tests for Login Handlers", () => {
let req, res, statusSpy, jsonSpy;

beforeEach(() => {
req = { body: {} };
res = {
json: () => {},
status: function (s) {
this.statusCode = s;
return this;
}
};
statusSpy = sinon.spy(res, "status");
jsonSpy = sinon.spy(res, "json");
});

afterEach(() => {
statusSpy.restore();
jsonSpy.restore();
});

describe("loginStudentHandler", () => {
it("should authenticate valid student credentials", () => {
req.body = { username: "s", password: "1" };
loginStudentHandler(req, res);
assert(statusSpy.calledWith(200));
assert(jsonSpy.calledWith({ authenticated: true }));
});

it("should not authenticate invalid student credentials", () => {
req.body = { username: "wrong", password: "user" };
loginStudentHandler(req, res);
assert(statusSpy.calledWith(200));
assert(jsonSpy.calledWith({ authenticated: false }));
});
});

describe("loginAdminHandler", () => {
it("should authenticate valid admin credentials", () => {
req.body = { username: "a", password: "1" };
loginAdminHandler(req, res);
assert(jsonSpy.calledWith({ authenticated: true }));
});

it("should not authenticate invalid admin credentials", () => {
req.body = { username: "wrong", password: "user" };
loginAdminHandler(req, res);
assert(jsonSpy.calledWith({ authenticated: false }));
});
});
});

//Integration Testing

import chaiHttp from "chai-http";
import server from "../app.js";

chai.use(chaiHttp);

// Integration tests for the login.js file
describe("Integration Tests for Login Endpoints", () => {
// Check student login
describe("POST /api/login/student", () => {
it("should authenticate student with correct credentials", async () => {
const res = await chai
.request(server)
.post("/api/login/student")
.send({ username: "s", password: "1" });
.send({ username: "student", password: "student" });
// Check that the response is correct
assert.equal(res.status, 200);
assert.deepEqual(res.body, { authenticated: true });
// Check if response matches expected response
assert.deepEqual(res.body, {
"__v": 0,
authenticated: true,
name: "student",
netId: "student",
userDept: "student",
userType: "student",
});
});

it("should not authenticate student with incorrect credentials", async () => {
Expand All @@ -84,18 +32,28 @@ describe("Integration Tests for Login Endpoints", () => {
.post("/api/login/student")
.send({ username: "wrong", password: "user" });
assert.equal(res.status, 200);
assert.deepEqual(res.body, { authenticated: false });
assert.deepEqual(res.body, { authenticated: false});
});
});

describe("POST /api/login/admin", () => {
// Check admin login
it("should authenticate admin with correct credentials", async () => {
const res = await chai
.request(server)
.post("/api/login/admin")
.send({ username: "a", password: "1" });
.send({ username: "admin", password: "admin" });
// Check that the response is correct
assert.equal(res.status, 200);
assert.deepEqual(res.body, { authenticated: true });
// Check if response matches expected response
assert.deepEqual(res.body, {
"__v": 0,
authenticated: true,
name: "admin",
netId: "admin",
userDept: "admin",
userType: "admin",
});
});

it("should not authenticate admin with incorrect credentials", async () => {
Expand Down
106 changes: 0 additions & 106 deletions back-end/test/studentIssueRetrieval.test.js

This file was deleted.

37 changes: 37 additions & 0 deletions back-end/test/studentIssuesHandler.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* 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);

// Integration tests for the studentIssuesHandler.js file
describe("Integration Tests for Student Issue Handler Endpoint", () => {
describe("GET /api/issues/student/:paramName", () => {
it("should retrieve all issues for a valid student NetID", async () => {
const paramName = "student";
const res = await chai
.request(server)
.get(`/api/issues/student/${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({ "studentNetID": 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 student NetID", async () => {
const paramName = "invalidStudentNetID";
const res = await chai
.request(server)
.get(`/api/issues/student/${paramName}`);
assert.equal(res.status, 500);
assert.equal(res.text, "User does not exist.");
});
});
});

/* eslint-enable */

0 comments on commit 96a7b96

Please sign in to comment.