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' => '活动已结束或已过期。']); } }