fix(gacha): validate reward pool before charging currency (#175)

Filter out gacha entries with no items at the query level (EXISTS
subquery) and reorder Play methods to validate the pool before
calling transact(), so players are never charged for a misconfigured
gacha.
This commit is contained in:
Houmgaor
2026-03-10 11:28:11 +01:00
parent 915e9bc0b0
commit 2365b63e9c
4 changed files with 52 additions and 19 deletions

View File

@@ -27,6 +27,7 @@ func TestGachaService_PlayNormalGacha(t *testing.T) {
}{
{
name: "transact error",
pool: []GachaEntry{{ID: 10, Weight: 100}},
txErr: errors.New("tx fail"),
wantErr: true,
},
@@ -36,6 +37,10 @@ func TestGachaService_PlayNormalGacha(t *testing.T) {
poolErr: errors.New("pool fail"),
wantErr: true,
},
{
name: "empty reward pool",
wantErr: true,
},
{
name: "success single roll",
txRolls: 1,
@@ -95,6 +100,7 @@ func TestGachaService_PlayStepupGacha(t *testing.T) {
}{
{
name: "transact error",
pool: []GachaEntry{{ID: 10, Weight: 100}},
txErr: errors.New("tx fail"),
wantErr: true,
},
@@ -104,6 +110,10 @@ func TestGachaService_PlayStepupGacha(t *testing.T) {
poolErr: errors.New("pool fail"),
wantErr: true,
},
{
name: "empty reward pool",
wantErr: true,
},
{
name: "success with guaranteed",
txRolls: 1,