38 lines
948 B
Go
38 lines
948 B
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
type accountQueryRecorder struct {
|
|
query string
|
|
args []any
|
|
}
|
|
|
|
func (r *accountQueryRecorder) GetContext(_ context.Context, dest any, query string, args ...any) error {
|
|
r.query = query
|
|
r.args = args
|
|
account := dest.(*Account)
|
|
*account = Account{MemberID: 9, Mobile: "13311111111", MemberStatus: memberStatusActive}
|
|
return nil
|
|
}
|
|
|
|
func TestAccountByMobileDoesNotFilterTenant(t *testing.T) {
|
|
recorder := &accountQueryRecorder{}
|
|
account, err := accountByMobile(context.Background(), recorder, "13311111111")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if account.MemberID != 9 {
|
|
t.Fatalf("MemberID = %d, want 9", account.MemberID)
|
|
}
|
|
if strings.Contains(strings.ToLower(recorder.query), "tenant_id=?") {
|
|
t.Fatalf("query must not filter tenant: %s", recorder.query)
|
|
}
|
|
if len(recorder.args) != 1 || recorder.args[0] != "13311111111" {
|
|
t.Fatalf("query args = %#v", recorder.args)
|
|
}
|
|
}
|