feat: sqlite: implement GetUserByUsername
This commit is contained in:
parent
9220753210
commit
6e1ac07b04
3 changed files with 77 additions and 6 deletions
|
|
@ -29,6 +29,7 @@ type SuiteStore interface {
|
|||
CreateUser(ctx context.Context, u *store.User) error
|
||||
GetUserByID(ctx context.Context, id string) (*store.User, error)
|
||||
GetUserByEmail(ctx context.Context, email string) (*store.User, error)
|
||||
GetUserByUsername(ctx context.Context, username string) (*store.User, error)
|
||||
}
|
||||
|
||||
// Factory returns a fresh, isolated Store. Each call to the factory must
|
||||
|
|
@ -56,6 +57,9 @@ func RunSuite(t *testing.T, newStore Factory) {
|
|||
{"CreateUser_duplicateUsernameNormalized", testCreateUserDuplicateUsernameNormalized},
|
||||
{"CreateUser_GetUserByEmail_roundTrip", testCreateUserGetUserByEmailRoundTrip},
|
||||
{"GetUserByEmail_notFound", testGetUserByEmailNotFound},
|
||||
{"CreateUser_GetUserByUsername_roundTrip", testCreateUserGetUserByUsernameRoundTrip},
|
||||
{"GetUserByUsername_notFound", testGetUserByUsernameNotFound},
|
||||
{"GetUserByUsername_notNormalized_notFound", testGetUserByUsernameNotNormalized},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
|
@ -167,6 +171,49 @@ func testGetUserByEmailNotFound(t *testing.T, s SuiteStore) {
|
|||
}
|
||||
}
|
||||
|
||||
func testCreateUserGetUserByUsernameRoundTrip(t *testing.T, s SuiteStore) {
|
||||
ctx := context.Background()
|
||||
|
||||
want := FixedUser()
|
||||
if err := s.CreateUser(ctx, want); err != nil {
|
||||
t.Fatalf("CreateUser: %v", err)
|
||||
}
|
||||
|
||||
got, err := s.GetUserByUsername(ctx, want.UsernameNormalized.String)
|
||||
if err != nil {
|
||||
t.Fatalf("GetUserByUsername (normalized username): %v", err)
|
||||
}
|
||||
|
||||
AssertUserEqual(t, got, want)
|
||||
}
|
||||
|
||||
func testGetUserByUsernameNotFound(t *testing.T, s SuiteStore) {
|
||||
got, err := s.GetUserByUsername(context.Background(), "does-not-exists")
|
||||
if err == nil {
|
||||
t.Fatalf("expected error, got user %+v", got)
|
||||
}
|
||||
if !errors.Is(err, store.ErrUserNotFound) {
|
||||
t.Errorf("expected ErrUserNotFound, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func testGetUserByUsernameNotNormalized(t *testing.T, s SuiteStore) {
|
||||
ctx := context.Background()
|
||||
|
||||
want := FixedUser()
|
||||
if err := s.CreateUser(ctx, want); err != nil {
|
||||
t.Fatalf("CreateUser: %v", err)
|
||||
}
|
||||
|
||||
got, err := s.GetUserByUsername(ctx, want.Username.String)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error, got user %+v", got)
|
||||
}
|
||||
if !errors.Is(err, store.ErrUserNotFound) {
|
||||
t.Errorf("expected ErrUserNotFound, got: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Fixtures and helpers. Exported so dialect-specific tests can reuse them
|
||||
// for one-off cases that don't fit into the shared suite.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue