refactor product domain models

This commit is contained in:
david
2026-07-28 08:44:54 +08:00
parent 7000e90d88
commit 8d71a1fc08
15 changed files with 634 additions and 85 deletions

View File

@@ -29,6 +29,12 @@ func TestEveryContractHasRegisteredRoute(t *testing.T) {
case platform.AppendOnly:
assertRouteMethods(t, routes, path, http.MethodGet, http.MethodPost)
assertNoRouteMethods(t, routes, path, http.MethodPut, http.MethodPatch, http.MethodDelete)
case platform.Editable:
assertRouteMethods(t, routes, path, http.MethodGet, http.MethodPost)
assertRouteMethods(t, routes, path+"/:identity", http.MethodGet, http.MethodPut)
assertRouteMethods(t, routes, path+"/:identity/status", http.MethodPatch)
assertNoRouteMethods(t, routes, path, http.MethodDelete)
assertNoRouteMethods(t, routes, path+"/:identity", http.MethodDelete)
default:
assertRouteMethods(t, routes, path, http.MethodGet, http.MethodPost)
assertRouteMethods(t, routes, path+"/:identity", http.MethodGet, http.MethodPut, http.MethodDelete)
@@ -87,7 +93,7 @@ func TestPlatformOrganizationAndAccountRoutesExposeResourceCRUD(t *testing.T) {
assertRouteMethods(t, routes, "/heqi/platform/v1/platform/platform_role/:identity/menus", http.MethodPut)
}
func TestPlatformDeviceCommerceAndDeliveryRoutesFollowTheirContracts(t *testing.T) {
func TestPlatformProductCommerceAndDeliveryRoutesFollowTheirContracts(t *testing.T) {
engine := gin.New()
RegisterPlatform("heqi", engine)
@@ -100,7 +106,6 @@ func TestPlatformDeviceCommerceAndDeliveryRoutesFollowTheirContracts(t *testing.
}
for _, resource := range []string{
"/device/dev_smart_cylinder_valve", "/device/dev_device_binding",
"/ec/ec_category", "/ec/ec_product", "/ec/ec_product_attribute", "/ec/ec_product_image", "/ec/ec_cart", "/ec/ec_order", "/ec/ec_order_item", "/ec/ec_review",
"/delivery/delivery_task", "/delivery/delivery_track",
} {
@@ -116,14 +121,17 @@ func TestPlatformDeviceCommerceAndDeliveryRoutesFollowTheirContracts(t *testing.
assertNoRouteMethods(t, routes, trackPoint+"/:identity", http.MethodPut, http.MethodDelete)
assertNoRouteMethods(t, routes, trackPoint+"/:identity/status", http.MethodPatch)
telemetry := "/heqi/platform/v1/device/dev_telemetry"
assertRouteMethods(t, routes, telemetry, http.MethodGet)
assertRouteMethods(t, routes, telemetry+"/:identity", http.MethodGet)
for _, method := range []string{http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete} {
if routes[telemetry][method] || routes[telemetry+"/:identity"][method] {
t.Errorf("telemetry unexpectedly permits %s", method)
}
for _, resource := range []string{"/product_type", "/product_warehouse", "/product_info", "/product_repair"} {
path := "/heqi/platform/v1" + resource
assertRouteMethods(t, routes, path, http.MethodGet, http.MethodPost)
assertRouteMethods(t, routes, path+"/:identity", http.MethodGet, http.MethodPut)
assertRouteMethods(t, routes, path+"/:identity/status", http.MethodPatch)
assertNoRouteMethods(t, routes, path+"/:identity", http.MethodDelete)
}
owner := "/heqi/platform/v1/product_owner"
assertRouteMethods(t, routes, owner, http.MethodGet, http.MethodPost)
assertRouteMethods(t, routes, owner+"/:identity", http.MethodGet)
assertNoRouteMethods(t, routes, owner+"/:identity", http.MethodPut, http.MethodPatch, http.MethodDelete)
for _, resource := range []string{
"/safety/safe_rule", "/safety/safe_event", "/safety/safe_inspection",