neon-sprawl/client/test/interactables_catalog_clien...

32 lines
1.3 KiB
GDScript

extends GdUnitTestSuite
## NEO-25: parse `GET /game/world/interactables` JSON into descriptor rows.
func test_parse_catalog_json_orders_and_fields() -> void:
var json := (
'{"schemaVersion":1,"interactables":['
+ '{"interactableId":"prototype_resource_node_alpha","kind":"resource_node",'
+ '"anchor":{"x":5,"y":0.5,"z":5},"interactionRadius":3},'
+ '{"interactableId":"prototype_terminal","kind":"terminal",'
+ '"anchor":{"x":0,"y":0.5,"z":0},"interactionRadius":3}'
+ "]}"
)
var rows: Variant = load("res://scripts/interactables_catalog_client.gd").call("parse_catalog_json", json)
assert_that(rows is Array).is_true()
var arr: Array = rows
assert_that(arr.size()).is_equal(2)
var r0: Dictionary = arr[0]
var r1: Dictionary = arr[1]
assert_that(r0.get("interactableId", "")).is_equal("prototype_resource_node_alpha")
assert_that(r0.get("kind", "")).is_equal("resource_node")
var a0: Variant = r0.get("anchor", null)
assert_that(a0 is Dictionary).is_true()
assert_that(float((a0 as Dictionary).get("x", -1.0))).is_equal(5.0)
assert_that(r1.get("interactableId", "")).is_equal("prototype_terminal")
func test_parse_catalog_json_returns_empty_on_garbage() -> void:
var rows2: Variant = load("res://scripts/interactables_catalog_client.gd").call("parse_catalog_json", "[]")
assert_that((rows2 as Array).is_empty()).is_true()