diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d0dfa517..ddebbd62d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Cleared up documentation for various graph-related front-end functions - 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` ## [0.8.1] - 2026-08-10 diff --git a/README.md b/README.md index 9aef5c4ed..4a4ae9775 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,7 @@ Sam Shaftoe, Ian Stewart-Binks, Alan Su, Maryam Taj, +Jack Tang, Betty Wang, Rui Weng, Fullchee Zhang, diff --git a/backend-test/Controllers/GraphControllerTests.hs b/backend-test/Controllers/GraphControllerTests.hs index b960e0064..954cf5f0c 100644 --- a/backend-test/Controllers/GraphControllerTests.hs +++ b/backend-test/Controllers/GraphControllerTests.hs @@ -102,10 +102,19 @@ runSaveGraphJSONTest (label, payload) = let expectedValue = fmap addDefaults (decode payload :: Maybe Value) assertEqual ("Unexpected response for " ++ label) expectedValue retrievedResult --- | Run all save graph test cases +-- | Run all save graph test cases on valid inputs runSaveGraphJSONTests :: [TestTree] runSaveGraphJSONTests = map runSaveGraphJSONTest saveGraphJSONTestCases +-- | Run save graph test on invalid input +runSaveGraphJSONInvalidJSONTest :: TestTree +runSaveGraphJSONInvalidJSONTest = testCase "Invalid JSON graph" $ do + runDb clearDatabase + response <- + runServerPartWith Controllers.Graph.saveGraphJSON $ + mockPutRequest "/graph-save" [("nameData", "Invalid Graph Name"), ("jsonData", "Invalid JSON")] "" + assertEqual "Unexpected response for invalid JSON" "Error" (BL.unpack $ rsBody response) + -- | List of test cases for getGraphJSON as (label, (texts, shapes, paths)) -- | Invariant: Expected Graph IDs are all set to 1 getGraphJSONTestCases :: [(String, ([Text], [Shape], [Path]))] @@ -213,4 +222,7 @@ runGetGraphJSONTests = map runGetGraphJSONTest getGraphJSONTestCases -- | Test suite for Graph Controller Module test_graphController :: TestTree -test_graphController = withDatabase "Graph Controller tests" (runIndexTests ++ runSaveGraphJSONTests ++ runGetGraphJSONTests) +test_graphController = + withDatabase + "Graph Controller tests" + (runIndexTests ++ runSaveGraphJSONTests ++ [runSaveGraphJSONInvalidJSONTest] ++ runGetGraphJSONTests)