Skip to content

Commit

Permalink
Make Twitter DNS query case insensitive (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffyanta committed Jun 10, 2024
1 parent fe26d1f commit 8fd80f4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pkg/code/data/twitter/memory/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package memory
import (
"context"
"sort"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -158,7 +159,7 @@ func (s *store) findUser(data *twitter.Record) *twitter.Record {
if item.Id == data.Id {
return item
}
if data.Username == item.Username {
if strings.EqualFold(data.Username, item.Username) {
return item
}
}
Expand All @@ -168,7 +169,7 @@ func (s *store) findUser(data *twitter.Record) *twitter.Record {

func (s *store) findUserByUsername(username string) *twitter.Record {
for _, item := range s.userRecords {
if username == item.Username {
if strings.EqualFold(username, item.Username) {
return item
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/code/data/twitter/postgres/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func dbGetUserByUsername(ctx context.Context, db *sqlx.DB, username string) (*mo
query := `SELECT
id, username, name, profile_pic_url, verified_type, follower_count, tip_address, created_at, last_updated_at
FROM ` + userTableName + `
WHERE username = $1
WHERE LOWER(username) = LOWER($1)
LIMIT 1`

err := db.GetContext(ctx, res, query, username)
Expand Down
7 changes: 4 additions & 3 deletions pkg/code/data/twitter/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tests
import (
"context"
"fmt"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -31,7 +32,7 @@ func testUserHappyPath(t *testing.T, s twitter.Store) {
t.Run("testUserHappyPath", func(t *testing.T) {
ctx := context.Background()

username := "jeffyanta"
username := "JeffYanta"
tipAddress1 := "tip_address_1"
tipAddress2 := "tip_address_2"

Expand Down Expand Up @@ -73,7 +74,7 @@ func testUserHappyPath(t *testing.T, s twitter.Store) {
require.NoError(t, s.SaveUser(ctx, expected))
assert.True(t, expected.LastUpdatedAt.After(expected.CreatedAt))

actual, err = s.GetUserByUsername(ctx, username)
actual, err = s.GetUserByUsername(ctx, strings.ToLower(username))
require.NoError(t, err)
assertEquivalentRecords(t, &cloned, actual)

Expand All @@ -86,7 +87,7 @@ func testUserHappyPath(t *testing.T, s twitter.Store) {
require.NoError(t, s.SaveUser(ctx, expected))
assert.True(t, expected.LastUpdatedAt.After(expected.CreatedAt))

actual, err = s.GetUserByUsername(ctx, username)
actual, err = s.GetUserByUsername(ctx, strings.ToUpper(username))
require.NoError(t, err)
assertEquivalentRecords(t, &cloned, actual)

Expand Down

0 comments on commit 8fd80f4

Please sign in to comment.