packages feed

natskell-0.0.0.1: test/Unit/UnsubSpec.hs

{-# LANGUAGE OverloadedStrings #-}

module UnsubSpec (spec) where

import           Control.Monad
import           Data.ByteString
import qualified Data.ByteString.Lazy      as LBS
import           Test.Hspec
import           Text.Printf
import           Transformers.Transformers
import           Types.Unsub
import           Validators.Validators

spec :: Spec
spec = do
  transformerCases
  validateCases

explicitTransformerCases :: [(Unsub, ByteString)]
explicitTransformerCases = [
  (Unsub "uuid" Nothing, "UNSUB uuid\r\n"),
  (Unsub "uuid" (Just 10), "UNSUB uuid 10\r\n")
  ]

transformerCases = parallel $ do
  describe "UNSUB transformer" $ do
    forM_ explicitTransformerCases $ \(input, want) ->
      it (printf "correctly transforms %s" (show input)) $ do
        LBS.toStrict (transform input) `shouldBe` want

explicitValidaterCases :: [(Unsub, Either ByteString ())]
explicitValidaterCases = [
  (Unsub "a" Nothing, Right ()),
  (Unsub "a" (Just 1), Right ()),
  (Unsub "a" (Just 0), Right ()),
  (Unsub "" Nothing, Left "explicit empty sid")
  ]

validateCases = parallel $ do
  describe "UNSUB validater" $ do
    forM_ explicitValidaterCases $ \(input, want) ->
      it (printf "correctly validates %s" (show input)) $ do
        validate input `shouldBe` want