新增每日签到与补签卡功能

This commit is contained in:
2026-04-24 22:47:27 +08:00
parent 34356a26ae
commit be9fc09d9d
46 changed files with 3934 additions and 55 deletions
+58
View File
@@ -300,4 +300,62 @@ class ShopControllerTest extends TestCase
&& $event->broadcastWith()['operator'] === $buyer->username;
});
}
/**
* 测试购买签到补签卡会扣金币并生成可用背包记录。
*/
public function test_buy_sign_repair_card_creates_active_purchase(): void
{
$user = User::factory()->create(['jjb' => 12000]);
$item = ShopItem::query()->where('slug', 'sign_repair_card')->firstOrFail();
$item->update([
'price' => 10000,
'is_active' => true,
]);
$response = $this->actingAs($user)->postJson(route('shop.buy'), [
'item_id' => $item->id,
]);
$response->assertOk()
->assertJsonPath('status', 'success')
->assertJsonPath('jjb', 2000);
$this->assertDatabaseHas('user_purchases', [
'user_id' => $user->id,
'shop_item_id' => $item->id,
'status' => 'active',
'price_paid' => 10000,
]);
}
/**
* 测试补签卡支持一次购买多张。
*/
public function test_buy_sign_repair_card_supports_quantity(): void
{
$user = User::factory()->create(['jjb' => 35000]);
$item = ShopItem::query()->where('slug', 'sign_repair_card')->firstOrFail();
$item->update([
'price' => 10000,
'is_active' => true,
]);
$response = $this->actingAs($user)->postJson(route('shop.buy'), [
'item_id' => $item->id,
'quantity' => 3,
]);
$response->assertOk()
->assertJsonPath('status', 'success')
->assertJsonPath('quantity', 3)
->assertJsonPath('total_price', 30000)
->assertJsonPath('jjb', 5000);
$this->assertSame(3, UserPurchase::query()
->where('user_id', $user->id)
->where('shop_item_id', $item->id)
->where('status', 'active')
->count());
}
}