测试: 完成游戏娱乐模块 (Gomoku, HorseRace, Lottery 等) 功能全量联调测试与代码格式化
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\HolidayClaim;
|
||||
use App\Models\HolidayEvent;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class HolidayControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_can_check_holiday_status()
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create();
|
||||
$event = HolidayEvent::create([
|
||||
'name' => 'Test Holiday',
|
||||
'status' => 'active',
|
||||
'expires_at' => now()->addDays(1),
|
||||
'max_claimants' => 10,
|
||||
'claimed_amount' => 0,
|
||||
'total_amount' => 5000,
|
||||
'distribute_type' => 'fixed',
|
||||
'send_at' => now(),
|
||||
'repeat_type' => 'once',
|
||||
'target_type' => 'all',
|
||||
]);
|
||||
|
||||
HolidayClaim::create([
|
||||
'event_id' => $event->id,
|
||||
'user_id' => $user->id,
|
||||
'amount' => 500,
|
||||
'claimed_at' => now(),
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)->getJson(route('holiday.status', ['event' => $event->id]));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson([
|
||||
'claimable' => true,
|
||||
'amount' => 500,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_can_claim_holiday_bonus()
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create(['jjb' => 100]);
|
||||
$event = HolidayEvent::create([
|
||||
'name' => 'Test Holiday',
|
||||
'status' => 'active',
|
||||
'expires_at' => now()->addDays(1),
|
||||
'max_claimants' => 10,
|
||||
'claimed_amount' => 0,
|
||||
'total_amount' => 5000,
|
||||
'distribute_type' => 'fixed',
|
||||
'send_at' => now(),
|
||||
'repeat_type' => 'once',
|
||||
'target_type' => 'all',
|
||||
]);
|
||||
|
||||
HolidayClaim::create([
|
||||
'event_id' => $event->id,
|
||||
'user_id' => $user->id,
|
||||
'amount' => 500,
|
||||
'claimed_at' => now(),
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('holiday.claim', ['event' => $event->id]));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['ok' => true]);
|
||||
|
||||
// Verify currency incremented
|
||||
$this->assertEquals(600, $user->fresh()->jjb);
|
||||
|
||||
// Verify claim is deleted
|
||||
$this->assertDatabaseMissing('holiday_claims', [
|
||||
'event_id' => $event->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_cannot_claim_if_not_in_list()
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create();
|
||||
$event = HolidayEvent::create([
|
||||
'name' => 'Test Holiday',
|
||||
'status' => 'active',
|
||||
'expires_at' => now()->addDays(1),
|
||||
'max_claimants' => 10,
|
||||
'claimed_amount' => 0,
|
||||
'total_amount' => 5000,
|
||||
'distribute_type' => 'fixed',
|
||||
'send_at' => now(),
|
||||
'repeat_type' => 'once',
|
||||
'target_type' => 'all',
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('holiday.claim', ['event' => $event->id]));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['ok' => false, 'message' => '您不在本次福利名单内,或活动已结束。']);
|
||||
}
|
||||
|
||||
public function test_cannot_claim_if_expired()
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = User::factory()->create();
|
||||
$event = HolidayEvent::create([
|
||||
'name' => 'Test Holiday',
|
||||
'status' => 'completed',
|
||||
'expires_at' => now()->subDays(1),
|
||||
'max_claimants' => 10,
|
||||
'claimed_amount' => 0,
|
||||
'total_amount' => 5000,
|
||||
'distribute_type' => 'fixed',
|
||||
'send_at' => now(),
|
||||
'repeat_type' => 'once',
|
||||
'target_type' => 'all',
|
||||
]);
|
||||
|
||||
HolidayClaim::create([
|
||||
'event_id' => $event->id,
|
||||
'user_id' => $user->id,
|
||||
'amount' => 500,
|
||||
'claimed_at' => now(),
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user)->postJson(route('holiday.claim', ['event' => $event->id]));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['ok' => false, 'message' => '活动已结束或已过期。']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user