Compare JSON return values, not strings
Leverage json quasi-quoting to build a JSON object for comparison so that arbitrary field order in objects doesn't invalidate tests.
This commit is contained in:
parent
7f8a853d3c
commit
6030be74c4
1 changed files with 58 additions and 7 deletions
65
test/Spec.hs
65
test/Spec.hs
|
@ -1,5 +1,6 @@
|
|||
{-# LANGUAGE QuasiQuotes #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE QuasiQuotes #-}
|
||||
|
||||
module Main (main) where
|
||||
|
||||
import Lib (app)
|
||||
|
@ -12,9 +13,59 @@ main = hspec spec
|
|||
|
||||
spec :: Spec
|
||||
spec = with (return app) $ do
|
||||
describe "GET /search" $ do
|
||||
it "responds with 200" $ do
|
||||
get "/search" `shouldRespondWith` 200
|
||||
it "responds with [Card]" $ do
|
||||
let cards = "[{\"scryfall_id\":\"f6cd7465-9dd0-473c-ac5e-dd9e2f22f5f6\",\"name\":\"Esika, God of the Tree // The Prismatic Bridge\",\"set_code\":\"KHM\",\"collector_number\":\"168\",\"rarity\":\"mythic\",\"color_identity\":\"WUBGR\",\"oracle_text\":null,\"prices\":{\"usd\":\"9.07\",\"usd_foil\":\"10.77\",\"eur\":\"7.79\",\"eur_foil\":\"12.27\",\"tix\":\"1.08\"}},{\"scryfall_id\":\"d761ff73-0717-4ee4-996b-f5547bcf9b2f\",\"name\":\"Go-Shintai of Life's Origin\",\"set_code\":\"NEC\",\"collector_number\":\"66\",\"rarity\":\"mythic\",\"color_identity\":\"WUBGR\",\"oracle_text\":\"{W}{U}{B}{R}{G}, {T}: Return target enchantment card from your graveyard to the battlefield.\\nWhenever Go-Shintai of Life's Origin or another nontoken Shrine enters the battlefield under your control, create a 1/1 colorless Shrine enchantment creature token.\",\"prices\":{\"usd\":\"23.28\",\"usd_foil\":null,\"eur\":\"23.05\",\"eur_foil\":null,\"tix\":null}},{\"scryfall_id\":\"e2539ff7-2b7d-47e3-bd77-3138a6c42d2b\",\"name\":\"Godsire\",\"set_code\":\"ALA\",\"collector_number\":\"170\",\"rarity\":\"mythic\",\"color_identity\":\"WGR\",\"oracle_text\":\"Vigilance\\n{T}: Create an 8/8 Beast creature token that's red, green, and white.\",\"prices\":{\"usd\":\"7.22\",\"usd_foil\":\"16.56\",\"eur\":\"4.00\",\"eur_foil\":\"13.95\",\"tix\":\"0.02\"}}]"
|
||||
get "/search" `shouldRespondWith` cards
|
||||
describe "GET /search" $ do
|
||||
it "responds with 200" $ do
|
||||
get "/search" `shouldRespondWith` 200
|
||||
it "responds with [Card]" $ do
|
||||
let cards =
|
||||
[json|[
|
||||
{
|
||||
"scryfall_id": "f6cd7465-9dd0-473c-ac5e-dd9e2f22f5f6",
|
||||
"name": "Esika, God of the Tree // The Prismatic Bridge",
|
||||
"set_code": "KHM",
|
||||
"collector_number": "168",
|
||||
"rarity": "mythic",
|
||||
"color_identity": "WUBGR",
|
||||
"oracle_text": null,
|
||||
"prices": {
|
||||
"usd": "9.07",
|
||||
"usd_foil": "10.77",
|
||||
"eur": "7.79",
|
||||
"eur_foil": "12.27",
|
||||
"tix": "1.08"
|
||||
}
|
||||
},
|
||||
{
|
||||
"scryfall_id": "d761ff73-0717-4ee4-996b-f5547bcf9b2f",
|
||||
"name": "Go-Shintai of Life's Origin",
|
||||
"set_code": "NEC",
|
||||
"collector_number": "66",
|
||||
"rarity": "mythic",
|
||||
"color_identity": "WUBGR",
|
||||
"oracle_text": "{W}{U}{B}{R}{G}, {T}: Return target enchantment card from your graveyard to the battlefield.\nWhenever Go-Shintai of Life's Origin or another nontoken Shrine enters the battlefield under your control, create a 1/1 colorless Shrine enchantment creature token.",
|
||||
"prices": {
|
||||
"usd": "23.28",
|
||||
"usd_foil": null,
|
||||
"eur": "23.05",
|
||||
"eur_foil": null,
|
||||
"tix": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"scryfall_id": "e2539ff7-2b7d-47e3-bd77-3138a6c42d2b",
|
||||
"name": "Godsire",
|
||||
"set_code": "ALA",
|
||||
"collector_number": "170",
|
||||
"rarity": "mythic",
|
||||
"color_identity": "WGR",
|
||||
"oracle_text": "Vigilance\n{T}: Create an 8/8 Beast creature token that's red, green, and white.",
|
||||
"prices": {
|
||||
"usd": "7.22",
|
||||
"usd_foil": "16.56",
|
||||
"eur": "4.00",
|
||||
"eur_foil": "13.95",
|
||||
"tix": "0.02"
|
||||
}
|
||||
}
|
||||
]|]
|
||||
get "/search" `shouldRespondWith` cards
|
||||
|
|
Loading…
Reference in a new issue