forked from mt-mods/mail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.spec.lua
45 lines (37 loc) · 1.11 KB
/
storage.spec.lua
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
mtt.register("storage", function(callback)
-- sanity checks
local playername = "player1"
local entry = mail.get_storage_entry(playername)
assert(entry)
-- create
local contact = {
name = "other-player",
note = "my-note"
}
mail.update_contact(playername, contact)
-- read
local contacts = mail.get_contacts(playername)
assert(#contacts == 1)
assert(contacts[1].note == contact.note)
assert(contacts[1].name == contact.name)
-- read through api
local contacts2 = mail.get_contacts(playername)
assert(#contacts2 == 1)
assert(contacts2[1].note == contact.note)
assert(contacts2[1].name == contact.name)
-- update
mail.update_contact(playername, {
name = contact.name,
note = "xy"
})
-- read updated
contacts = mail.get_contacts(playername)
assert(#contacts == 1)
assert(contacts[1].note == "xy")
assert(contacts[1].name == contact.name)
-- delete
mail.delete_contact(playername, contact.name)
contacts = mail.get_contacts(playername)
assert(#contacts == 0)
callback()
end)