neon-sprawl/client/test/interaction_request_client_...

53 lines
1.6 KiB
GDScript

extends GdUnitTestSuite
## NEO-25: `InteractionRequestClient` POST bodies for E vs R contract ids.
const IxClient := preload("res://scripts/interaction_request_client.gd")
class MockHttpTransport:
extends Node
signal request_completed(
result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray
)
var last_url: String = ""
var last_body: String = ""
var last_method: HTTPClient.Method = HTTPClient.METHOD_GET
func request(
url: String,
_custom_headers: PackedStringArray = PackedStringArray(),
method: HTTPClient.Method = HTTPClient.METHOD_GET,
request_data: String = ""
) -> Error:
last_url = url
last_body = request_data
last_method = method
var body_bytes: PackedByteArray = '{"schemaVersion":1,"allowed":true}'.to_utf8_buffer()
request_completed.emit(HTTPRequest.RESULT_SUCCESS, 200, PackedStringArray(), body_bytes)
return OK
func _make_ix(transport: Node) -> Node:
var ix: Node = IxClient.new()
ix.set("injected_http", transport)
auto_free(transport)
auto_free(ix)
add_child(ix)
return ix
func test_post_terminal_body_contains_prototype_terminal() -> void:
var transport := MockHttpTransport.new()
var ix := _make_ix(transport)
ix.call("_post_interact", "prototype_terminal")
assert_that(transport.last_body).contains("prototype_terminal")
assert_that(transport.last_url).contains("/interact")
func test_post_resource_body_contains_resource_node_id() -> void:
var transport := MockHttpTransport.new()
var ix := _make_ix(transport)
ix.call("_post_interact", "prototype_resource_node_alpha")
assert_that(transport.last_body).contains("prototype_resource_node_alpha")