Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Removed unused files
- Refactored controllers to retrieve graph info data using `lookText'` instead of `look`
- Removed `Location` datatype in favour of `Building`
- Refactor tests to run directly on tuple input to prevent unnecessary unpacking and repacking

## [0.7.2] - 2025-12-10

Expand Down
18 changes: 9 additions & 9 deletions backend-test/Controllers/CourseControllerTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ retrieveCourseTestCases =
]

-- | Run a test case (case, input, expected status code, expected output) on the retrieveCourse function.
runRetrieveCourseTest :: String -> T.Text -> Map.Map T.Text T.Text -> [MeetTime] -> Int -> String -> TestTree
runRetrieveCourseTest label courseName courseData meetingTimes expectedCode expectedBody =
runRetrieveCourseTest :: (String, T.Text, Map.Map T.Text T.Text, [MeetTime], Int, String) -> TestTree
runRetrieveCourseTest (label, courseName, courseData, meetingTimes, expectedCode, expectedBody) =
testCase label $ do
let currCourseName = fromMaybe "" $ Map.lookup "name" courseData

Expand Down Expand Up @@ -230,7 +230,7 @@ runRetrieveCourseTest label courseName courseData meetingTimes expectedCode expe

-- | Run all the retrieveCourse test cases
runRetrieveCourseTests :: [TestTree]
runRetrieveCourseTests = map (\(label, courseName, courseData, meetingTimes, expectedCode, expectedBody) -> runRetrieveCourseTest label courseName courseData meetingTimes expectedCode expectedBody) retrieveCourseTestCases
runRetrieveCourseTests = map runRetrieveCourseTest retrieveCourseTestCases

-- | Helper function to insert courses into the database
insertCourses :: [T.Text] -> SqlPersistM ()
Expand Down Expand Up @@ -268,8 +268,8 @@ indexTestCases =
]

-- | Run a test case (case, input, expected output) on the index function.
runIndexTest :: String -> [T.Text] -> String -> TestTree
runIndexTest label courses expected =
runIndexTest :: (String, [T.Text], String) -> TestTree
runIndexTest (label, courses, expected) =
testCase label $ do
runDb $ do
clearDatabase
Expand All @@ -280,7 +280,7 @@ runIndexTest label courses expected =

-- | Run all the index test cases
runIndexTests :: [TestTree]
runIndexTests = map (\(label, courses, expected) -> runIndexTest label courses expected) indexTestCases
runIndexTests = map runIndexTest indexTestCases

-- | List of test cases as (case, database state, input [dept], expected JSON output) for the courseInfo function
courseInfoTestCases :: [(String, [Courses], T.Text, String)]
Expand Down Expand Up @@ -345,8 +345,8 @@ courseInfoTestCases =
}

-- | Run a test case (case, database state, input [dept], expected JSON output) on the courseInfo function
runCourseInfoTest :: String -> [Courses] -> T.Text -> String -> TestTree
runCourseInfoTest label state dept expected =
runCourseInfoTest :: (String, [Courses], T.Text, String) -> TestTree
runCourseInfoTest (label, state, dept, expected) =
testCase label $ do
runDb $ do
clearDatabase
Expand All @@ -357,7 +357,7 @@ runCourseInfoTest label state dept expected =

-- | Run all courseInfo test cases
runCourseInfoTests :: [TestTree]
runCourseInfoTests = map (\(label, state, dept, expected) -> runCourseInfoTest label state dept expected) courseInfoTestCases
runCourseInfoTests = map runCourseInfoTest courseInfoTestCases

-- | Test suite for Course Controller Module
test_courseController :: TestTree
Expand Down
10 changes: 5 additions & 5 deletions backend-test/Controllers/GenerateControllerTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ findAndSavePrereqsResponseTestCases =
)]

-- | Run a test case (input course, course/prereq structure, JSON payload, expected # of nodes) on the findAndSavePrereqsResponse function.
runfindAndSavePrereqsResponseTest :: String -> [(T.Text, Maybe T.Text)] -> BSL.ByteString -> Integer -> Integer -> TestTree
runfindAndSavePrereqsResponseTest course graphStructure payload expectedNodes expectedBoolNodes =
runFindAndSavePrereqsResponseTest :: (String, [(T.Text, Maybe T.Text)], BSL.ByteString, Integer, Integer) -> TestTree
runFindAndSavePrereqsResponseTest (course, graphStructure, payload, expectedNodes, expectedBoolNodes) =
testCase course $ do
runDb $ do
clearDatabase
Expand Down Expand Up @@ -108,9 +108,9 @@ runfindAndSavePrereqsResponseTest course graphStructure payload expectedNodes ex
isBoolNode _ = False

-- | Run all the findAndSavePrereqsResponse test cases
runfindAndSavePrereqsResponseTests :: [TestTree]
runfindAndSavePrereqsResponseTests = map (\(course, courseStructure, payload, expectedNodes, expectedBoolNodes) -> runfindAndSavePrereqsResponseTest course courseStructure payload expectedNodes expectedBoolNodes) findAndSavePrereqsResponseTestCases
runFindAndSavePrereqsResponseTests :: [TestTree]
runFindAndSavePrereqsResponseTests = map runFindAndSavePrereqsResponseTest findAndSavePrereqsResponseTestCases

-- | Test suite for Generate Controller Module
test_generateController :: TestTree
test_generateController = withDatabase "Generate Controller tests" runfindAndSavePrereqsResponseTests
test_generateController = withDatabase "Generate Controller tests" runFindAndSavePrereqsResponseTests
18 changes: 9 additions & 9 deletions backend-test/Controllers/GraphControllerTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ insertGraphs = mapM_ insertGraph'
insertGraph' title = insert_ (Graph title 0 0 False )

-- | Run a test case (case, input, expected output) on the index function.
runIndexTest :: String -> [T.Text] -> String -> TestTree
runIndexTest label graphs expected =
runIndexTest :: (String, [T.Text], String) -> TestTree
runIndexTest (label, graphs, expected) =
testCase label $ do
runDb $ do
clearDatabase
Expand All @@ -63,7 +63,7 @@ runIndexTest label graphs expected =

-- | Run all the index test cases
runIndexTests :: [TestTree]
runIndexTests = map (\(label, graphs, expected) -> runIndexTest label graphs expected) indexTestCases
runIndexTests = map runIndexTest indexTestCases

-- | Helper function to add the default width and height to graph JSON
addDefaults :: Value -> Value
Expand All @@ -89,8 +89,8 @@ saveGraphJSONTestCases =
]

-- | Run a test case (case, graph JSON payload)
runSaveGraphJSONTest :: String -> BL.ByteString -> TestTree
runSaveGraphJSONTest label payload =
runSaveGraphJSONTest :: (String, BL.ByteString) -> TestTree
runSaveGraphJSONTest (label, payload) =
testCase label $ do
runDb clearDatabase
let graphName = "Test Graph Name"
Expand All @@ -101,7 +101,7 @@ runSaveGraphJSONTest label payload =

-- | Run all save graph test cases
runSaveGraphJSONTests :: [TestTree]
runSaveGraphJSONTests = map (uncurry runSaveGraphJSONTest) saveGraphJSONTestCases
runSaveGraphJSONTests = map runSaveGraphJSONTest saveGraphJSONTestCases


-- | List of test cases for getGraphJSON as (label, (texts, shapes, paths))
Expand Down Expand Up @@ -181,8 +181,8 @@ getGraphJSONTestCases =

-- | Run a test case (case, (texts', shapes', paths')) on getGraphJSON.
-- | Map GraphID to 1 in the assertions to account for insertGraph overriding the field.
runGetGraphJSONTest :: String -> ([Text], [Shape], [Path]) -> TestTree
runGetGraphJSONTest label (texts', shapes', paths') =
runGetGraphJSONTest :: (String, ([Text], [Shape], [Path])) -> TestTree
runGetGraphJSONTest (label, (texts', shapes', paths')) =
testCase label $ do
let graphName = "Test Graph Name"
runDb $ do
Expand All @@ -200,7 +200,7 @@ runGetGraphJSONTest label (texts', shapes', paths') =

-- | Run all getGraphJSON tests
runGetGraphJSONTests :: [TestTree]
runGetGraphJSONTests = map (\(label, (texts', shapes', paths')) -> runGetGraphJSONTest label (texts', shapes', paths')) getGraphJSONTestCases
runGetGraphJSONTests = map runGetGraphJSONTest getGraphJSONTestCases


-- | Test suite for Graph Controller Module
Expand Down
16 changes: 8 additions & 8 deletions backend-test/Controllers/ProgramControllerTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ instance FromJSON ProgramResponseNoTime where
return $ ProgramResponseNoTime code dept desc name reqs

-- | List of test cases as (label, programs to insert, query params, expected output)
retrieveprogramTestCases :: [(String, [T.Text], T.Text, Maybe ProgramResponseNoTime)]
retrieveprogramTestCases =
retrieveProgramTestCases :: [(String, [T.Text], T.Text, Maybe ProgramResponseNoTime)]
retrieveProgramTestCases =
[ ("Valid program code returns JSON"
, ["ASMAJ1689"]
, "ASMAJ1689"
Expand All @@ -66,8 +66,8 @@ parseProgramResponse :: String -> Maybe ProgramResponseNoTime
parseProgramResponse jsonStr = decode (BL.pack jsonStr)

-- | Run a test case (case, input, expected output) on the retrieveProgram function.
runRetrieveProgramTest :: String -> [T.Text] -> T.Text -> Maybe ProgramResponseNoTime -> TestTree
runRetrieveProgramTest label programs queryParam expected =
runRetrieveProgramTest :: (String, [T.Text], T.Text, Maybe ProgramResponseNoTime) -> TestTree
runRetrieveProgramTest (label, programs, queryParam, expected) =
testCase label $ do
runDb $ do
clearDatabase
Expand All @@ -79,7 +79,7 @@ runRetrieveProgramTest label programs queryParam expected =

-- | Run all the retrieveProgram test cases
runRetrieveProgramTests :: [TestTree]
runRetrieveProgramTests = map (\(label, programs, params, expected) -> runRetrieveProgramTest label programs params expected) retrieveprogramTestCases
runRetrieveProgramTests = map runRetrieveProgramTest retrieveProgramTestCases

-- | List of test cases as (label, input programs, expected output)
indexTestCases :: [(String, [T.Text], String)]
Expand All @@ -91,8 +91,8 @@ indexTestCases =
]

-- | Run a test case (case, input, expected output) on the index function.
runIndexTest :: String -> [T.Text] -> String -> TestTree
runIndexTest label programs expected =
runIndexTest :: (String, [T.Text], String) -> TestTree
runIndexTest (label, programs, expected) =
testCase label $ do
runDb $ do
clearDatabase
Expand All @@ -112,7 +112,7 @@ insertPrograms = mapM_ insertProgram

-- | Run all the index test cases
runIndexTests :: [TestTree]
runIndexTests = map (\(label, programs, expected) -> runIndexTest label programs expected) indexTestCases
runIndexTests = map runIndexTest indexTestCases

-- | Test suite for Program Controller Module
test_programController :: TestTree
Expand Down
6 changes: 3 additions & 3 deletions backend-test/Database/CourseQueriesTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ reqsForProgramTestCases =
]

-- | Run a test case (case, requirements, input, expected output) on the reqsForProgram function.
runReqsForProgramTest :: String -> T.Text -> T.Text -> String -> TestTree
runReqsForProgramTest label reqsToInsert program expected =
runReqsForProgramTest :: (String, T.Text, T.Text, String) -> TestTree
runReqsForProgramTest (label, reqsToInsert, program, expected) =
testCase label $ do
currentTime <- liftIO getCurrentTime
let testProgram = Program Major "Computer Science" program "Sample program description" reqsToInsert currentTime currentTime
Expand All @@ -46,7 +46,7 @@ runReqsForProgramTest label reqsToInsert program expected =

-- | Run all the reqsForProgram test cases
runReqsForProgramTests :: [TestTree]
runReqsForProgramTests = map (\(label, reqsToInsert, program, expected) -> runReqsForProgramTest label reqsToInsert program expected) reqsForProgramTestCases
runReqsForProgramTests = map runReqsForProgramTest reqsForProgramTestCases

-- | Test suite for CourseQueries Module
test_courseQueries :: TestTree
Expand Down
7 changes: 3 additions & 4 deletions backend-test/RequirementTests/FilterReqTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,16 @@ filterReqTestCases =
]

-- | Helper to run a single test case
runFilterReqTest :: String -> Req -> GraphOptions -> Req -> TestTree
runFilterReqTest description input options expected =
runFilterReqTest :: (String, Req, GraphOptions, Req) -> TestTree
runFilterReqTest (description, input, options, expected) =
testCase description $
assertEqual ("Failed test: " ++ description)
expected
(filterReq options input)

-- | Generate all tests from the list above
runFilterReqTests :: [TestTree]
runFilterReqTests =
[runFilterReqTest name input options expected | (name, input, options, expected) <- filterReqTestCases]
runFilterReqTests = map runFilterReqTest filterReqTestCases

-- | Test suite for FilterReq
test_filterReqs :: TestTree
Expand Down