[tests] fix WithQuery frontend serialization test

Also, add WithQuery pubmed test (with api_key)
parent bc29319c
Pipeline #7209 passed with stages
in 53 minutes and 36 seconds
...@@ -61,6 +61,7 @@ tests = testGroup "JSON" [ ...@@ -61,6 +61,7 @@ tests = testGroup "JSON" [
, testProperty "NodeType roundtrips" (jsonEnumRoundtrip (Dict @_ @NodeType)) , testProperty "NodeType roundtrips" (jsonEnumRoundtrip (Dict @_ @NodeType))
, testProperty "NodePublishPolicy roundtrips" (jsonEnumRoundtrip (Dict @_ @NodePublishPolicy)) , testProperty "NodePublishPolicy roundtrips" (jsonEnumRoundtrip (Dict @_ @NodePublishPolicy))
, testCase "WithQuery frontend compliance" testWithQueryFrontend , testCase "WithQuery frontend compliance" testWithQueryFrontend
, testCase "WithQuery frontend compliance (PubMed)" testWithQueryFrontendPubMed
, testGroup "Phylo" [ , testGroup "Phylo" [
testProperty "PeriodToNode" (jsonRoundtrip @PeriodToNodeData) testProperty "PeriodToNode" (jsonRoundtrip @PeriodToNodeData)
, testProperty "GraphData" (jsonRoundtrip @GraphData) , testProperty "GraphData" (jsonRoundtrip @GraphData)
...@@ -81,11 +82,23 @@ testWithQueryFrontend = do ...@@ -81,11 +82,23 @@ testWithQueryFrontend = do
Left err -> fail $ "JSON instance will break frontend!: JSON decoding returned: " <> err Left err -> fail $ "JSON instance will break frontend!: JSON decoding returned: " <> err
Right _ -> pure () Right _ -> pure ()
testWithQueryFrontendPubMed :: Assertion
testWithQueryFrontendPubMed = do
case eitherDecode @WithQuery (C8.pack cannedWithQueryPayloadPubMed) of
Left err -> fail $ "JSON instance will break frontend (PubMed)!: JSON decoding returned: " <> err
Right _ -> pure ()
-- The aim of this type is to catch regressions in the frontend serialisation; this -- The aim of this type is to catch regressions in the frontend serialisation; this
-- is what the frontend currently expects, and therefore if we were to change the JSON -- is what the frontend currently expects, and therefore if we were to change the JSON
-- instances, this test would fail, and we will be notified. -- instances, this test would fail, and we will be notified.
cannedWithQueryPayload :: String cannedWithQueryPayload :: String
cannedWithQueryPayload = [r| {"query":"Haskell","node_id":138,"lang":"EN","flowListWith":{"type":"MyListsFirst"},"datafield": { "External": "Arxiv"},"databases":"Arxiv"} |] cannedWithQueryPayload = [r| {"query":"Haskell","node_id":138,"lang":"EN","flowListWith":{"type":"MyListsFirst"},"datafield": { "External": {"db": "Arxiv"}}} |]
-- The aim of this type is to catch regressions in the frontend serialisation; this
-- is what the frontend currently expects, and therefore if we were to change the JSON
-- instances, this test would fail, and we will be notified.
cannedWithQueryPayloadPubMed :: String
cannedWithQueryPayloadPubMed = [r| {"query":"Haskell","node_id":138,"lang":"EN","flowListWith":{"type":"MyListsFirst"},"datafield": { "External": {"db": "PubMed", "api_key": "x"}}} |]
testParseBpaPhylo :: Assertion testParseBpaPhylo :: Assertion
testParseBpaPhylo = do testParseBpaPhylo = do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment