Skip to content

Commit

Permalink
Test coverage for SettlementDesk
Browse files Browse the repository at this point in the history
  • Loading branch information
rjsamson committed Feb 15, 2016
1 parent cad8b33 commit 76f3042
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/controllers/score_controller_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Stackfooter.ScoreControllerTest do
use Stackfooter.ConnCase
alias Stackfooter.{Venue, VenueRegistry, ApiKeyRegistry}
alias Stackfooter.{Venue, VenueRegistry, ApiKeyRegistry, SettlementDesk}

@admin_apikey "4cy7uf63Lw2Sx6652YmLwBKy662weU4q"
@non_admin_apikey "KVi7irGjY8ZhYg6B20QU7H6IIbhWmyt0"
Expand All @@ -10,6 +10,7 @@ defmodule Stackfooter.ScoreControllerTest do

{:ok, venue} = VenueRegistry.lookup(Stackfooter.VenueRegistry, "OBEX")
Venue.reset(venue)
SettlementDesk.reset_accounts(SettlementDesk)

Enum.each(4200..4211, fn x ->
Venue.place_order(venue, %{direction: "buy", symbol: "NYC", qty: 7, price: x, account: "admin", orderType: "limit"})
Expand Down
24 changes: 24 additions & 0 deletions test/otp/settlement_desk_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defmodule Stackfooter.SettlementDeskTest do
use ExUnit.Case, async: true
alias Stackfooter.{SettlementDesk, Order.Fill}

test "tests position_or_new_position" do
SettlementDesk.reset_accounts(SettlementDesk)
:timer.sleep(20)
SettlementDesk.settle_transaction(SettlementDesk, %{buy_account: "RJSAMSON", sell_account: "ADMIN", stock: "NYC", fill: %Fill{price: 100, qty: 10}})
:timer.sleep(20)
SettlementDesk.settle_transaction(SettlementDesk, %{buy_account: "RJSAMSON", sell_account: "ADMIN", stock: "FOO", fill: %Fill{price: 100, qty: 10}})
:timer.sleep(20)

accounts = SettlementDesk.all_accounts(SettlementDesk)

expected_accounts = [%Stackfooter.SettlementDesk.Account{cash: 2000, name: "ADMIN", nav: 0,
positions: [%Stackfooter.SettlementDesk.Account.Position{price: 0, qty: -10, stock: "FOO"},
%Stackfooter.SettlementDesk.Account.Position{price: 0, qty: -10, stock: "NYC"}]},
%Stackfooter.SettlementDesk.Account{cash: -2000, name: "RJSAMSON", nav: 0,
positions: [%Stackfooter.SettlementDesk.Account.Position{price: 0, qty: 10, stock: "FOO"},
%Stackfooter.SettlementDesk.Account.Position{price: 0, qty: 10, stock: "NYC"}]}]

assert accounts == expected_accounts
end
end

0 comments on commit 76f3042

Please sign in to comment.