You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.5 KiB

4 years ago
require "luarocks.loader"
package.path = package.path .. ";../?.lua" .. ";../3rdparty/?.lua"
local lu = require "luaunit"
require "qtis"
local json = require "JSON"
local Mock = require "test.mock.Mock"
local Match = require "test.mock.ValueMatcher"
quik = require "quik_api"
function test_handle_message()
local class = "TESTCLASS"
local ticker = "TESTTICKER"
local lot_size = 42
local price_step = 0.01
local tick_value = 10
local long_name = "The test ticker Inc."
quik.getParamEx = Mock()
quik.message = Mock()
quik.message:whenCalled { with={Match.anyString}, thenReturn=nil }
quik.getParamEx:whenCalled { with={class, ticker, "LOTSIZE"}, thenReturn = {{param_value = tostring(lot_size)}} }
quik.getParamEx:whenCalled { with={class, ticker, "SEC_PRICE_STEP"}, thenReturn = {{param_value = tostring(price_step)}} }
quik.getParamEx:whenCalled { with={class, ticker, "STEPPRICET"}, thenReturn = {{param_value = tostring(tick_value)}} }
quik.getParamEx:whenCalled { with={class, ticker, "LONGNAME"}, thenReturn = {{param_image = long_name}} }
local ok, data = handle_message( json:encode { ticker = class .. "#" .. ticker })
local resp = json:decode(data)
lu.assertEquals(ok, "OK")
lu.assertEquals(resp.ticker, class .. "#" .. ticker)
lu.assertEquals(resp.lot_size, lot_size)
lu.assertEquals(resp.tick_size, price_step)
lu.assertEquals(resp.tick_value, tick_value)
lu.assertEquals(resp.long_name, long_name)
end
os.exit(lu.LuaUnit.run())