speechmatics-0.1.0.0: test/PeekJobSpec.hs
{-# 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,
jobNotification = "email",
jobJobType = "transcription",
jobUrl = "/v1.0/user/42578/jobs/8221819/audio",
jobNextCheck = 1.527572657e9,
jobLang = "en-US",
jobJobStatus = "transcribing",
jobName = "file.mp3",
jobCreatedAt = "Tue, 29 May 2018 05:43:46 GMT",
jobId = 8221819.0,
jobMeta = Nothing,
jobUserId = 42578.0,
jobDuration = 4.0,
jobTranscription = Nothing
}
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,
jobNotification = "email",
jobJobType = "transcription",
jobUrl = "/v1.0/user/42578/jobs/8220130/audio",
jobNextCheck = 0.0,
jobLang = "en-US",
jobJobStatus = "done",
jobName = "zero.wav",
jobCreatedAt = "Tue, 29 May 2018 04:21:48 GMT",
jobId = 8220130.0,
jobMeta = Nothing,
jobUserId = 42578.0,
jobDuration = 0.0,
jobTranscription = Just "zero.json"
}
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)