统一合同气阀候选与绑定入口
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
// 功能描述:验证气站合同与配送订单展示查询的对象权限范围。
|
||||
// 版本:v1.0.0
|
||||
// 版本:v1.1.0。
|
||||
package gas
|
||||
|
||||
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"
|
||||
@@ -35,3 +36,28 @@ func TestScopedOrderDisplayQuery(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestGasContractProductCandidates 验证气站候选按指定合同用户过滤,而非返回本站全部用户设备。
|
||||
func TestGasContractProductCandidates(t *testing.T) {
|
||||
connection, _, err := sqlmock.New()
|
||||
if err != nil {
|
||||
t.Fatalf("创建 SQL 模拟失败:%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)
|
||||
}
|
||||
statement := gasContractProductCandidateQuery(databaseService, models.GasorderContract{Entity: models.Entity{ID: 17}, UserAccountID: 23}, 42).
|
||||
Find(&[]models.ProductInfo{}).Statement.SQL.String()
|
||||
for _, fragment := range []string{
|
||||
"product_info.user_account_id =",
|
||||
"candidate_binding.gasorder_contract_id =",
|
||||
"candidate_relation.gas_basic_id =",
|
||||
"candidate_relation.user_account_id = product_info.user_account_id",
|
||||
} {
|
||||
if !strings.Contains(statement, fragment) {
|
||||
t.Fatalf("气站合同气阀候选 SQL 缺少 %q:%s", fragment, statement)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user