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
59
60
61
62
63
64
65
66
67
68
69
|
require("mineunit")
mineunit("core")
mineunit("common/chatcommands")
mineunit("server")
mineunit("player")
mineunit("settings")
mineunit("auth")
sourcefile("init")
mineunit:mods_loaded()
local exists = minetest.player_exists
local settings = core.settings
describe("Afk works", function()
local admin = Player("admin", {kick = true, ban = true})
setup(function()
minetest.check_password_entry = function()
return false
end
mineunit:execute_on_joinplayer(admin)
end)
it("Sets afk status correctly", function ()
admin:send_chat_message('/mod_afk on')
assert.equals(xban.present["admin"],nil)
admin:send_chat_message('/mod_afk off')
assert.equals(xban.present["admin"],true)
end)
it("Allows new players to join by default", function()
minetest.player_exists = function()
return false
end
local newplayer = Player("newplayer")
mineunit:execute_on_joinplayer(newplayer)
assert.is_true(newplayer._online)
end)
it("Rejects players if no moderator is active", function()
local newplayer = Player("newplayer2")
xban.present = {}
minetest.settings = Settings("moderate.conf")
mineunit:execute_on_joinplayer(newplayer)
assert.is_not_true(newplayer._online)
end)
it("Allows a new player if there is an online moderator", function ()
local newplayer = Player("newplayer3")
admin:send_chat_message('/mod_afk off')
mineunit:execute_on_joinplayer(newplayer)
assert.is_true(newplayer._online)
end)
it("Bans passwordless accounts and allows accounts with password", function ()
local newplayer = Player("newplayer3")
mineunit:execute_on_joinplayer(newplayer)
assert.is_true(newplayer._online)
minetest.check_password_entry = function()
return true
end
local newplayer2 = Player("newplayer4")
mineunit:execute_on_joinplayer(admin)
assert.is_false(newplayer2._online)
end)
it("Can force moderators to be marked afk", function ()
local moderator = Player("moderator", {kick = true, ban = true})
assert.is_true(xban.present["admin"])
moderator:send_chat_message('/force_afk admin')
assert.is_not_true(xban.present["admin"])
end)
end)
|