41 lines
1.4 KiB
GDScript
41 lines
1.4 KiB
GDScript
extends GdUnitTestSuite
|
|
|
|
## NEO-25: parse `GET /game/world/interactables` JSON into descriptor rows.
|
|
|
|
const _CATALOG_SCRIPT := preload("res://scripts/interactables_catalog_client.gd")
|
|
|
|
|
|
func test_parse_catalog_json_orders_and_fields() -> void:
|
|
# Arrange
|
|
var json := (
|
|
'{"schemaVersion":1,"interactables":['
|
|
+ '{"interactableId":"prototype_resource_node_alpha","kind":"resource_node",'
|
|
+ '"anchor":{"x":12,"y":0.5,"z":-6},"interactionRadius":3},'
|
|
+ '{"interactableId":"prototype_terminal","kind":"terminal",'
|
|
+ '"anchor":{"x":0,"y":0.5,"z":0},"interactionRadius":3}'
|
|
+ "]}"
|
|
)
|
|
# Act
|
|
var rows: Variant = _CATALOG_SCRIPT.parse_catalog_json(json)
|
|
# Assert
|
|
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(12.0)
|
|
assert_that(r1.get("interactableId", "")).is_equal("prototype_terminal")
|
|
|
|
|
|
func test_parse_catalog_json_returns_empty_on_garbage() -> void:
|
|
# Arrange
|
|
var garbage := "[]"
|
|
# Act
|
|
var rows2: Variant = _CATALOG_SCRIPT.parse_catalog_json(garbage)
|
|
# Assert
|
|
assert_that((rows2 as Array).is_empty()).is_true()
|