aboutsummaryrefslogtreecommitdiff
path: root/spec/welfare_spec.lua
blob: d41cf71f62cde97e7213ba242147e9d12c656050 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require("mineunit")

mineunit("core")

mineunit("common/chatcommands")
mineunit("server")
mineunit("player")

sourcefile("init")

mineunit:mods_loaded()

minetest.safe_file_write = function ()

end

describe("Welfare payout", function()
				it("sets up balance correctly", function()
						local newplayer = Player("newplayer")
						mineunit:execute_on_joinplayer(newplayer)
						atm.ensure_init("newplayer")
						assert.equals(atm.balance["newplayer"], atm.startbalance)
				end)
				it("pays out welfare to players", function()
						atm.ensure_init("newplayer")
						local oldbalance = atm.balance["newplayer"]
						atm.welfare_payout()
						assert.equals(atm.balance["newplayer"], oldbalance + atm.welfare_amount)
						assert.equals(atm.welfare["newplayer"], atm.welfare_cap - atm.welfare_amount)
				end)
				it("does not payout welfare if welfare cap is exhausted", function()
						atm.ensure_init("newplayer")
						local oldbalance = atm.balance["newplayer"]
						atm.welfare["newplayer"] = atm.welfare_amount - 1
						local oldwelfare = atm.welfare['newplayer']
						atm.welfare_payout()
						assert.equals(atm.balance["newplayer"], oldbalance)
						assert.equals(atm.welfare["newplayer"], oldwelfare)
				end)
				it("allows moderators to put players on welfare", function()
						local moderator =  Player("admin", {kick = true, ban = true})
						moderator:send_chat_message("/give_welfare newplayer 555")
						assert.equals(atm.welfare["newplayer"], 555)
						moderator:send_chat_message("/give_welfare newplayer bbbb")
						assert.equals(atm.welfare["newplayer"], 555)
				end)
				it("bans normal players from giving themselves welfare", function()
						local player = Player("foobar")
						mineunit:execute_on_joinplayer(player)
						atm.welfare_payout()
						local oldwelfare = atm.welfare['foobar']
						player:send_chat_message("/give_welfare foobar 555")
						assert.equals(atm.welfare["foobar"], oldwelfare)
				end)
				
end
)