11local water = require (" water" )
22
3+ _G .os .time = spy .new (function () return 100 end )
4+ _G .to_unix = spy .new (function () return 100 - 10 * 86400 end )
35_G .dispense = spy .new (function () end )
46_G .get_curve = spy .new (function ()
57 return { day = function () return 100 end }
@@ -22,7 +24,7 @@ describe("water()", function()
2224 _G .complete_job :clear ()
2325 end )
2426
25- it (" gets water amount and calls dispense()" , function ()
27+ it (" gets water amount from age and calls dispense()" , function ()
2628 local plant = {
2729 name = " Plant" ,
2830 age = 10 ,
@@ -43,6 +45,27 @@ describe("water()", function()
4345 assert .spy (complete_job ).was .called_with (" Watering Plant at (1, 2)" )
4446 end )
4547
48+ it (" gets water amount from planted_at and calls dispense()" , function ()
49+ local plant = {
50+ name = " Plant" ,
51+ planted_at = " 2021-03-31T19:42:18.173Z" ,
52+ water_curve_id = 1 ,
53+ x = 1 ,
54+ y = 2 ,
55+ z = 3 ,
56+ }
57+ water (plant )
58+
59+ assert .spy (get_curve ).was .called_with (1 )
60+ assert .spy (toast ).was_not_called ()
61+ assert .spy (set_job ).was .called_with (" Watering Plant at (1, 2)" , { status = " Moving" })
62+ assert .spy (move ).was .called_with ({x = 1 , y = 2 , z = 0 })
63+ assert .spy (set_job ).was .called_with (" Watering Plant at (1, 2)" , { status = " Watering" , percent = 50 })
64+ assert .spy (send_message ).was .called_with (" info" , " Watering 10 day old Plant at (1, 2) 100mL" )
65+ assert .spy (dispense ).was .called_with (100 , nil )
66+ assert .spy (complete_job ).was .called_with (" Watering Plant at (1, 2)" )
67+ end )
68+
4669 it (" passes params" , function ()
4770 local plant = {
4871 name = " Plant" ,
0 commit comments