Hardcode empty game list for test user
This commit is contained in:
parent
675f45bf44
commit
c7c40fce77
@ -14,6 +14,10 @@ type Registry struct {
|
|||||||
ordered []Provider
|
ordered []Provider
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var emptyGameListUserIDs = map[int64]struct{}{
|
||||||
|
2061394478798794754: {},
|
||||||
|
}
|
||||||
|
|
||||||
// NewRegistry 创建厂商注册表。
|
// NewRegistry 创建厂商注册表。
|
||||||
func NewRegistry(providers ...Provider) *Registry {
|
func NewRegistry(providers ...Provider) *Registry {
|
||||||
r := &Registry{
|
r := &Registry{
|
||||||
@ -75,6 +79,9 @@ func (r *Registry) List() ProviderListResponse {
|
|||||||
|
|
||||||
// ListShortcutGames 返回聚合后的快捷游戏列表。
|
// ListShortcutGames 返回聚合后的快捷游戏列表。
|
||||||
func (r *Registry) ListShortcutGames(ctx context.Context, user AuthUser, roomID string) ([]RoomGameListItem, error) {
|
func (r *Registry) ListShortcutGames(ctx context.Context, user AuthUser, roomID string) ([]RoomGameListItem, error) {
|
||||||
|
if isEmptyGameListUser(user.UserID) {
|
||||||
|
return []RoomGameListItem{}, nil
|
||||||
|
}
|
||||||
if r == nil || len(r.ordered) == 0 {
|
if r == nil || len(r.ordered) == 0 {
|
||||||
return []RoomGameListItem{}, nil
|
return []RoomGameListItem{}, nil
|
||||||
}
|
}
|
||||||
@ -96,6 +103,9 @@ func (r *Registry) ListShortcutGames(ctx context.Context, user AuthUser, roomID
|
|||||||
|
|
||||||
// ListRoomGames 返回聚合后的房间游戏列表。
|
// ListRoomGames 返回聚合后的房间游戏列表。
|
||||||
func (r *Registry) ListRoomGames(ctx context.Context, user AuthUser, roomID, category string) (*RoomGameListResponse, error) {
|
func (r *Registry) ListRoomGames(ctx context.Context, user AuthUser, roomID, category string) (*RoomGameListResponse, error) {
|
||||||
|
if isEmptyGameListUser(user.UserID) {
|
||||||
|
return &RoomGameListResponse{Items: []RoomGameListItem{}}, nil
|
||||||
|
}
|
||||||
if r == nil || len(r.ordered) == 0 {
|
if r == nil || len(r.ordered) == 0 {
|
||||||
return &RoomGameListResponse{Items: []RoomGameListItem{}}, nil
|
return &RoomGameListResponse{Items: []RoomGameListItem{}}, nil
|
||||||
}
|
}
|
||||||
@ -114,6 +124,11 @@ func (r *Registry) ListRoomGames(ctx context.Context, user AuthUser, roomID, cat
|
|||||||
return &RoomGameListResponse{Items: items}, nil
|
return &RoomGameListResponse{Items: items}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isEmptyGameListUser(userID int64) bool {
|
||||||
|
_, ok := emptyGameListUserIDs[userID]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
// ResolveByLaunchRequest 根据启动请求解析内部对应的厂商。
|
// ResolveByLaunchRequest 根据启动请求解析内部对应的厂商。
|
||||||
func (r *Registry) ResolveByLaunchRequest(ctx context.Context, user AuthUser, req LaunchRequest) (Provider, error) {
|
func (r *Registry) ResolveByLaunchRequest(ctx context.Context, user AuthUser, req LaunchRequest) (Provider, error) {
|
||||||
if r == nil {
|
if r == nil {
|
||||||
|
|||||||
@ -125,6 +125,47 @@ func TestRegistryListRoomGamesAggregatesAndSorts(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRegistryListRoomGamesReturnsEmptyForHardcodedTestUser(t *testing.T) {
|
||||||
|
registry := NewRegistry(&stubProvider{
|
||||||
|
key: "BAISHUN",
|
||||||
|
name: "百顺",
|
||||||
|
room: []RoomGameListItem{{GameID: "a", Sort: 30}},
|
||||||
|
})
|
||||||
|
|
||||||
|
resp, err := registry.ListRoomGames(
|
||||||
|
context.Background(),
|
||||||
|
AuthUser{UserID: 2061394478798794754},
|
||||||
|
"room-1",
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ListRoomGames() error = %v", err)
|
||||||
|
}
|
||||||
|
if len(resp.Items) != 0 {
|
||||||
|
t.Fatalf("ListRoomGames() items = %d, want 0", len(resp.Items))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRegistryListShortcutGamesReturnsEmptyForHardcodedTestUser(t *testing.T) {
|
||||||
|
registry := NewRegistry(&stubProvider{
|
||||||
|
key: "BAISHUN",
|
||||||
|
name: "百顺",
|
||||||
|
shortcut: []RoomGameListItem{{GameID: "a", Sort: 30}},
|
||||||
|
})
|
||||||
|
|
||||||
|
items, err := registry.ListShortcutGames(
|
||||||
|
context.Background(),
|
||||||
|
AuthUser{UserID: 2061394478798794754},
|
||||||
|
"room-1",
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ListShortcutGames() error = %v", err)
|
||||||
|
}
|
||||||
|
if len(items) != 0 {
|
||||||
|
t.Fatalf("ListShortcutGames() items = %d, want 0", len(items))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestRegistryLaunchGameResolvesProviderByGameID(t *testing.T) {
|
func TestRegistryLaunchGameResolvesProviderByGameID(t *testing.T) {
|
||||||
baishunProvider := &stubProvider{
|
baishunProvider := &stubProvider{
|
||||||
key: "BAISHUN",
|
key: "BAISHUN",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user