package service

import (
	"testing"

	"hyapp/services/room-service/internal/room/outbox"
)

func TestSortOutboxRecordsPrioritizesGiftDisplay(t *testing.T) {
	// 低优先级事件故意给更早 created_at_ms，验证 worker 不会让热度/榜单压住礼物展示。
	records := []outbox.Record{
		{EventID: "rank", EventType: "RoomRankChanged", CreatedAtMS: 1},
		{EventID: "gift", EventType: "RoomGiftSent", CreatedAtMS: 2},
		{EventID: "other", EventType: "RoomNoticeCreated", CreatedAtMS: 0},
		{EventID: "heat", EventType: "RoomHeatChanged", CreatedAtMS: 0},
	}

	sortOutboxRecords(records)

	got := []string{records[0].EventID, records[1].EventID, records[2].EventID, records[3].EventID}
	want := []string{"gift", "other", "heat", "rank"}
	for index := range want {
		if got[index] != want[index] {
			t.Fatalf("priority order mismatch got=%v want=%v", got, want)
		}
	}
}
