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 @@ -22,6 +22,7 @@
- Added `.gitattributes` file to standardize to LF line endings and renormalized codebase
- Added invalid JSON graph test coverage for `saveGraphJSON` in `app/Controllers/Graph.hs`
- Converted various JS files to TypeScript
- Added static info existence test for `Database/Database.hs`

## [0.8.1] - 2026-08-10

Expand Down
26 changes: 15 additions & 11 deletions app/Database/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
--
-- The main module for parsing course information from the web and
-- inserting it into the database. Run when @cabal run database@ is executed.
module Database.Database (populateCalendar, setupDatabase) where
module Database.Database (populateCalendar, setupDatabase, populateStaticInfo) where

import Config (databasePath, runDb)
import Control.Monad (void)
Expand All @@ -13,7 +13,7 @@ import Data.Maybe (fromMaybe)
import Data.Text as T (findIndex, length, reverse, take, unpack)
import Database.CourseVideoSeed (seedVideos)
import Database.Migrations (getDatabaseVersion)
import Database.Persist.Sqlite (insert_, runMigration, runMigrationQuiet)
import Database.Persist.Sqlite (insertMany_, runMigration, runMigrationQuiet)
import Database.Tables
import System.Directory (createDirectoryIfMissing)
import WebParsing.ArtSciParser (parseCalendar)
Expand Down Expand Up @@ -54,16 +54,20 @@ populateStaticInfo = do
-- | Sets up the Distribution table.
setupDistributionTable :: IO ()
setupDistributionTable = runDb $ do
insert_ $ Distribution "Humanities"
insert_ $ Distribution "Social Science"
insert_ $ Distribution "Science"
insertMany_
[ Distribution "Humanities"
, Distribution "Social Science"
, Distribution "Science"
]

-- | Sets up the Breadth table.
setupBreadthTable :: IO ()
setupBreadthTable = runDb $ do
insert_ $ Breadth "Creative and Cultural Representations (1)"
insert_ $ Breadth "Thought, Belief, and Behaviour (2)"
insert_ $ Breadth "Society and its Institutions (3)"
insert_ $ Breadth "Living Things and Their Environment (4)"
insert_ $ Breadth "The Physical and Mathematical Universes (5)"
insert_ $ Breadth "No Breadth"
insertMany_
[ Breadth "Creative and Cultural Representations (1)"
, Breadth "Thought, Belief, and Behaviour (2)"
, Breadth "Society and its Institutions (3)"
, Breadth "Living Things and Their Environment (4)"
, Breadth "The Physical and Mathematical Universes (5)"
, Breadth "No Breadth"
]
57 changes: 57 additions & 0 deletions backend-test/Database/DatabaseTests.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
-- |
-- Description: Database module tests
--
-- Module that contains the tests for the functions in the Database module.
module Database.DatabaseTests (
test_database,
) where

import Config (runDb)
import Data.List (sort)
import qualified Data.Text as T
import Database.Database (populateStaticInfo)
import Database.Persist.Sqlite (Entity, entityVal, selectList)
import Database.Tables (
Breadth (..),
Distribution (..),
)
import Test.Tasty (TestTree)
import Test.Tasty.HUnit (assertEqual, testCase)
import TestHelpers (clearDatabase, withDatabase)

-- | Run test on populateStaticInfo to check that distribution and breadth tables are set up
testPopulateStaticInfo :: TestTree
testPopulateStaticInfo =
testCase "populateStaticInfo inserts tables into the database" $ do
runDb clearDatabase
populateStaticInfo

distributions <- runDb $ selectList [] [] :: IO [Entity Distribution]
breadths <- runDb $ selectList [] [] :: IO [Entity Breadth]

assertEqual
"Expected populateStaticInfo to insert distribution entries"
(sort $ map (distributionDescription . entityVal) distributions)
( sort
[ T.pack "Humanities"
, T.pack "Social Science"
, T.pack "Science"
]
)
assertEqual
"Expected populateStaticInfo to insert breadth entries"
(sort $ map (breadthDescription . entityVal) breadths)
( sort
[ T.pack "Creative and Cultural Representations (1)"
, T.pack "Thought, Belief, and Behaviour (2)"
, T.pack "Society and its Institutions (3)"
, T.pack "Living Things and Their Environment (4)"
, T.pack "The Physical and Mathematical Universes (5)"
, T.pack "No Breadth"
]
)

-- | Test suite for Database module
test_database :: TestTree
test_database =
withDatabase "Database tests" [testPopulateStaticInfo]
1 change: 1 addition & 0 deletions courseography.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ test-suite Tests
Controllers.ProgramControllerTests,
Database.BuildingTests,
Database.CourseQueriesTests,
Database.DatabaseTests,
Database.TablesTests,
RequirementTests.ModifierTests,
RequirementTests.PostParserTests,
Expand Down
Loading