-
Notifications
You must be signed in to change notification settings - Fork 69
Tests for Graph controller index method #1548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
david-yz-liu
merged 11 commits into
Courseography:master
from
yoonieaj:index-controller-tests
May 20, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4b9101b
Add tests for Graph index method
yoonieaj a4706c7
Update descriptions
yoonieaj 8c45432
Update Changelog and contributors list
yoonieaj 3431c47
Fix import statements
yoonieaj 2a85baf
Fix import statement order
yoonieaj 070de23
Revert unnecessary changes
yoonieaj 41c9184
Change import order
yoonieaj 44ba2d3
Fix import order
yoonieaj 6dec96f
Remove whitespace
yoonieaj 5213bcc
Fix order
yoonieaj 0aa26eb
Merge branch 'master' into index-controller-tests
yoonieaj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{-| | ||
Description: Graph Controller module tests. | ||
|
||
Module that contains the tests for the functions in the Graph Controller module. | ||
|
||
-} | ||
|
||
module Controllers.GraphControllerTests | ||
( graphControllerTestSuite | ||
) where | ||
|
||
import Config (runDb) | ||
import Controllers.Graph (index) | ||
import qualified Data.ByteString.Lazy.Char8 as BL | ||
import qualified Data.Text as T | ||
import Database.Persist.Sqlite (SqlPersistM, insert_) | ||
import Database.Tables (Graph (..)) | ||
import Happstack.Server (rsBody) | ||
import Test.HUnit (Test (..), assertEqual) | ||
import TestHelpers (clearDatabase, runServerPart) | ||
|
||
-- | List of test cases as (label, input graphs, expected output) | ||
indexTestCases :: [(String, [T.Text], String)] | ||
indexTestCases = | ||
[ ("No graphs", | ||
[], | ||
"[]" | ||
), | ||
|
||
("One graph", | ||
["Statistics"], | ||
"[{\"dynamic\":false,\"height\":0,\"id\":1,\"title\":\"Statistics\",\"width\":0}]" | ||
), | ||
|
||
("Multiple graphs", | ||
["Computer Science", "Statistics", "Physics"], | ||
"[{\"dynamic\":false,\"height\":0,\"id\":1,\"title\":\"Computer Science\",\"width\":0},{\"dynamic\":false,\"height\":0,\"id\":3,\"title\":\"Physics\",\"width\":0},{\"dynamic\":false,\"height\":0,\"id\":2,\"title\":\"Statistics\",\"width\":0}]" ) | ||
] | ||
|
||
-- | Helper function to insert graphs into the database | ||
insertGraphs :: [T.Text] -> SqlPersistM () | ||
insertGraphs = mapM_ insertGraph | ||
where | ||
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 -> Test | ||
runIndexTest label graphs expected = | ||
TestLabel label $ TestCase $ do | ||
runDb $ do | ||
clearDatabase | ||
insertGraphs graphs | ||
response <- runServerPart Controllers.Graph.index | ||
let actual = BL.unpack $ rsBody response | ||
assertEqual ("Unexpected response body for " ++ label) expected actual | ||
|
||
-- | Run all the index test cases | ||
runIndexTests :: [Test] | ||
runIndexTests = map (\(label, graphs, expected) -> runIndexTest label graphs expected) indexTestCases | ||
|
||
-- | Test suite for Graph Controller Module | ||
graphControllerTestSuite :: Test | ||
graphControllerTestSuite = TestLabel "Graph Controller tests" $ TestList runIndexTests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like if I don't add this space here, then the import statements get ordered alphabetically upon commit