aboutsummaryrefslogtreecommitdiff
path: root/server/test/Thermoprint/Server/QueueSpec.hs
blob: 4a9297e8c28ca7c2a3c86cd27c377c13f9fd7b99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, StandaloneDeriving #-}

module Thermoprint.Server.QueueSpec (spec) where

import Test.Hspec
import Test.Hspec.QuickCheck (prop)

import Thermoprint.Server.Queue
import Thermoprint.Server.Database
import Thermoprint.API hiding (JobId)

import Test.QuickCheck.Arbitrary
import Test.QuickCheck.Gen
import Test.QuickCheck.Modifiers

deriving instance (Eq PrintingError)
deriving instance (Eq Queue)

instance Arbitrary Queue where
  arbitrary = Queue <$> arbitrary <*> arbitrary <*> arbitrary

instance Arbitrary QueueEntry where
  arbitrary = QueueEntry <$> arbitrary <*> arbitrary

instance Arbitrary PrintingError where
  arbitrary = oneof [ return (IOError "dummy")
                    ]

instance Arbitrary JobId where
  arbitrary = castId . getNonNegative <$> (arbitrary :: Gen (NonNegative Integer))

spec :: Spec
spec = do
  describe "queue morphisms" $ do
    prop "are inverse" $ \queue -> queue == toZipper (fromZipper queue)