-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
1d5b815
commit 3833f19
Showing
5 changed files
with
59 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;" |