NEO-28: AAA layout for cast tests (C# + GdUnit)

pull/57/head
VinPropane 2026-04-27 21:46:37 -04:00
parent 7de8e7ecfd
commit 09e783a5e8
2 changed files with 27 additions and 17 deletions

View File

@ -77,10 +77,13 @@ func _make_client(transport: Node) -> Node:
func test_request_cast_posts_expected_payload_with_null_target() -> void: func test_request_cast_posts_expected_payload_with_null_target() -> void:
# Arrange
var transport := MockHttpTransport.new() var transport := MockHttpTransport.new()
transport.enqueue(HTTPRequest.RESULT_SUCCESS, 200, '{"schemaVersion":1,"accepted":true}') transport.enqueue(HTTPRequest.RESULT_SUCCESS, 200, '{"schemaVersion":1,"accepted":true}')
var c := _make_client(transport) var c := _make_client(transport)
# Act
var started: bool = bool(c.call("request_cast", 2, "prototype_guard", null)) var started: bool = bool(c.call("request_cast", 2, "prototype_guard", null))
# Assert
assert_that(started).is_true() assert_that(started).is_true()
assert_that(transport.last_url).contains("/ability-cast") assert_that(transport.last_url).contains("/ability-cast")
assert_that(transport.last_method).is_equal(HTTPClient.METHOD_POST) assert_that(transport.last_method).is_equal(HTTPClient.METHOD_POST)
@ -94,20 +97,22 @@ func test_request_cast_posts_expected_payload_with_null_target() -> void:
func test_request_cast_posts_target_id_string_when_set() -> void: func test_request_cast_posts_target_id_string_when_set() -> void:
# Arrange
var transport := MockHttpTransport.new() var transport := MockHttpTransport.new()
transport.enqueue(HTTPRequest.RESULT_SUCCESS, 200, '{"schemaVersion":1,"accepted":true}') transport.enqueue(HTTPRequest.RESULT_SUCCESS, 200, '{"schemaVersion":1,"accepted":true}')
var c := _make_client(transport) var c := _make_client(transport)
( # Act
assert_that(bool(c.call("request_cast", 0, "prototype_pulse", "prototype_target_alpha"))) var started: bool = bool(c.call("request_cast", 0, "prototype_pulse", "prototype_target_alpha"))
. is_true() # Assert
) assert_that(started).is_true()
var parsed: Variant = JSON.parse_string(transport.last_body) var parsed: Variant = JSON.parse_string(transport.last_body)
var body: Dictionary = parsed var body: Dictionary = parsed
assert_that(body.get("targetId")).is_equal("prototype_target_alpha") assert_that(body.get("targetId")).is_equal("prototype_target_alpha")
func test_request_cast_returns_false_when_http_request_fails_to_start() -> void: func test_request_cast_returns_false_when_http_request_fails_to_start() -> void:
# Arrange: empty queue → transport.request returns ERR_UNAVAILABLE (same as failed start). # Arrange
# Empty queue → transport.request returns ERR_UNAVAILABLE (same as failed start).
var transport := MockHttpTransport.new() var transport := MockHttpTransport.new()
var c := _make_client(transport) var c := _make_client(transport)
# Act # Act
@ -117,12 +122,15 @@ func test_request_cast_returns_false_when_http_request_fails_to_start() -> void:
func test_request_cast_while_busy_is_ignored() -> void: func test_request_cast_while_busy_is_ignored() -> void:
# Arrange
var transport := HoldFirstThenAutoTransport.new() var transport := HoldFirstThenAutoTransport.new()
var c := _make_client(transport) var c := _make_client(transport)
# Act
assert_that(bool(c.call("request_cast", 0, "prototype_pulse", null))).is_true() assert_that(bool(c.call("request_cast", 0, "prototype_pulse", null))).is_true()
assert_that(bool(c.call("request_cast", 1, "prototype_guard", null))).is_false() assert_that(bool(c.call("request_cast", 1, "prototype_guard", null))).is_false()
await get_tree().process_frame await get_tree().process_frame
await get_tree().process_frame await get_tree().process_frame
# Assert
assert_that(transport.request_count).is_equal(1) assert_that(transport.request_count).is_equal(1)
var parsed: Variant = JSON.parse_string(transport.last_body) var parsed: Variant = JSON.parse_string(transport.last_body)
var body: Dictionary = parsed var body: Dictionary = parsed
@ -130,6 +138,7 @@ func test_request_cast_while_busy_is_ignored() -> void:
func test_cast_result_received_emits_false_with_reason_on_denied() -> void: func test_cast_result_received_emits_false_with_reason_on_denied() -> void:
# Arrange
var transport := MockHttpTransport.new() var transport := MockHttpTransport.new()
transport.enqueue( transport.enqueue(
HTTPRequest.RESULT_SUCCESS, HTTPRequest.RESULT_SUCCESS,
@ -148,6 +157,7 @@ func test_cast_result_received_emits_false_with_reason_on_denied() -> void:
func test_cast_result_received_emits_true_with_empty_reason_on_accepted() -> void: func test_cast_result_received_emits_true_with_empty_reason_on_accepted() -> void:
# Arrange
var transport := MockHttpTransport.new() var transport := MockHttpTransport.new()
transport.enqueue(HTTPRequest.RESULT_SUCCESS, 200, '{"schemaVersion":1,"accepted":true}') transport.enqueue(HTTPRequest.RESULT_SUCCESS, 200, '{"schemaVersion":1,"accepted":true}')
var c := _make_client(transport) var c := _make_client(transport)

View File

@ -68,9 +68,9 @@ public sealed class AbilityCastApiTests
AbilityId = PrototypeAbilityRegistry.PrototypePulse, AbilityId = PrototypeAbilityRegistry.PrototypePulse,
TargetId = PrototypeTargetRegistry.PrototypeTargetAlphaId, TargetId = PrototypeTargetRegistry.PrototypeTargetAlphaId,
}); });
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
// Assert // Assert
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(body); Assert.NotNull(body);
Assert.True(body!.Accepted); Assert.True(body!.Accepted);
@ -96,9 +96,9 @@ public sealed class AbilityCastApiTests
AbilityId = PrototypeAbilityRegistry.PrototypePulse, AbilityId = PrototypeAbilityRegistry.PrototypePulse,
TargetId = "prototype_target_alpha", TargetId = "prototype_target_alpha",
}); });
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
// Assert // Assert
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(body); Assert.NotNull(body);
Assert.True(body!.Accepted); Assert.True(body!.Accepted);
@ -123,9 +123,9 @@ public sealed class AbilityCastApiTests
AbilityId = PrototypeAbilityRegistry.PrototypePulse, AbilityId = PrototypeAbilityRegistry.PrototypePulse,
TargetId = null, TargetId = null,
}); });
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
// Assert // Assert
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(body); Assert.NotNull(body);
Assert.False(body!.Accepted); Assert.False(body!.Accepted);
@ -151,9 +151,9 @@ public sealed class AbilityCastApiTests
AbilityId = PrototypeAbilityRegistry.PrototypePulse, AbilityId = PrototypeAbilityRegistry.PrototypePulse,
TargetId = "not_a_registered_combat_target", TargetId = "not_a_registered_combat_target",
}); });
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
// Assert // Assert
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(body); Assert.NotNull(body);
Assert.False(body!.Accepted); Assert.False(body!.Accepted);
@ -169,7 +169,7 @@ public sealed class AbilityCastApiTests
await BindSlot0PulseAsync(client); await BindSlot0PulseAsync(client);
await LockPrototypeTargetAlphaAsync(client); await LockPrototypeTargetAlphaAsync(client);
// Act — server lock is alpha; client sends beta id // Act
var response = await client.PostAsJsonAsync( var response = await client.PostAsJsonAsync(
"/game/players/dev-local-1/ability-cast", "/game/players/dev-local-1/ability-cast",
new AbilityCastRequest new AbilityCastRequest
@ -179,9 +179,9 @@ public sealed class AbilityCastApiTests
AbilityId = PrototypeAbilityRegistry.PrototypePulse, AbilityId = PrototypeAbilityRegistry.PrototypePulse,
TargetId = PrototypeTargetRegistry.PrototypeTargetBetaId, TargetId = PrototypeTargetRegistry.PrototypeTargetBetaId,
}); });
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
// Assert // Assert
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(body); Assert.NotNull(body);
Assert.False(body!.Accepted); Assert.False(body!.Accepted);
@ -206,9 +206,9 @@ public sealed class AbilityCastApiTests
AbilityId = PrototypeAbilityRegistry.PrototypePulse, AbilityId = PrototypeAbilityRegistry.PrototypePulse,
TargetId = PrototypeTargetRegistry.PrototypeTargetAlphaId, TargetId = PrototypeTargetRegistry.PrototypeTargetAlphaId,
}); });
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
// Assert // Assert
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(body); Assert.NotNull(body);
Assert.False(body!.Accepted); Assert.False(body!.Accepted);
@ -235,9 +235,9 @@ public sealed class AbilityCastApiTests
AbilityId = PrototypeAbilityRegistry.PrototypePulse, AbilityId = PrototypeAbilityRegistry.PrototypePulse,
TargetId = PrototypeTargetRegistry.PrototypeTargetAlphaId, TargetId = PrototypeTargetRegistry.PrototypeTargetAlphaId,
}); });
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
// Assert // Assert
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(body); Assert.NotNull(body);
Assert.False(body!.Accepted); Assert.False(body!.Accepted);
@ -261,9 +261,9 @@ public sealed class AbilityCastApiTests
AbilityId = PrototypeAbilityRegistry.PrototypeGuard, AbilityId = PrototypeAbilityRegistry.PrototypeGuard,
TargetId = null, TargetId = null,
}); });
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
// Assert // Assert
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(body); Assert.NotNull(body);
Assert.False(body!.Accepted); Assert.False(body!.Accepted);
@ -288,9 +288,9 @@ public sealed class AbilityCastApiTests
AbilityId = PrototypeAbilityRegistry.PrototypeBurst, AbilityId = PrototypeAbilityRegistry.PrototypeBurst,
TargetId = null, TargetId = null,
}); });
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
// Assert // Assert
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(body); Assert.NotNull(body);
Assert.False(body!.Accepted); Assert.False(body!.Accepted);
@ -315,9 +315,9 @@ public sealed class AbilityCastApiTests
AbilityId = PrototypeAbilityRegistry.PrototypePulse, AbilityId = PrototypeAbilityRegistry.PrototypePulse,
TargetId = null, TargetId = null,
}); });
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
// Assert // Assert
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(body); Assert.NotNull(body);
Assert.False(body!.Accepted); Assert.False(body!.Accepted);
@ -342,9 +342,9 @@ public sealed class AbilityCastApiTests
AbilityId = "not_a_real_ability", AbilityId = "not_a_real_ability",
TargetId = null, TargetId = null,
}); });
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
// Assert // Assert
var body = await response.Content.ReadFromJsonAsync<AbilityCastResponse>();
Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(body); Assert.NotNull(body);
Assert.False(body!.Accepted); Assert.False(body!.Accepted);