修复气站用户配送点归属展示
This commit is contained in:
32
backend/api/internal/logic/gas/user_test.go
Normal file
32
backend/api/internal/logic/gas/user_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package gas
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// TestScopedUserListIncludesDeliveryRelation 验证用户列表带出当前气站服务关系的配送点主键。
|
||||
func TestScopedUserListIncludesDeliveryRelation(t *testing.T) {
|
||||
connection, _, err := sqlmock.New()
|
||||
if err != nil {
|
||||
t.Fatalf("create SQL mock: %v", err)
|
||||
}
|
||||
t.Cleanup(func() { _ = connection.Close() })
|
||||
databaseService, err := gorm.Open(postgres.New(postgres.Config{Conn: connection}), &gorm.Config{DryRun: true})
|
||||
if err != nil {
|
||||
t.Fatalf("open GORM database: %v", err)
|
||||
}
|
||||
|
||||
statement := scopedUserList(databaseService, 42).
|
||||
Find(&[]gasUserListItem{}).Statement.SQL.String()
|
||||
if !strings.Contains(statement, "user_service_relation.delivery_basic_id AS delivery_basic_id") {
|
||||
t.Fatalf("user list must select delivery relation, got: %s", statement)
|
||||
}
|
||||
if !strings.Contains(statement, "user_service_relation.gas_basic_id =") {
|
||||
t.Fatalf("user list must keep gas scope, got: %s", statement)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user