feat(platform): add device safety commerce APIs
This commit is contained in:
@@ -56,6 +56,45 @@ func TestPlatformOrganizationAndAccountRoutesExposeResourceCRUD(t *testing.T) {
|
||||
assertRouteMethods(t, routes, "/heqi/platform/v1/platform/platform_role/:identity/menus", http.MethodPut)
|
||||
}
|
||||
|
||||
func TestPlatformDeviceSafetyCommerceAndDeliveryRoutesFollowTheirContracts(t *testing.T) {
|
||||
engine := gin.New()
|
||||
RegisterPlatform("heqi", engine)
|
||||
|
||||
routes := make(map[string]map[string]bool)
|
||||
for _, route := range engine.Routes() {
|
||||
if routes[route.Path] == nil {
|
||||
routes[route.Path] = make(map[string]bool)
|
||||
}
|
||||
routes[route.Path][route.Method] = true
|
||||
}
|
||||
|
||||
for _, resource := range []string{
|
||||
"/device/dev_smart_cylinder_valve", "/device/dev_device_binding",
|
||||
"/safety/saf_rule", "/safety/saf_event", "/safety/saf_inspection",
|
||||
"/ec/ec_category", "/ec/ec_product", "/ec/ec_product_attribute", "/ec/ec_product_image", "/ec/ec_cart", "/ec/ec_order", "/ec/ec_review",
|
||||
"/delivery/delivery_task", "/delivery/delivery_track", "/delivery/delivery_track_point",
|
||||
} {
|
||||
assertRouteMethods(t, routes, "/heqi/platform/v1"+resource, http.MethodGet, http.MethodPost)
|
||||
assertRouteMethods(t, routes, "/heqi/platform/v1"+resource+"/:identity", http.MethodGet, http.MethodPut, http.MethodDelete)
|
||||
assertRouteMethods(t, routes, "/heqi/platform/v1"+resource+"/: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)
|
||||
}
|
||||
}
|
||||
|
||||
disposal := "/heqi/platform/v1/safety/saf_event/:identity/disposals"
|
||||
assertRouteMethods(t, routes, disposal, http.MethodPost)
|
||||
if routes[disposal][http.MethodDelete] {
|
||||
t.Fatal("safety event disposals must be append-only")
|
||||
}
|
||||
}
|
||||
|
||||
func assertRouteMethods(t *testing.T, routes map[string]map[string]bool, path string, methods ...string) {
|
||||
t.Helper()
|
||||
for _, method := range methods {
|
||||
|
||||
Reference in New Issue
Block a user