From 8b8bd4fe429b7ff12e67b975744ba991f2d8e504 Mon Sep 17 00:00:00 2001 From: PeanutPiglet Date: Tue, 22 Sep 2026 22:22:19 -0400 Subject: [PATCH 1/5] refactor database table setup --- app/Database/Database.hs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/Database/Database.hs b/app/Database/Database.hs index 185fa044b..c113b70bb 100644 --- a/app/Database/Database.hs +++ b/app/Database/Database.hs @@ -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) @@ -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" + ] From 1f77216471b00754e2a4fc023cf10ef61964a204 Mon Sep 17 00:00:00 2001 From: PeanutPiglet Date: Thu, 24 Sep 2026 21:01:09 -0400 Subject: [PATCH 2/5] expose populateStaticInfo of Database.hs --- app/Database/Database.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Database/Database.hs b/app/Database/Database.hs index c113b70bb..8971f5667 100644 --- a/app/Database/Database.hs +++ b/app/Database/Database.hs @@ -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) From 6ad9b309fc53b33caf492ea054aab28e4fafc853 Mon Sep 17 00:00:00 2001 From: PeanutPiglet Date: Thu, 24 Sep 2026 21:10:26 -0400 Subject: [PATCH 3/5] add backend test file for Database --- backend-test/Database/DatabaseTests.hs | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 backend-test/Database/DatabaseTests.hs diff --git a/backend-test/Database/DatabaseTests.hs b/backend-test/Database/DatabaseTests.hs new file mode 100644 index 000000000..08d7e5b1b --- /dev/null +++ b/backend-test/Database/DatabaseTests.hs @@ -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] From 7a15a2a79e61b6ee156e7504451538dbc91d8e91 Mon Sep 17 00:00:00 2001 From: PeanutPiglet Date: Fri, 25 Sep 2026 10:49:16 -0400 Subject: [PATCH 4/5] add DatabaseTests to cabel listing --- courseography.cabal | 1 + 1 file changed, 1 insertion(+) diff --git a/courseography.cabal b/courseography.cabal index 285b9a212..0dd465fd8 100644 --- a/courseography.cabal +++ b/courseography.cabal @@ -123,6 +123,7 @@ test-suite Tests Controllers.ProgramControllerTests, Database.BuildingTests, Database.CourseQueriesTests, + Database.DatabaseTests, Database.TablesTests, RequirementTests.ModifierTests, RequirementTests.PostParserTests, From e003e3b8fdaca44b97fa31ed138522d142a717af Mon Sep 17 00:00:00 2001 From: PeanutPiglet Date: Fri, 25 Sep 2026 10:53:24 -0400 Subject: [PATCH 5/5] update changelog on new test --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b682f4bac..6d55c9a7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Adopted TypeScript v7 into build and CI pipelines and converted `js/components/graph/Button.js` to `Button.tsx` as a proof of concept - 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` +- Added static info existence test for `Database/Database.hs` ## [0.8.1] - 2026-08-10