Test cases for saveGraphJSON #1653
Draft
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.
Proposed Changes
Added test cases for the
saveGraphJSONfunction inapp/Controllers/Graph.hs.The test cases check the case with an empty graph/no inputted texts, shapes, or path nodes, the case with a single node, and the case with multiple connected nodes.
Type of Change
(Write an
Xor a brief description next to the type or types that best describe your changes.)Checklist
(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the
[ ]into a[x]in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)Before opening your pull request:
After opening your pull request:
Questions and Comments
(Include any questions or comments you have regarding your changes.)
In the
getGraphfunction ofapp/Models/Graph.hs, it concatenates paths that are marked as a region and texts that do not intersect with any shape to the preexistinggraphpathsandgraphtextslists, respectively, which already contain the added paths and texts. If you replacegraphtexts ++ regionTextswithgraphtextsandgraphpaths ++ regionswithgraphpathsin the response object, the tests don't seem to fail, nor did I notice any obvious changes to the website.courseography/app/Models/Graph.hs
Lines 47 to 58 in f5e8a3a
To my understanding, we’re testing that the inputted JSON representing the graph is saved in the database properly, and we can get it from said database to compare with the original with
getGraphfrom theapp/Models/Graph.hs. However, the++ regionTextsand++ regionsmeans that some text and paths are duplicated in thegetGraphreturn value, compared to the original value. Sincegraphpathsalready contains any paths inregion, because the latter is a partition of the first, and similarly asgraphtextsis already contained inregionTexts, the resulting concatenation contains duplicate elements.I checked the blame and the commit from 10 years ago that added the code said “json-request: source and targets added,” so unfortunately I’m not really familiar with the context behind its addition. I think that since any text that intersects with a shape is automatically added to that shape's "text" attribute, the original intent of
regionTextsmight have been to only return the text that is not already combined into a shape.Currently, I separated the input and expected JSON in the test cases and accounted for the duplicated nodes in the expected values, but I am unsure if this is the best approach for testing this function, especially considering that when testing if a JSON is saved, presumably the saved JSON should match the inputted JSON.