47 lines
1.6 KiB
Go
47 lines
1.6 KiB
Go
package roomadmin
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestNormalizeRoomPinListQueryDefaultsToActive(t *testing.T) {
|
|
query := normalizeRoomPinListQuery(roomPinListQuery{Page: -1, PageSize: 200, Status: "unknown", RegionID: -10, Keyword: " 123 "})
|
|
if query.Page != 1 || query.PageSize != 100 {
|
|
t.Fatalf("pagination normalization mismatch: %+v", query)
|
|
}
|
|
if query.Status != roomPinStatusActive || query.RegionID != 0 || query.Keyword != "123" {
|
|
t.Fatalf("filter normalization mismatch: %+v", query)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeCreateRoomPinRequestDefaultsDuration(t *testing.T) {
|
|
req, err := normalizeCreateRoomPinRequest(createRoomPinRequest{RoomID: " room-1 ", Weight: 10})
|
|
if err != nil {
|
|
t.Fatalf("normalize create pin failed: %v", err)
|
|
}
|
|
if req.RoomID != "room-1" || req.DurationDays != defaultRoomPinDays || req.Weight != 10 {
|
|
t.Fatalf("create pin normalization mismatch: %+v", req)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeCreateRoomPinRequestRejectsInvalidInput(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
req createRoomPinRequest
|
|
}{
|
|
{name: "empty_room", req: createRoomPinRequest{Weight: 1, DurationDays: 30}},
|
|
{name: "negative_weight", req: createRoomPinRequest{RoomID: "room-1", Weight: -1, DurationDays: 30}},
|
|
{name: "duration_too_large", req: createRoomPinRequest{RoomID: "room-1", Weight: 1, DurationDays: maxRoomPinDays + 1}},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
_, err := normalizeCreateRoomPinRequest(test.req)
|
|
if !errors.Is(err, ErrInvalidArgument) {
|
|
t.Fatalf("expected ErrInvalidArgument, got %v", err)
|
|
}
|
|
})
|
|
}
|
|
}
|