Skip to content

Commit

Permalink
Add hspec tests
Browse files Browse the repository at this point in the history
Add several hspec tests of the library.

Also make a small fix to the Travis CI config file and to the show instances for OrderType.
  • Loading branch information
ExcaliburZero committed Jun 15, 2016
1 parent 1d5b815 commit 3833f19
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ script:

after_script:
# Send a test coverage report to Coveralls.io
- shc system-test unit-tests
- shc stockfighter unit-tests
2 changes: 1 addition & 1 deletion src/Network/Stockfighter/Trade.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ instance Show OrderType where
show Limit = "limit"
show Market = "market"
show FillOrKill = "fill-or-kill"
show ImmediateOrCancel = "immeditate-or-cancel"
show ImmediateOrCancel = "immediate-or-cancel"

-- | Sends a request for the given order using the given APIKey, and returns
-- the response.
Expand Down
7 changes: 5 additions & 2 deletions stockfighter.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ executable stockfighter-exe
, stockfighter
default-language: Haskell2010

test-suite stockfighter-test
test-suite unit-tests
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Spec.hs
main-is: Main.hs
other-modules: Spec
build-depends: base
, stockfighter
, aeson
, hspec
ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010

Expand Down
8 changes: 8 additions & 0 deletions test/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Main where

import Test.Hspec

import Spec

main :: IO ()
main = hspec spec
46 changes: 44 additions & 2 deletions test/Spec.hs
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
main :: IO ()
main = putStrLn "Test suite not yet implemented"
module Spec where

import Data.Aeson (encode)
import Test.Hspec

import Network.Stockfighter.Trade
import Network.Stockfighter.Util

spec :: Spec
spec = do
-- Trade
describe "Order" $ do
it "converts into a JSON String" $ do
let order = Order {
account = Account "EXB123456"
, venue = Venue "TESTEX"
, symbol = Symbol "FOOBAR"
, price = Price 25000
, quantity = Quantity 100
, direction = Buy
, orderType = Limit
}
byteStringToString (encode order) `shouldBe` "{\"account\":\"EXB123456\",\"venue\":\"TESTEX\",\"symbol\":\"FOOBAR\",\"price\":25000,\"qty\":100,\"direction\":\"buy\",\"orderType\":\"limit\"}"

describe "Direction" $ do
it "converts to correct String representation for API request" $ do
show Buy `shouldBe` "buy"
show Sell `shouldBe` "sell"

describe "OrderType" $ do
it "converts to correct String representation for API request" $ do
show Limit `shouldBe` "limit"
show Market `shouldBe` "market"
show FillOrKill `shouldBe` "fill-or-kill"
show ImmediateOrCancel `shouldBe` "immediate-or-cancel"

-- Util
describe "headerToString" $ do
it "converts a single part header" $ do
headerToString (HTTPHeader [("key", "value")]) `shouldBe` "key:value;"

it "converts a multi part header" $ do
headerToString (HTTPHeader [("key1", "value1"), ("key2","value2")])
`shouldBe` "key1:value1;key2:value2;"

0 comments on commit 3833f19

Please sign in to comment.