diff --git a/.check_date.sh b/.check_date.sh index 7310fde..831a6dd 100755 --- a/.check_date.sh +++ b/.check_date.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -grep $(date -I) mod.conf +grep $(date -u -I) mod.conf exit $? diff --git a/mod.conf b/mod.conf index 7f36e8e..ec55ebe 100644 --- a/mod.conf +++ b/mod.conf @@ -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 diff --git a/tests/init.lua b/tests/init.lua index 37c152b..0505fc5 100644 --- a/tests/init.lua +++ b/tests/init.lua @@ -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") diff --git a/tests/split_payment_stack.lua b/tests/split_payment_stack.lua new file mode 100644 index 0000000..cd00ade --- /dev/null +++ b/tests/split_payment_stack.lua @@ -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, +})