{-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} module PeekJobSpec (spec) where import NeatInterpolation (text) import Speechmatics.JSON.PeekJob import Test.Hspec import Data.Text.Encoding(encodeUtf8) import Data.ByteString.Lazy progressExpected :: Job progressExpected = Job { jobCheckWait = Just 30 } progressFixture :: ByteString progressFixture = fromStrict $ encodeUtf8 [text| { "job": { "check_wait": 30, "created_at": "Tue, 29 May 2018 05:43:46 GMT", "duration": 4, "id": 8221819, "job_status": "transcribing", "job_type": "transcription", "lang": "en-US", "meta": null, "name": "file.mp3", "next_check": 1527572657, "notification": "email", "transcription": null, "url": "/v1.0/user/42578/jobs/8221819/audio", "user_id": 42578 } } |] doneExpected :: Job doneExpected = Job { jobCheckWait = Nothing } doneFixture :: ByteString doneFixture = fromStrict $ encodeUtf8 [text| { "job": { "check_wait": null, "created_at": "Tue, 29 May 2018 04:21:48 GMT", "duration": 0, "id": 8220130, "job_status": "done", "job_type": "transcription", "lang": "en-US", "meta": null, "name": "zero.wav", "next_check": 0, "notification": "email", "transcription": "zero.json", "url": "/v1.0/user/42578/jobs/8220130/audio", "user_id": 42578 } } |] spec :: Spec spec = do describe "Ceres stats output parser" $ do it "parses doneFixture to doneExpected value" $ do (parse doneFixture) `shouldBe` (Right doneExpected) it "parses progressFixture to doneExpected value" $ do (parse progressFixture) `shouldBe` (Right progressExpected) it "does not parse invalid json" $ do (parse "not json") `shouldSatisfy` (\case Left _ -> True _ -> False)