make claim command case insensitive

Fixes #3
absences v0.3.0
William Perron 2 years ago
parent ad22f31bcd
commit bd490bc18f

@ -108,12 +108,12 @@ func (s *Store) Claim(ctx context.Context, userId, player, province string, clai
} }
// check that provided name matches the claim type // check that provided name matches the claim type
stmt, err := s.db.PrepareContext(ctx, fmt.Sprintf(`SELECT COUNT(1) FROM provinces WHERE provinces.%s = ?`, claimTypeToColumn[claimType])) stmt, err := s.db.PrepareContext(ctx, fmt.Sprintf(`SELECT COUNT(1) FROM provinces WHERE LOWER(provinces.%s) = ?`, claimTypeToColumn[claimType]))
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to prepare count query: %w", err) return 0, fmt.Errorf("failed to prepare count query: %w", err)
} }
row := stmt.QueryRowContext(ctx, province) row := stmt.QueryRowContext(ctx, strings.ToLower(province))
var count int var count int
err = row.Scan(&count) err = row.Scan(&count)
if err != nil { if err != nil {

@ -68,6 +68,26 @@ func TestStore_Claim(t *testing.T) {
}, },
wantErr: false, wantErr: false,
}, },
{
name: "case sensitivity lower",
args: args{
player: "foo",
province: "wien",
claimType: CLAIM_TYPE_TRADE,
userId: "000000000000000001",
},
wantErr: false,
},
{
name: "case sensitivity upper",
args: args{
player: "foo",
province: "CONSTANTINOPLE",
claimType: CLAIM_TYPE_TRADE,
userId: "000000000000000001",
},
wantErr: false,
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {

Loading…
Cancel
Save