Files
platforms/backend/api/internal/logic/delivery/staff_test.go
2026-08-22 22:23:35 +08:00

34 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 功能描述验证配送点人员查询始终限制为当前配送点的配送角色。版本v1.0.0。
package delivery
import (
"strings"
"testing"
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
"github.com/DATA-DOG/go-sqlmock"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
// TestDeliveryStaffQueryKeepsRoleScope 验证列表、详情和头像共用的范围包含 delivery 角色。
func TestDeliveryStaffQueryKeepsRoleScope(t *testing.T) {
connection, _, err := sqlmock.New()
if err != nil {
t.Fatalf("创建 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("打开 GORM 失败:%v", err)
}
point := models.DeliveryBasic{Entity: models.Entity{ID: 22}, GasBasicID: 11}
statement := deliveryStaffQuery(databaseService, point).
Where("identity = ?", "staff-identity").Find(&models.StaffAccount{}).Statement.SQL.String()
for _, required := range []string{"gas_basic_id", "delivery_basic_id", "role_code"} {
if !strings.Contains(statement, required) {
t.Fatalf("配送人员范围缺少 %s%s", required, statement)
}
}
}