Replace scotty with servant

This commit is contained in:
2026-09-25 11:48:42 +03:00
parent 9c47bbcb42
commit 05bd609c7e
5 changed files with 118 additions and 60 deletions
+19 -1
View File
@@ -20,15 +20,30 @@ import System.Directory (findExecutable, getTemporaryDirectory, removeFile)
import System.Exit (ExitCode (..))
import System.Process (readProcessWithExitCode)
import Test.Hspec
import Servant.API (FromHttpApiData(..), ToHttpApiData (..))
import HomeAssistant.Runtime.Graphing (Graph(..))
traffic :: GraphSpec
traffic = case lookupGraph graphs "traffic" of
traffic = case lookupGraph graphs Traffic of
Just s -> s
Nothing -> error "traffic graph is missing from the table"
spec :: Spec
spec = do
describe "Graph HttpApiData" $ do
-- There's an enumerable amount of graphs, we can just enumerate through them all
it "satisfies roundtrip property" $ do
let modes = [minBound..maxBound]
let got = map (parseQueryParam . toQueryParam @Graph) modes
let wanted = map Right modes
got `shouldBe` wanted
describe "parseRange" $ do
-- Fully enumerable
it "the http-api-data satisfies roundtrip property" $ do
let rs = [minBound..maxBound]
let got = map (parseQueryParam . toQueryParam @Range) rs
let wanted = map Right rs
got `shouldBe` wanted
it "accepts every suffix in the closed set" $
map parseRange ["10m", "1h", "24h", "7d", "30d"]
`shouldBe` [ Just TenMinutes
@@ -124,3 +139,6 @@ spec = do
out `shouldSatisfy` BS.isPrefixOf pngMagic
)
`finally` cleanup