Skip to content
Open
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 @@ -28,6 +28,7 @@
- Removed `Location` datatype in favour of `Building`
- Refactor tests to run directly on tuple input to prevent unnecessary unpacking and repacking
- Renamed usages of the word "room" to "location" in the codebase to better reflect the data represented
- Added test cases for JSON parsing of Meeting data type in `Database/TablesTests.hs`

## [0.7.2] - 2025-12-10

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Nazanin Ghazitabatabai,
Sidharth Gupta,
Parker Hutcheson,
Yoonie Jang,
Angelina Jiang,
Jai Joshi,
Aayush Karki,
Japleen Kaur,
Expand Down
2 changes: 1 addition & 1 deletion app/Database/Tables.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Meeting
enrol Int
wait Int
extra Int
deriving Generic Show
deriving Generic Show Eq
UniqueMeeting code session section

Times
Expand Down
46 changes: 46 additions & 0 deletions backend-test/Database/TablesTests.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{-|
Description: Tables module tests.

Module that contains the tests for the functions in the Tables module.

-}

module Database.TablesTests
( test_tables
) where

import Data.Aeson (decode)
import qualified Data.ByteString.Lazy.Char8 as BL
import Database.Tables (Meeting (..))
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.HUnit (assertEqual, testCase)

-- | List of test cases as (label, input JSON payload, expected output)
meetingFromJSONTestCases :: [(String, BL.ByteString, Maybe Meeting)]
meetingFromJSONTestCases =
[ ("Invalid meeting (empty JSON), Nothing returned", "{}", Nothing)
, ("Valid meeting with valid teachMethod", "{\"teachMethod\":\"LEC\"}", Just (Meeting "" "" "LEC" (-1) "" 0 0 0))
, ("Valid meeting with all fields", "{\"teachMethod\":\"LEC\",\"sectionNumber\":\"0101\",\"maxEnrolment\":100,\"currentEnrolment\":77,\"currentWaitlist\":0,\"instructors\":[{\"firstName\":\"Brinda\",\"lastName\":\"Venkataramani\"}]}", Just (Meeting "" "" "LEC0101" 100 "Brinda. Venkataramani" 77 0 0))
, ("Valid meeting with no maxEnrolment, default cap returned", "{\"teachMethod\":\"LEC\",\"sectionNumber\":\"0101\"}", Just (Meeting "" "" "LEC0101" (-1) "" 0 0 0))
, ("Valid meeting with no currentEnrolment, default enrol returned", "{\"teachMethod\":\"LEC\",\"sectionNumber\":\"0101\",\"maxEnrolment\":100}", Just (Meeting "" "" "LEC0101" 100 "" 0 0 0))
, ("Valid meeting with no currentWaitlist, default wait returned", "{\"teachMethod\":\"LEC\",\"sectionNumber\":\"0101\",\"maxEnrolment\":100,\"currentEnrolment\":50}", Just (Meeting "" "" "LEC0101" 100 "" 50 0 0))
, ("Valid meeting with multiple instructors", "{\"teachMethod\":\"LEC\",\"sectionNumber\":\"0101\",\"instructors\":[{\"firstName\":\"A\",\"lastName\":\"B\"},{\"firstName\":\"C\",\"lastName\":\"D\"}]}", Just (Meeting "" "" "LEC0101" (-1) "A. B; C. D" 0 0 0))
, ("Invalid meeting with no teachMethod, Nothing returned", "{\"sectionNumber\":\"0101\",\"maxEnrolment\":100}", Nothing)
, ("Invalid meeting with unknown teachMethod, Nothing returned", "{\"teachMethod\":\"LAB\",\"sectionNumber\":\"0101\"}", Nothing)
]

-- | Run a test case (case, input, expected output) on the FromJSON instance of Meeting.
runMeetingFromJSONTest :: (String, BL.ByteString, Maybe Meeting) -> TestTree
runMeetingFromJSONTest (label, meetingJSON, expected) =
testCase label $ do
let actual = decode meetingJSON :: Maybe Meeting
assertEqual ("Unexpected parsing result for " ++ label) expected actual

-- | Run all the meetingFromJSON test cases
runMeetingFromJSONTests :: [TestTree]
runMeetingFromJSONTests = map runMeetingFromJSONTest meetingFromJSONTestCases

-- | Test suite for Tables Module
test_tables :: TestTree
test_tables =
testGroup "Parsing from JSON to Meeting tests" runMeetingFromJSONTests
1 change: 1 addition & 0 deletions courseography.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ test-suite Tests
Controllers.GraphControllerTests,
Controllers.ProgramControllerTests,
Database.CourseQueriesTests,
Database.TablesTests,
RequirementTests.ModifierTests,
RequirementTests.PostParserTests,
RequirementTests.PreProcessingTests,
Expand Down