优化聊天室烟花特效表现与卡顿问题
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Events\EffectBroadcast;
|
||||
use App\Events\MessageSent;
|
||||
use App\Models\ShopItem;
|
||||
use App\Models\User;
|
||||
@@ -250,4 +251,53 @@ class ShopControllerTest extends TestCase
|
||||
&& str_contains((string) ($event->message['content'] ?? ''), $item->name);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试指定接收人购买单次特效时,购买者本端仍会拿到播放指令,且广播会带上接收人与操作者信息。
|
||||
*/
|
||||
public function test_buy_instant_effect_for_recipient_returns_local_play_and_broadcasts_targeted_event(): void
|
||||
{
|
||||
Event::fake([EffectBroadcast::class]);
|
||||
|
||||
$buyer = User::factory()->create([
|
||||
'username' => 'buyer-user',
|
||||
'jjb' => 5000,
|
||||
]);
|
||||
$recipient = User::factory()->create([
|
||||
'username' => 'receiver-user',
|
||||
]);
|
||||
|
||||
$item = ShopItem::create([
|
||||
'name' => '烟花单次卡',
|
||||
'slug' => 'once_fireworks_targeted',
|
||||
'type' => 'instant',
|
||||
'price' => 888,
|
||||
'icon' => '🎆',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($buyer)->postJson(route('shop.buy'), [
|
||||
'item_id' => $item->id,
|
||||
'room_id' => 1,
|
||||
'recipient' => $recipient->username,
|
||||
'message' => '送你一场烟花',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson([
|
||||
'status' => 'success',
|
||||
'play_effect' => $item->effectKey(),
|
||||
'target_username' => $recipient->username,
|
||||
'gift_message' => '送你一场烟花',
|
||||
]);
|
||||
|
||||
Event::assertDispatched(EffectBroadcast::class, function (EffectBroadcast $event) use ($buyer, $recipient, $item): bool {
|
||||
return $event->roomId === 1
|
||||
&& $event->type === $item->effectKey()
|
||||
&& $event->operator === $buyer->username
|
||||
&& $event->targetUsername === $recipient->username
|
||||
&& $event->giftMessage === '送你一场烟花'
|
||||
&& $event->broadcastWith()['operator'] === $buyer->username;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user