|
|
@@ -59,7 +59,7 @@ class SiteMessageTest extends TestCase
|
|
|
$t->id(); $t->string('resource_type'); $t->integer('resource_id'); $t->string('action'); $t->json('changes');
|
|
|
$t->integer('operator_id')->nullable(); $t->string('operator_name'); $t->timestamp('created_at')->useCurrent();
|
|
|
});
|
|
|
- $this->migration()->up();
|
|
|
+ $this->migration()->up(); (require dirname(__DIR__, 2) . '/database/migrations/2026_10_27_150000_create_site_realtime_events.php')->up();
|
|
|
foreach ([1 => ['zh', 1], 2 => ['en', 1], 3 => ['vi', 1], 4 => [null, 1], 5 => ['zh', -1], 6 => ['zh', 2], 7 => ['zh', 0], 8 => ['zh', 1]] as $id => [$lang, $from]) {
|
|
|
DB::table('users')->insert(['id' => $id, 'user_id' => (string) (100 + $id), 'member_id' => 'M' . $id, 'account' => 'member' . $id,
|
|
|
'username' => 'name' . $id, 'first_name' => '昵称' . $id, 'language' => $lang, 'from' => $from, 'delete_time' => $id === 8 ? now() : null]);
|
|
|
@@ -96,6 +96,22 @@ class SiteMessageTest extends TestCase
|
|
|
$this->expectException(ValidationException::class); $this->send(['request_id' => 'same', 'category' => 'promotion']);
|
|
|
}
|
|
|
|
|
|
+ public function test_websocket_events_are_committed_with_delivery_and_retraction_and_retries_do_not_duplicate(): void
|
|
|
+ {
|
|
|
+ $message = $this->send(['request_id' => 'push-once']); $this->send(['request_id' => 'push-once']);
|
|
|
+ $this->assertSame(1, DB::table('site_realtime_events')->count());
|
|
|
+ $this->assertSame('message', DB::table('site_realtime_events')->first()->module);
|
|
|
+ $this->assertSame($message['id'], (int) DB::table('site_realtime_events')->first()->resource_id);
|
|
|
+ $this->service->retract($message['id']); $this->service->retract($message['id']);
|
|
|
+ $this->assertSame(['send', 'retract'], DB::table('site_realtime_events')->orderBy('id')->pluck('action')->all());
|
|
|
+ $this->send(['send_at' => '2026-10-26 11:00:00']);
|
|
|
+ $this->assertSame(2, DB::table('site_realtime_events')->count());
|
|
|
+ Carbon::setTestNow(Carbon::parse('2026-10-26 11:00:00', 'Asia/Shanghai')); $this->service->dispatchDue();
|
|
|
+ $this->assertSame(3, DB::table('site_realtime_events')->count());
|
|
|
+ DB::beginTransaction(); $this->send(); DB::rollBack();
|
|
|
+ $this->assertSame(3, DB::table('site_realtime_events')->count());
|
|
|
+ }
|
|
|
+
|
|
|
public function test_specified_users_and_agents_use_distinct_id_namespaces_and_retraction_hides_every_read_path(): void
|
|
|
{
|
|
|
$user = $this->send(['recipient_type' => 'specified_users', 'recipient_ids' => [1, 2, 1], 'request_id' => 'select']);
|