Skip to content

Commit

Permalink
add tests for split payment stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxionary committed Feb 8, 2024
1 parent 299d9af commit 54bc01c
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .check_date.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
grep $(date -I) mod.conf
grep $(date -u -I) mod.conf
exit $?
2 changes: 1 addition & 1 deletion mod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ website = https://content.minetest.net/packages/rheo/smartshop/
author = fluxionary
license = LGPL-3.0-or-later
media_license = CC-BY-SA-3.0
version = 2024-01-12
version = 2024-02-08
min_minetest_version = 5.8.0
supported_games = *
depends = fmod, futil
Expand Down
1 change: 1 addition & 0 deletions tests/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ smartshop.dofile("tests", "currency")
smartshop.dofile("tests", "shop_full")
smartshop.dofile("tests", "strict_meta")
smartshop.dofile("tests", "admin_shop")
smartshop.dofile("tests", "split_payment_stack")
131 changes: 131 additions & 0 deletions tests/split_payment_stack.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
local inv_count = smartshop.tests.inv_count

smartshop.tests.register_test({
name = "split payment purchase",
func = function(player, state)
minetest.set_player_privs(player:get_player_name(), {
interact = true,
server = true,
[smartshop.settings.admin_shop_priv] = true,
})

local under = state.place_shop_against
local shop_at = vector.subtract(state.place_shop_against, vector.new(0, 0, 1))

minetest.remove_node(shop_at)
minetest.item_place_node(ItemStack("smartshop:shop"), player, { type = "node", under = under, above = shop_at })

local shop = smartshop.api.get_object(shop_at)

shop.inv:set_stack("pay3", 1, "smartshop:currency_1 2")
shop.inv:set_stack("give3", 1, "smartshop:gold 99")
shop:update_appearance()

local player_inv = player:get_inventory()
player_inv:set_list("main", {
"smartshop:currency_1 97",
"smartshop:currency_1 2",
"smartshop:gold",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
})

shop:receive_fields(player, { buy3a = true })

assert(inv_count(player_inv, "main", "smartshop:gold") == 100, "correct amount was received")
assert(inv_count(player_inv, "main", "smartshop:currency_1") == 97, "correct amount was spent")
assert(inv_count(player_inv, "main", "smartshop:tool") == 29, "tools not replaced")
end,
})

smartshop.tests.register_test({
name = "split payment purchase failure",
func = function(player, state)
minetest.set_player_privs(player:get_player_name(), {
interact = true,
server = true,
[smartshop.settings.admin_shop_priv] = true,
})

local under = state.place_shop_against
local shop_at = vector.subtract(state.place_shop_against, vector.new(0, 0, 1))

minetest.remove_node(shop_at)
minetest.item_place_node(ItemStack("smartshop:shop"), player, { type = "node", under = under, above = shop_at })

local shop = smartshop.api.get_object(shop_at)

shop.inv:set_stack("pay3", 1, "smartshop:currency_1 2")
shop.inv:set_stack("give3", 1, "smartshop:gold 99")
shop:update_appearance()

local player_inv = player:get_inventory()
player_inv:set_list("main", {
"smartshop:currency_1 2",
"smartshop:currency_1 97",
"smartshop:gold",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
"smartshop:tool",
})

shop:receive_fields(player, { buy3a = true })

assert(inv_count(player_inv, "main", "smartshop:gold") == 1, "correct amount was received")
assert(inv_count(player_inv, "main", "smartshop:currency_1") == 99, "correct amount was spent")
assert(inv_count(player_inv, "main", "smartshop:tool") == 29, "tools not replaced")
end,
})

0 comments on commit 54bc01c

Please sign in to comment.