Skip to content

Commit

Permalink
Merge branch 'main' into 86
Browse files Browse the repository at this point in the history
  • Loading branch information
86LAK committed May 6, 2024
2 parents 124b53e + fd3bbb5 commit 471bc1e
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 12 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ This project is brought to you by the Evan Hughes FanClub. Our team consists of:
- [Shanon Lakshan Chandrasekara](https://github.com/86LAK)
- [Jackson Trenarry](https://github.com/JTrenarry)
- [Olivia Ronda](https://github.com/vilnor)
- [Ibrahim Cassim](https://github.com/IbrahimCassim)

### DevOps

- [Shanon Lakshan Chandrasekara](https://github.com/86LAK)

### QUT Guy Who Has Vanished?
- [Ibrahim Cassim](https://github.com/IbrahimCassim)

## Deployment

Deployment of UniBasement is managed via the GitHub Actions. This is the recommended and easiest way to deploy the application and automatically preserve the state files. The GitHub actions utilise and manage its state files in AWS via an S3 bucket.
Expand Down
11 changes: 6 additions & 5 deletions backend/src/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ router.patch('/courses/:courseCode/star', async (req: Request<CourseRouteParams>
const { courseCode } = req.params;
const { starRating, userId } = req.body;

if (!starRating || !userId) {
if (starRating === undefined || !userId) {
res.status(400).json('Missing starRating or userId');
return;
}

// Checks to see star rating is between 1 and 5
if (starRating < 1 || starRating > 5) {
res.status(400).json('Star rating must be between 1 and 5');
if (starRating < 0 || starRating > 5) {
res.status(400).json('Star rating must be between 0 and 5');
return;
}

Expand Down Expand Up @@ -367,6 +367,7 @@ router.post('/users', async (req: Request<any, any, any, any>, res: Response) =>
const { rowCount } = await db.query(`
INSERT INTO users ("userId")
VALUES ($1)
ON CONFLICT DO NOTHING
`, [userId]);

if (rowCount === 0) {
Expand Down Expand Up @@ -643,7 +644,7 @@ router.get('/courses/:courseCode', async (req: Request<CourseRouteParams>, res:
const { courseCode } = req.params;

const { rows } = await db.query<Course>(`
SELECT "courseCode", "courseName", "courseDescription", "university"
SELECT "courseCode", "courseName", "courseDescription", "university", "stars", "votes"
FROM courses
WHERE courses."courseCode" = $1
`, [courseCode]);
Expand All @@ -662,7 +663,7 @@ router.get('/courses', async (req: Request<any, any, any, CourseQueryParams>, re
const limit = req.query.limit ?? 100;

const { rows } = await db.query<Course>(`
SELECT "courseCode", "courseName", "courseDescription", "university"
SELECT "courseCode", "courseName", "courseDescription", "university", "stars", "votes"
FROM courses
LIMIT $1
OFFSET $2
Expand Down
146 changes: 141 additions & 5 deletions integration_tests/test_courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ def test_course_get_course(self):
"courseCode": "ENGG1001",
"courseName": "Programming for Engineers",
"courseDescription": "An introductory course covering basic concepts of software engineering.",
"university": "UQ"
"university": "UQ",
"stars": 0,
"votes": 0
}

response = requests.get(self.host() + '/courses/' + courseCode)
Expand All @@ -120,9 +122,9 @@ def test_course_get_all(self):
Checks for the correct response message
"""
expectedCourses = [
{"courseCode": "ENGG1001", "courseName": "Programming for Engineers", "courseDescription": "An introductory course covering basic concepts of software engineering.", "university": "UQ"},
{"courseCode": "ENGG1100", "courseName": "Professional Engineering", "courseDescription": "An introductory course covering fundamental concepts in engineering principles.", "university": "UQ"},
{"courseCode": "MATH1051", "courseName": "Calculus & Linear Algebra", "courseDescription": "A foundational course in calculus covering limits, derivatives, and integrals.", "university": "UQ"}
{"courseCode": "ENGG1001", "courseName": "Programming for Engineers", "courseDescription": "An introductory course covering basic concepts of software engineering.", "university": "UQ", "stars": 0, "votes": 0},
{"courseCode": "ENGG1100", "courseName": "Professional Engineering", "courseDescription": "An introductory course covering fundamental concepts in engineering principles.", "university": "UQ", "stars": 0, "votes": 0},
{"courseCode": "MATH1051", "courseName": "Calculus & Linear Algebra", "courseDescription": "A foundational course in calculus covering limits, derivatives, and integrals.", "university": "UQ", "stars": 0, "votes": 0},
]

response = requests.get(self.host() + '/courses')
Expand All @@ -133,8 +135,142 @@ def test_course_get_all(self):
self.assertIn(expectedCourse, response.json())


def test_course_patch_star(self):
"""
Checks for a 200 response from the /courses/:courseCode/star endpoint
Checks for the correct response message
"""
course_data = {
"courseCode": "STAR1001",
"courseName": "Stargazing",
"courseDescription": "An introductory course covering basic concepts of astronomy.",
"university": "UQ"
}

# Make a new course
response = requests.post(self.host() + '/courses', json=course_data, headers={'Accept': 'application/json'})
self.assertEqual(201, response.status_code)

user = {
"userId": "stars",
}

# Make a new user
response = requests.post(self.host() + '/users', json=user)
self.assertEqual(201, response.status_code)

stars = {
"starRating": 5,
"userId": "stars",
}


response = requests.patch(self.host() + '/courses/' + 'STAR1001' + '/star', json=stars)
self.assertEqual(200, response.status_code)
self.assertEqual('Course starred', response.json())

response = requests.get(self.host() + '/courses/' + 'STAR1001')
self.assertEqual(200, response.status_code)
self.assertEqual(5, response.json()['stars'])

stars = {
"starRating": 3,
"userId": "stars",
}

response = requests.patch(self.host() + '/courses/' + 'STAR1001' + '/star', json=stars)
self.assertEqual(200, response.status_code)
self.assertEqual('Course starred', response.json())

response = requests.get(self.host() + '/courses/' + 'STAR1001')
self.assertEqual(200, response.status_code)
self.assertEqual(3, response.json()['stars'])

def test_course_patch_star_miss(self):
"""
Checks for a 400 response from the /courses/:courseCode/star endpoint
Checks for the correct response message
"""
stars = {
"starRating": 5,
}

response = requests.patch(self.host() + '/courses/' + 'STAR2001' + '/star', json=stars)
self.assertEqual(400, response.status_code)
self.assertEqual('Missing starRating or userId', response.json())

stars = {
"userId": "stars",
}

response = requests.patch(self.host() + '/courses/' + 'STAR2001' + '/star', json=stars)
self.assertEqual(400, response.status_code)
self.assertEqual('Missing starRating or userId', response.json())


def test_course_patch_bad_star(self):
"""
Checks for a 400 response from the /courses/:courseCode/star endpoint
Checks for the correct response message
"""

stars = {
"starRating": 6,
"userId": "stars",
}


response = requests.patch(self.host() + '/courses/' + 'STAR1001' + '/star', json=stars)
self.assertEqual(400, response.status_code)
self.assertEqual('Star rating must be between 0 and 5', response.json())

stars = {
"starRating": -1,
"userId": "stars",
}

response = requests.patch(self.host() + '/courses/' + 'STAR1001' + '/star', json=stars)
self.assertEqual(400, response.status_code)
self.assertEqual('Star rating must be between 0 and 5', response.json())


def test_course_patch_star_user(self):
"""
Checks for a 404 response from the /courses/:courseCode/star endpoint
Checks for the correct response message
"""
stars = {
"starRating": 5,
"userId": "stari",
}


response = requests.patch(self.host() + '/courses/' + 'STAR1001' + '/star', json=stars)
self.assertEqual(404, response.status_code)
self.assertEqual('User not found', response.json())

def test_course_patch_star_course(self):
"""
Checks for a 404 response from the /courses/:courseCode/star endpoint
Checks for the correct response message
"""
user = {
"userId": "stary",
}

# Make a new user
response = requests.post(self.host() + '/users', json=user)
self.assertEqual(201, response.status_code)

stars = {
"starRating": 5,
"userId": "stary",
}

response = requests.patch(self.host() + '/courses/' + 'STAR2401' + '/star', json=stars)
self.assertEqual(404, response.status_code)
self.assertEqual('Course not found', response.json())


if __name__ == '__main__':
unittest.main()
unittest.main()
4 changes: 3 additions & 1 deletion integration_tests/test_full_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def test_full_1(self):
"courseName": "The History of Toyota 86",
"courseDescription": "A course on the history of the Toyota 86 and its impact on the automotive industry.",
"university": "The University of Queensland",
"stars": 0,
"votes": 0
}

# Create a course
Expand Down Expand Up @@ -355,4 +357,4 @@ def test_full_1(self):


if __name__ == '__main__':
unittest.main()
unittest.main()
59 changes: 59 additions & 0 deletions integration_tests/test_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import unittest
import requests

from .base import BaseCase


class TestUser(BaseCase):

def test_user_post(self):
"""
Checks for a 201 response from the /courses endpoint
Checks for the correct response message
"""
user_data = {
"userId": "EVANs",
}

response = requests.post(self.host() + '/users', json=user_data, headers={'Accept': 'application/json'})

self.assertEqual(201, response.status_code)
self.assertEqual("User Added", response.json())


def test_user_post_missing(self):
"""
Checks for a 201 response from the /courses endpoint
Checks for the correct response message
"""
user_data = {
"filler": "meow",
}

response = requests.post(self.host() + '/users', json=user_data, headers={'Accept': 'application/json'})

self.assertEqual(400, response.status_code)
self.assertEqual("Missing userId", response.json())


def test_user_post_double(self):
"""
Checks for a 201 response from the /courses endpoint
Checks for the correct response message
"""
user_data = {
"userId": "DoughBell",
}

response = requests.post(self.host() + '/users', json=user_data, headers={'Accept': 'application/json'})

self.assertEqual(201, response.status_code)
self.assertEqual("User Added", response.json())

response = requests.post(self.host() + '/users', json=user_data, headers={'Accept': 'application/json'})

self.assertEqual(409, response.status_code)
self.assertEqual("User already exists", response.json())

if __name__ == '__main__':
unittest.main()

0 comments on commit 471bc1e

Please sign in to comment.