From 7422427968b66fdbd636e2e05b533c1f9748509c Mon Sep 17 00:00:00 2001 From: "86.LAK" Date: Thu, 2 May 2024 23:37:36 +1000 Subject: [PATCH 01/20] removing unused import and creating full suite file --- integration_tests/test_comments.py | 1 - integration_tests/test_courses.py | 1 - integration_tests/test_exams.py | 1 - integration_tests/test_full_suite.py | 19 +++++++++++++++++++ integration_tests/test_questions.py | 1 - 5 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 integration_tests/test_full_suite.py diff --git a/integration_tests/test_comments.py b/integration_tests/test_comments.py index b5b6f10..623ee2b 100644 --- a/integration_tests/test_comments.py +++ b/integration_tests/test_comments.py @@ -1,6 +1,5 @@ import unittest import requests -import random from .base import BaseCase diff --git a/integration_tests/test_courses.py b/integration_tests/test_courses.py index e116a0a..6c31806 100644 --- a/integration_tests/test_courses.py +++ b/integration_tests/test_courses.py @@ -1,6 +1,5 @@ import unittest import requests -import random from .base import BaseCase diff --git a/integration_tests/test_exams.py b/integration_tests/test_exams.py index c9bb4de..c494f6c 100644 --- a/integration_tests/test_exams.py +++ b/integration_tests/test_exams.py @@ -1,6 +1,5 @@ import unittest import requests -import random from .base import BaseCase diff --git a/integration_tests/test_full_suite.py b/integration_tests/test_full_suite.py new file mode 100644 index 0000000..623ee2b --- /dev/null +++ b/integration_tests/test_full_suite.py @@ -0,0 +1,19 @@ +import unittest +import requests + +from .base import BaseCase + + +class TestUser(BaseCase): + def test_evan(self): + """ + Checks for a 200 response from the evan endpoint + """ + response = requests.get(self.host() + '/evan', headers={'Accept': 'application/json'}) + self.assertEqual(200, response.status_code) + + + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/integration_tests/test_questions.py b/integration_tests/test_questions.py index 78e0ac1..4646498 100644 --- a/integration_tests/test_questions.py +++ b/integration_tests/test_questions.py @@ -1,6 +1,5 @@ import unittest import requests -import random from .base import BaseCase From 7ba55019602abfc902c0aedbe0aa1f787457860e Mon Sep 17 00:00:00 2001 From: "86.LAK" Date: Fri, 3 May 2024 01:16:03 +1000 Subject: [PATCH 02/20] writing tests for questions and fixing http responses and messages from routes --- backend/src/routes/routes.ts | 4 +- integration_tests/test_comments.py | 2 +- integration_tests/test_courses.py | 2 +- integration_tests/test_exams.py | 2 +- integration_tests/test_full_suite.py | 2 +- integration_tests/test_questions.py | 78 +++++++++++++++++++++++++--- 6 files changed, 76 insertions(+), 14 deletions(-) diff --git a/backend/src/routes/routes.ts b/backend/src/routes/routes.ts index bc54bee..70e2463 100644 --- a/backend/src/routes/routes.ts +++ b/backend/src/routes/routes.ts @@ -69,11 +69,11 @@ router.put('/questions/:questionId/edit', async (req: Request Date: Fri, 3 May 2024 01:26:30 +1000 Subject: [PATCH 03/20] changed some http to match standardised meanings --- backend/src/routes/routes.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/src/routes/routes.ts b/backend/src/routes/routes.ts index cf6b25a..fa1ab21 100644 --- a/backend/src/routes/routes.ts +++ b/backend/src/routes/routes.ts @@ -64,16 +64,16 @@ router.put('/questions/:questionId/edit', async (req: Request Date: Fri, 3 May 2024 01:32:14 +1000 Subject: [PATCH 04/20] the fix that didnt get merged??? --- backend/src/routes/routes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/routes/routes.ts b/backend/src/routes/routes.ts index fa1ab21..0d8679d 100644 --- a/backend/src/routes/routes.ts +++ b/backend/src/routes/routes.ts @@ -64,7 +64,7 @@ router.put('/questions/:questionId/edit', async (req: Request Date: Fri, 3 May 2024 01:48:53 +1000 Subject: [PATCH 05/20] fixed bad url for questions --- integration_tests/test_questions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration_tests/test_questions.py b/integration_tests/test_questions.py index bace605..9935dfc 100644 --- a/integration_tests/test_questions.py +++ b/integration_tests/test_questions.py @@ -18,7 +18,7 @@ def test_edit_question_successful(self): "questionPNG": None } - response = requests.put(self.host() + '/questions' + str(questionId) + '/edit', json=body) + response = requests.put(self.host() + '/questions/' + str(questionId) + '/edit', json=body) self.assertEqual(200, response.status_code) self.assertEqual('Question edited', response.json()) @@ -31,7 +31,7 @@ def test_edit_question_invalid_id(self): "questionType": "Multiple Choice", "questionPNG": None } - response = requests.put(self.host() + '/questions' + str(questionId) + '/edit', json=body) + response = requests.put(self.host() + '/questions/' + str(questionId) + '/edit', json=body) self.assertEqual(404, response.status_code) self.assertEqual('Question not found', response.json()) From 8fbeffcc50b917e3ed645404905a95c4133fe557 Mon Sep 17 00:00:00 2001 From: "86.LAK" Date: Fri, 3 May 2024 01:51:04 +1000 Subject: [PATCH 06/20] updated questions table to handle created and updated at flags --- backend/src/db/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/db/index.ts b/backend/src/db/index.ts index 9c66af7..b193d36 100644 --- a/backend/src/db/index.ts +++ b/backend/src/db/index.ts @@ -33,7 +33,9 @@ export const setupTables = () => { "examId" INTEGER REFERENCES exams("examId"), "questionText" TEXT, "questionPNG" BYTEA, - "questionType" VARCHAR(20) + "questionType" VARCHAR(20), + "created_at" TIMESTAMP DEFAULT NOW(), + "updated_at" TIMESTAMP DEFAULT NOW() ); CREATE TABLE IF NOT EXISTS comments ( From 73348ad1dc972369320b75ce793698f717472349 Mon Sep 17 00:00:00 2001 From: "86.LAK" Date: Fri, 3 May 2024 01:51:48 +1000 Subject: [PATCH 07/20] included updated at in to edits question put --- backend/src/routes/routes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/routes/routes.ts b/backend/src/routes/routes.ts index 0d8679d..9d8f4aa 100644 --- a/backend/src/routes/routes.ts +++ b/backend/src/routes/routes.ts @@ -64,7 +64,7 @@ router.put('/questions/:questionId/edit', async (req: Request Date: Fri, 3 May 2024 01:58:34 +1000 Subject: [PATCH 08/20] wrote test cases for put request for questions --- backend/src/routes/routes.ts | 6 ++-- integration_tests/test_questions.py | 45 ++++++++--------------------- 2 files changed, 15 insertions(+), 36 deletions(-) diff --git a/backend/src/routes/routes.ts b/backend/src/routes/routes.ts index 9d8f4aa..3e678e6 100644 --- a/backend/src/routes/routes.ts +++ b/backend/src/routes/routes.ts @@ -38,7 +38,7 @@ router.put('/questions/:questionId/edit', async (req: Request Date: Fri, 3 May 2024 12:17:00 +1000 Subject: [PATCH 09/20] better names for question routes --- integration_tests/test_questions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integration_tests/test_questions.py b/integration_tests/test_questions.py index e10ce68..75b6511 100644 --- a/integration_tests/test_questions.py +++ b/integration_tests/test_questions.py @@ -5,7 +5,7 @@ class TestQuestions(BaseCase): - def test_edit_question_successful(self): + def test_put_edit_question_successful(self): """ Check for a 201 response from the /questions endpoint Check for the correct response message @@ -23,7 +23,7 @@ def test_edit_question_successful(self): self.assertEqual(200, response.status_code) self.assertEqual('Question edited', response.json()) - def test_edit_question_invalid_id(self): + def test_put_edit_question_invalid_id(self): questionId = 8686 body = { "questionId": questionId, @@ -35,7 +35,7 @@ def test_edit_question_invalid_id(self): self.assertEqual(404, response.status_code) self.assertEqual('Question not found', response.json()) - def test_edit_question_no_changes(self): + def test_put_edit_question_no_changes(self): # Test editing a question with no changes # Make a PUT request without providing any changes # Check that the response status code is 400 From 21be7e81eb2671bd2a13217e29a447be56229cb8 Mon Sep 17 00:00:00 2001 From: "86.LAK" Date: Fri, 3 May 2024 12:17:56 +1000 Subject: [PATCH 10/20] better commenting on what each questions test tests --- integration_tests/test_questions.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/integration_tests/test_questions.py b/integration_tests/test_questions.py index 75b6511..18eaeb7 100644 --- a/integration_tests/test_questions.py +++ b/integration_tests/test_questions.py @@ -23,7 +23,12 @@ def test_put_edit_question_successful(self): self.assertEqual(200, response.status_code) self.assertEqual('Question edited', response.json()) + def test_put_edit_question_invalid_id(self): + """ + Check for a 404 response from the /questions endpoint + Check for the correct response message + """ questionId = 8686 body = { "questionId": questionId, @@ -35,11 +40,12 @@ def test_put_edit_question_invalid_id(self): self.assertEqual(404, response.status_code) self.assertEqual('Question not found', response.json()) + def test_put_edit_question_no_changes(self): - # Test editing a question with no changes - # Make a PUT request without providing any changes - # Check that the response status code is 400 - # Verify that the response message indicates no changes were made + """ + Check for a 400 response from the /questions endpoint + Check for the correct response message + """ questionId = 1 body = { "questionId": None, From 29608f514d54424f39dbaeeda83870d4351a10c5 Mon Sep 17 00:00:00 2001 From: "86.LAK" Date: Fri, 3 May 2024 12:25:33 +1000 Subject: [PATCH 11/20] tests for post question completed --- integration_tests/test_questions.py | 56 ++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/integration_tests/test_questions.py b/integration_tests/test_questions.py index 18eaeb7..87d160a 100644 --- a/integration_tests/test_questions.py +++ b/integration_tests/test_questions.py @@ -59,7 +59,61 @@ def test_put_edit_question_no_changes(self): self.assertEqual('No changes made', response.json()) - #TODO finished the first route for questions. so the rest need to be done + def test_post_add_question_successful(self): + """ + Check for a 201 response from the /questions endpoint + Check for the correct response message + """ + body = { + "examId": 1, + "questionText": "Do you use Arch?", + "questionType": "Multiple Choice", + "questionPNG": None + } + + response = requests.post(self.host() + '/questions', json=body) + self.assertEqual(201, response.status_code) + self.assertEqual('Question added', response.json()) + + + def test_post_add_question_invalid_exam_id(self): + """ + Check for a 404 response from the /questions endpoint + Check for the correct response message + """ + body = { + "examId": 868686, + "questionText": "This question is going to an invalid examId", + "questionType": "Multiple Choice", + "questionPNG": None + } + + response = requests.post(self.host() + '/questions', json=body) + self.assertEqual(404, response.status_code) + self.assertEqual('ExamId not found', response.json()) + + + def test_post_add_question_no_exam_id(self): + """ + Check for a 400 response from the /questions endpoint + Check for the correct response message + """ + body = { + "examId": None, + "questionText": "This question is going to an invalid examId", + "questionType": "Multiple Choice", + "questionPNG": None + } + + response = requests.post(self.host() + '/questions', json=body) + self.assertEqual(400, response.status_code) + self.assertEqual('ExamId not found', response.json()) + + + + + + if __name__ == '__main__': unittest.main() From ad0d8482ac4aca6b30730dc06d5508eab56bfb95 Mon Sep 17 00:00:00 2001 From: "86.LAK" Date: Fri, 3 May 2024 15:42:31 +1000 Subject: [PATCH 12/20] all question routes except last tested. included new question in test data for one with no comments --- backend/src/routes/routes.ts | 73 ++++++++------ integration_tests/test_courses.py | 4 +- integration_tests/test_questions.py | 148 +++++++++++++++++++++++++++- 3 files changed, 194 insertions(+), 31 deletions(-) diff --git a/backend/src/routes/routes.ts b/backend/src/routes/routes.ts index 3e678e6..2da7580 100644 --- a/backend/src/routes/routes.ts +++ b/backend/src/routes/routes.ts @@ -81,17 +81,17 @@ router.put('/comments/:commentId/edit', async (req: Request, res: // Check key if (!questionId) { - res.status(400).json('Missing questionId!'); + res.status(400).json('Missing questionId'); return; } const { rowCount } = await db.query(`SELECT "questionId" FROM questions WHERE "questionId" = $1`, [questionId]); if (rowCount === 0) { - res.status(404).json('Question not found!'); + res.status(404).json('Question not found'); return; } @@ -220,12 +220,12 @@ router.post('/comments', async (req: Request, res: if (parentCommentId) { const { rowCount, rows } = await db.query>(`SELECT "commentId", "questionId" FROM comments WHERE "commentId" = $1`, [parentCommentId]); if (rowCount === 0) { - res.status(404).json('Parent comment not found!'); + res.status(404).json('Parent comment not found'); return; } const parentComment = rows[0]; if (parentComment.questionId !== questionId) { - res.status(400).json('Parent comment is not from the same question!'); + res.status(400).json('Parent comment is not from the same question'); return; } } @@ -235,7 +235,7 @@ router.post('/comments', async (req: Request, res: VALUES ($1, $2, $3, $4, $5, $6, $7, $8) `, [questionId, parentCommentId, commentText, commentPNG, isCorrect, isEndorsed, upvotes, downvotes]); - res.status(201).json('Comment Added!'); + res.status(201).json('Comment Added'); }); // Adds a new question to the database @@ -249,13 +249,13 @@ router.post('/questions', async (req: Request, res // Check key if (!examId) { - res.status(400).json('Missing examId!'); + res.status(400).json('Missing examId'); return; } const { rowCount } = await db.query(`SELECT "examId" FROM exams WHERE "examId" = $1`, [examId]); if (rowCount === 0) { - res.status(404).json('Exam not found!'); + res.status(404).json('ExamId not found'); return; } @@ -264,7 +264,7 @@ router.post('/questions', async (req: Request, res VALUES ($1, $2, $3, $4) `, [examId, questionText, questionType, questionPNG]); - res.status(201).json('Question Added!'); + res.status(201).json('Question added'); }); // Adds a new exam to the database @@ -320,7 +320,7 @@ router.post('/courses', async (req: Request, res: Re VALUES ($1, $2, $3) `, [courseCode, courseName, courseDescription]); - res.status(201).json('Course Added!'); + res.status(201).json('Course Added'); }); /* @@ -348,15 +348,27 @@ router.get('/comments/:commentId', async (req: Request, res: router.get('/questions/:questionId/comments', async (req: Request, res: Response) => { const { questionId } = req.params; + // Check if the questionId exists in the database + const { rows : questionRows } = await db.query(` + SELECT "questionId" + From questions + WHERE "questionId" = $1 + `, [questionId]); + + if (questionRows.length === 0) { + return res.status(404).json({ error: 'Question not found' }); + } + const { rows } = await db.query(` - SELECT "commentId", "parentCommentId", "commentText", "commentPNG", "isCorrect", "isEndorsed", "upvotes", "downvotes", "created_at", "updated_at" - FROM comments - WHERE comments."questionId" = $1 + SELECT "commentId", "parentCommentId", "commentText", "commentPNG", "isCorrect", "isEndorsed", "upvotes", "downvotes", "created_at", "updated_at" + FROM comments + WHERE comments."questionId" = $1 `, [questionId]); res.status(200).json(nest(rows)); }); +//TODO this // Gets question information by question id router.get('/questions/:questionId', async (req: Request, res: Response) => { const { questionId } = req.params; @@ -367,7 +379,11 @@ router.get('/questions/:questionId', async (req: Request, r WHERE questions."questionId" = $1 `, [questionId]); - res.status(200).json(rows[0]); + if (rows.length === 0) { + return res.status(404).json({ error: "Question not found" }); + } + + res.status(200).json(rows[0]); }); // Exam questions by exam ID @@ -472,7 +488,7 @@ router.get('/evan', async (req: Request, res: Response) => { router.get('/sketch', async (req: Request, res: Response) => { const b = await db.query1('SELECT "examId" FROM exams WHERE "examId" = 1'); if (b.rows.length != 0) { - res.status(400).json('Data already exists!'); + res.status(400).json('Data already exists'); return } @@ -511,7 +527,8 @@ router.get('/sketch', async (req: Request, res: Response) => { VALUES (1, 'Who is the best tutor at UQ?', 'Multiple Choice'), (2, 'Who is not the best tutor at UQ?', 'Multiple Choice'), - (3, 'Who is the second best tutor at UQ?', 'Multiple Choice'); + (3, 'Who is the second best tutor at UQ?', 'Multiple Choice'), + (4, 'A question with no comments', 'Multiple Choice'); INSERT INTO comments ("questionId", "parentCommentId", "commentText", "isCorrect", "isEndorsed", "upvotes", "downvotes") VALUES diff --git a/integration_tests/test_courses.py b/integration_tests/test_courses.py index a94eb94..1ffd5ca 100644 --- a/integration_tests/test_courses.py +++ b/integration_tests/test_courses.py @@ -21,7 +21,7 @@ def test_course_post(self): self.assertEqual(201, response.status_code) - self.assertEqual('Course Added!', response.json()) + self.assertEqual('Course Added', response.json()) def test_course_post_null_coursecode(self): """ @@ -55,7 +55,7 @@ def test_course_post_duplicate_coursecode(self): response = requests.post(self.host() + '/courses', json=course_data, headers={'Accept': 'application/json'}) # Should post the course fine the first time self.assertEqual(201, response.status_code) - self.assertEqual('Course Added!', response.json()) + self.assertEqual('Course Added', response.json()) # Should error as duplicate when posting same course again. response = requests.post(self.host() + '/courses', json=course_data, headers={'Accept': 'application/json'}) diff --git a/integration_tests/test_questions.py b/integration_tests/test_questions.py index 87d160a..38c8db3 100644 --- a/integration_tests/test_questions.py +++ b/integration_tests/test_questions.py @@ -107,12 +107,158 @@ def test_post_add_question_no_exam_id(self): response = requests.post(self.host() + '/questions', json=body) self.assertEqual(400, response.status_code) - self.assertEqual('ExamId not found', response.json()) + self.assertEqual('Missing examId', response.json()) + + +# expected response for get question infromation by question id + + def test_get_question_by_questionId(self): + """ + Check for a 200 response from the /questions endpoint + Check for the correct response message + """ + questionId = 1 + expectedResponse = [ + { + "commentId": 1, + "parentCommentId": None, + "commentText": "Evan Hughes", + "commentPNG": None, + "isCorrect": True, + "isEndorsed": True, + "upvotes": 100, + "downvotes": 1, + "created_at": "2024-05-03T02:36:21.849Z", + "updated_at": "2024-05-03T02:36:21.849Z", + "children": [ + { + "commentId": 2, + "parentCommentId": 1, + "commentText": "Are you stupid it is clearly Liv Ronda", + "commentPNG": None, + "isCorrect": False, + "isEndorsed": False, + "upvotes": 0, + "downvotes": 100, + "created_at": "2024-05-03T02:36:21.849Z", + "updated_at": "2024-05-03T02:36:21.849Z", + "children": [ + { + "commentId": 3, + "parentCommentId": 2, + "commentText": "Bro went to stupid school L", + "commentPNG": None, + "isCorrect": False, + "isEndorsed": True, + "upvotes": 999, + "downvotes": 1, + "created_at": "2024-05-03T02:36:21.849Z", + "updated_at": "2024-05-03T02:36:21.849Z" + } + ] + }, + { + "commentId": 4, + "parentCommentId": 1, + "commentText": "Fax what a goat", + "commentPNG": None, + "isCorrect": False, + "isEndorsed": False, + "upvotes": 80, + "downvotes": 1, + "created_at": "2024-05-03T02:36:21.849Z", + "updated_at": "2024-05-03T02:36:21.849Z" + } + ] + } + ] + + response = requests.get(self.host() + '/questions/' + str(questionId) + '/comments') + + def update_timestamps(response_dict, created_at, updated_at): + if isinstance(response_dict, list): + for item in response_dict: + update_timestamps(item, created_at, updated_at) + elif isinstance(response_dict, dict): + if 'created_at' in response_dict: + response_dict['created_at'] = created_at + if 'updated_at' in response_dict: + response_dict['updated_at'] = updated_at + for key, value in response_dict.items(): + if isinstance(value, (list, dict)): + update_timestamps(value, created_at, updated_at) + + update_timestamps(expectedResponse, response.json()[0]['created_at'], response.json()[0]['updated_at']) + + self.assertEqual(200, response.status_code) + self.assertEqual(expectedResponse, response.json()) + + + def test_get_question_by_invalid_questionId(self): + """ + Check for a 404 response from the /questions endpoint + Check for the correct response message + """ + questionId = 3344 + expectedResponse = { + 'error': 'Question not found' + } + response = requests.get(self.host() + '/questions/' + str(questionId) + '/comments') + self.assertEqual(404, response.status_code) + self.assertEqual(expectedResponse, response.json()) + + + def test_get_question_by_questionId_no_comments(self): + """ + Check for a 200 response from the /questions endpoint + Check for the correct response message + """ + questionId = 4 + expectedResponse = [] + response = requests.get(self.host() + '/questions/' + str(questionId) + '/comments') + self.assertEqual(200, response.status_code) + self.assertEqual(expectedResponse, response.json()) + + + def test_get_question_information_by_id(self): + """ + Check for a 200 response from the /questions endpoint + Check for the correct response message + """ + questionId = 1 + expectedResponse = { + "questionId": 1, + "questionText": "Who is the best tutor at UQ?", + "questionType": "Multiple Choice", + "questionPNG": None + } + response = requests.get(self.host() + '/questions/' + str(questionId)) + self.assertEqual(200, response.status_code) + self.assertEqual(expectedResponse, response.json()) + + + def test_get_question_information_by_invalid_id(self): + """ + Check for a 404 response from the /questions endpoint + Check for the correct response message + """ + questionId = 4486 + expectedResponse = { + "error": "Question not found" + } + + response = requests.get(self.host() + '/questions/' + str(questionId)) + self.assertEqual(404, response.status_code) + self.assertEqual(expectedResponse, response.json()) + + # need to do testing on /questions/:questionId + #TODO go through every route i rest and add a comment above the test for which route is specifcally called. + if __name__ == '__main__': From a4adc9fd8691cc88a67f184982ec7699162119f0 Mon Sep 17 00:00:00 2001 From: "86.LAK" Date: Fri, 3 May 2024 15:47:24 +1000 Subject: [PATCH 13/20] questions fully tested --- backend/src/routes/routes.ts | 17 ++++++++++++----- integration_tests/test_questions.py | 9 --------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/backend/src/routes/routes.ts b/backend/src/routes/routes.ts index 2da7580..0275e9c 100644 --- a/backend/src/routes/routes.ts +++ b/backend/src/routes/routes.ts @@ -368,21 +368,28 @@ router.get('/questions/:questionId/comments', async (req: Request, res: Response) => { const { questionId } = req.params; + // Check if the questionId exists in the database + const { rows : questionRows } = await db.query(` + SELECT "questionId" + From questions + WHERE "questionId" = $1 + `, [questionId]); + + if (questionRows.length === 0) { + return res.status(404).json({ error: 'Question not found' }); + } + const { rows } = await db.query(` SELECT "questionId", "questionText", "questionType", "questionPNG" FROM questions WHERE questions."questionId" = $1 `, [questionId]); - if (rows.length === 0) { - return res.status(404).json({ error: "Question not found" }); - } - res.status(200).json(rows[0]); }); diff --git a/integration_tests/test_questions.py b/integration_tests/test_questions.py index 38c8db3..914659c 100644 --- a/integration_tests/test_questions.py +++ b/integration_tests/test_questions.py @@ -252,14 +252,5 @@ def test_get_question_information_by_invalid_id(self): self.assertEqual(expectedResponse, response.json()) - - - # need to do testing on /questions/:questionId - - #TODO go through every route i rest and add a comment above the test for which route is specifcally called. - - - - if __name__ == '__main__': unittest.main() From be4693cea0592b378a414cb5d59c016f76b55a06 Mon Sep 17 00:00:00 2001 From: "86.LAK" Date: Fri, 3 May 2024 16:11:54 +1000 Subject: [PATCH 14/20] @JTrenerry hi --- backend/src/routes/routes.ts | 8 ++++++++ integration_tests/test_comments.py | 29 +++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/backend/src/routes/routes.ts b/backend/src/routes/routes.ts index 0275e9c..6857d57 100644 --- a/backend/src/routes/routes.ts +++ b/backend/src/routes/routes.ts @@ -76,6 +76,7 @@ router.put('/questions/:questionId/edit', async (req: Request, res: Response) => { const { commentId } = req.params; @@ -102,6 +103,7 @@ router.put('/comments/:commentId/edit', async (req: Request, res: Response) => { const { commentId } = req.params; @@ -115,6 +117,7 @@ router.patch('/comments/:commentId/delete', async (req: Request, res: Response) => { const { commentId } = req.params; @@ -132,6 +135,7 @@ router.patch('/comments/:commentId/correct', async (req: Request, res: Response) => { const { commentId } = req.params; @@ -149,6 +153,7 @@ router.patch('/comments/:commentId/endorse', async (req: Request, res: Response) => { const { commentId } = req.params; @@ -166,6 +171,7 @@ router.patch('/comments/:commentId/downvote', async (req: Request, res: Response) => { const { commentId } = req.params; @@ -191,6 +197,7 @@ router.patch('/comments/:commentId/upvote', async (req: Request, res: Response) => { const { @@ -331,6 +338,7 @@ router.post('/courses', async (req: Request, res: Re * */ +//TODO needs to be tested // Gets comment by comment id router.get('/comments/:commentId', async (req: Request, res: Response) => { const { commentId } = req.params; diff --git a/integration_tests/test_comments.py b/integration_tests/test_comments.py index 023bfd1..9e13c09 100644 --- a/integration_tests/test_comments.py +++ b/integration_tests/test_comments.py @@ -5,12 +5,29 @@ class TestComments(BaseCase): - def test_evan(self): - """ - Checks for a 200 response from the evan endpoint - """ - response = requests.get(self.host() + '/evan', headers={'Accept': 'application/json'}) - self.assertEqual(200, response.status_code) + + def test_put_edits_comment_success(self): + pass + + + + # def test_put_edit_question_successful(self): + # """ + # Check for a 201 response from the /questions endpoint + # Check for the correct response message + # """ + # questionId = 1 + # body = { + # "questionId": questionId, + # "questionText": "Who is the best tutor at UQ?", + # "questionType": "Multiple Choice", + # "questionPNG": None + # } + + # response = requests.put(self.host() + '/questions/' + str(questionId) + '/edit', json=body) + + # self.assertEqual(200, response.status_code) + # self.assertEqual('Question edited', response.json()) From 1905da1d328487526531a80aff97586aa09b2952 Mon Sep 17 00:00:00 2001 From: "86.LAK" Date: Fri, 3 May 2024 16:12:59 +1000 Subject: [PATCH 15/20] hi again ?? Co-authored-by: Jackson Trenerry \<105094182+jtrenerry@users.noreply.github.com\> --- integration_tests/test_comments.py | 1 + 1 file changed, 1 insertion(+) diff --git a/integration_tests/test_comments.py b/integration_tests/test_comments.py index 9e13c09..c566e4c 100644 --- a/integration_tests/test_comments.py +++ b/integration_tests/test_comments.py @@ -7,6 +7,7 @@ class TestComments(BaseCase): def test_put_edits_comment_success(self): + pass From 011e7a5b35e479c3c6f18cd0632110bbbcb19843 Mon Sep 17 00:00:00 2001 From: "86.LAK" Date: Fri, 3 May 2024 16:13:33 +1000 Subject: [PATCH 16/20] Co-authored-by: Jackson Trenerry \<105094182+jtrenerry@users.noreply.github.com\> --- integration_tests/test_comments.py | 1 - 1 file changed, 1 deletion(-) diff --git a/integration_tests/test_comments.py b/integration_tests/test_comments.py index c566e4c..9e13c09 100644 --- a/integration_tests/test_comments.py +++ b/integration_tests/test_comments.py @@ -7,7 +7,6 @@ class TestComments(BaseCase): def test_put_edits_comment_success(self): - pass From 91bdc5f7edf2a28b829dbbff4a45f59a7f179cff Mon Sep 17 00:00:00 2001 From: "86.LAK" Date: Fri, 3 May 2024 16:17:26 +1000 Subject: [PATCH 17/20] Co-authored-by: Jackson Trenerry <105094182+jtrenerry@users.noreply.github.com> --- integration_tests/test_comments.py | 1 + 1 file changed, 1 insertion(+) diff --git a/integration_tests/test_comments.py b/integration_tests/test_comments.py index 9e13c09..c566e4c 100644 --- a/integration_tests/test_comments.py +++ b/integration_tests/test_comments.py @@ -7,6 +7,7 @@ class TestComments(BaseCase): def test_put_edits_comment_success(self): + pass From 0c07d029ba15cabf6ab1dd8f97aa2c0b31476aa6 Mon Sep 17 00:00:00 2001 From: "86.LAK" Date: Fri, 3 May 2024 16:17:59 +1000 Subject: [PATCH 18/20] i giveup but ye --- integration_tests/test_comments.py | 1 - 1 file changed, 1 deletion(-) diff --git a/integration_tests/test_comments.py b/integration_tests/test_comments.py index c566e4c..9e13c09 100644 --- a/integration_tests/test_comments.py +++ b/integration_tests/test_comments.py @@ -7,7 +7,6 @@ class TestComments(BaseCase): def test_put_edits_comment_success(self): - pass From 7f1a9fedf274482f6da147d2d541634b02194bf3 Mon Sep 17 00:00:00 2001 From: "86.LAK" Date: Fri, 3 May 2024 16:23:18 +1000 Subject: [PATCH 19/20] testing of editing comment finished --- backend/src/routes/routes.ts | 3 +- integration_tests/test_comments.py | 72 ++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/backend/src/routes/routes.ts b/backend/src/routes/routes.ts index 6857d57..56c3a73 100644 --- a/backend/src/routes/routes.ts +++ b/backend/src/routes/routes.ts @@ -76,7 +76,6 @@ router.put('/questions/:questionId/edit', async (req: Request, res: Response) => { const { commentId } = req.params; @@ -88,7 +87,7 @@ router.put('/comments/:commentId/edit', async (req: Request Date: Fri, 3 May 2024 17:34:56 +1000 Subject: [PATCH 20/20] everything excluding comments and full int testing --- backend/src/routes/routes.ts | 5 ++ integration_tests/test_comments.py | 89 +++++++++++++++++------------- 2 files changed, 57 insertions(+), 37 deletions(-) diff --git a/backend/src/routes/routes.ts b/backend/src/routes/routes.ts index 56c3a73..ae010c5 100644 --- a/backend/src/routes/routes.ts +++ b/backend/src/routes/routes.ts @@ -85,6 +85,11 @@ router.put('/comments/:commentId/edit', async (req: Request