packages feed

speechmatics-0.1.0.0: test/PostJobSpec.hs

{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module PostJobSpec (spec) where

import NeatInterpolation (text)
import           Speechmatics.JSON.PostJob
import           Test.Hspec
import Data.Text.Encoding(encodeUtf8)
import Data.ByteString.Lazy

expected :: PostJob
expected = PostJob {
    checkWait = Nothing,
    cost = 0.0,
    balance = 9195.0,
    postId = 8217275
  }

fixture :: ByteString
fixture = fromStrict $ encodeUtf8 [text|
{
  "balance": 9195, 
  "check_wait": null, 
  "cost": 0, 
  "id": 8217275
}|]

spec :: Spec
spec = do
  describe "Ceres stats output parser" $ do
    it "parses fixture to expected value" $ do
      (parse fixture) `shouldBe` (Right expected)
    it "does not parse invalid json" $ do
      (parse "not json") `shouldSatisfy` (\case 
                                             Left _ -> True
                                             _ -> False)