diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d0dfa517..908a209f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### 🔧 Internal changes +- Added a test case for the getGraphJSON function in `Controllers/Graph` - Migrated JS package manager from yarn to pnpm - Updated `react-leaflet` to v5.0.0 and `@eslint/compat` to v2.1.0 - Added peer dependency overrides for `eslint-plugin-react` (for `eslint` v10) and `@babel/plugin-syntax-*` (for `@babel/core` v8.0.1 diff --git a/README.md b/README.md index 9aef5c4ed..35b6ed208 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,7 @@ Mia Meng, Christine Murad, Justin Park, Harsh Patel, +Daniel Rafailov, Eleonora Scognamiglio, Sam Shaftoe, Ian Stewart-Binks, diff --git a/backend-test/Controllers/GraphControllerTests.hs b/backend-test/Controllers/GraphControllerTests.hs index b960e0064..5a8f55fc4 100644 --- a/backend-test/Controllers/GraphControllerTests.hs +++ b/backend-test/Controllers/GraphControllerTests.hs @@ -207,9 +207,28 @@ runGetGraphJSONTest (label, (texts', shapes', paths')) = assertEqual ("Shapes differ for " ++ label) shapes' (map (\shape -> shape{shapeGraph = toSqlKey 1}) parsedShapes) assertEqual ("Paths differ for " ++ label) paths' (map (\path -> path{pathGraph = toSqlKey 1}) parsedPaths) +-- | Run a specific test case that verifies the behaviour of getGraphJSON when graphName does not correspond to a graph in the database. +testGraphNotFound :: TestTree +testGraphNotFound = + let label = "Graph not found returns empty components" + in testCase label $ do + let graphName = "Test Graph Name" + runDb clearDatabase + response <- + runServerPartWith Controllers.Graph.getGraphJSON $ + mockGetRequest "/get-json-data" [("graphName", T.unpack graphName)] "" + let body = rsBody response + let jsonObj = parseGraphComponentsJSON body + case jsonObj of + Nothing -> assertFailure ("Maybe ([Text], [Shape], [Path]) returned as Nothing for " ++ label) + Just (parsedTexts, parsedShapes, parsedPaths) -> do + assertEqual ("Texts differ for " ++ label) [] parsedTexts + assertEqual ("Shapes differ for " ++ label) [] parsedShapes + assertEqual ("Paths differ for " ++ label) [] parsedPaths + -- | Run all getGraphJSON tests runGetGraphJSONTests :: [TestTree] -runGetGraphJSONTests = map runGetGraphJSONTest getGraphJSONTestCases +runGetGraphJSONTests = map runGetGraphJSONTest getGraphJSONTestCases ++ [testGraphNotFound] -- | Test suite for Graph Controller Module test_graphController :: TestTree