NEO-74: Fix craft busy flag ordering; drop unused recipe helpers.
Set _busy before HTTP request so sync mock completion cannot leave the client stuck busy; remove uncalled recipes_snapshot/recipe_by_id; add GdUnit guard for is_busy after sync response.pull/108/head
parent
f939132f38
commit
d6d95ec438
|
|
@ -40,6 +40,7 @@ func request_craft(recipe_id: String, quantity: int = 1) -> bool:
|
||||||
if rid.is_empty():
|
if rid.is_empty():
|
||||||
return false
|
return false
|
||||||
_current_recipe_id = rid
|
_current_recipe_id = rid
|
||||||
|
_busy = true
|
||||||
var payload: Dictionary = {
|
var payload: Dictionary = {
|
||||||
"schemaVersion": SCHEMA_VERSION,
|
"schemaVersion": SCHEMA_VERSION,
|
||||||
"recipeId": rid,
|
"recipeId": rid,
|
||||||
|
|
@ -49,10 +50,10 @@ func request_craft(recipe_id: String, quantity: int = 1) -> bool:
|
||||||
var headers := PackedStringArray(["Content-Type: application/json"])
|
var headers := PackedStringArray(["Content-Type: application/json"])
|
||||||
var err: Error = _http.request(url, headers, HTTPClient.METHOD_POST, JSON.stringify(payload))
|
var err: Error = _http.request(url, headers, HTTPClient.METHOD_POST, JSON.stringify(payload))
|
||||||
if err != OK:
|
if err != OK:
|
||||||
|
_busy = false
|
||||||
_current_recipe_id = ""
|
_current_recipe_id = ""
|
||||||
push_warning("CraftClient: POST failed to start (%s)" % err)
|
push_warning("CraftClient: POST failed to start (%s)" % err)
|
||||||
return false
|
return false
|
||||||
_busy = true
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,20 +41,6 @@ func request_sync_from_server() -> void:
|
||||||
recipes_sync_failed.emit(reason)
|
recipes_sync_failed.emit(reason)
|
||||||
|
|
||||||
|
|
||||||
func recipes_snapshot() -> Array:
|
|
||||||
return _recipes.duplicate(true)
|
|
||||||
|
|
||||||
|
|
||||||
func recipe_by_id(recipe_id: String) -> Dictionary:
|
|
||||||
for row_variant in _recipes:
|
|
||||||
if not row_variant is Dictionary:
|
|
||||||
continue
|
|
||||||
var row: Dictionary = row_variant
|
|
||||||
if str(row.get("id", "")) == recipe_id:
|
|
||||||
return row.duplicate(true)
|
|
||||||
return {}
|
|
||||||
|
|
||||||
|
|
||||||
func _base_root() -> String:
|
func _base_root() -> String:
|
||||||
return base_url.strip_edges().rstrip("/")
|
return base_url.strip_edges().rstrip("/")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -130,3 +130,15 @@ func test_http_error_emits_craft_request_failed() -> void:
|
||||||
c.call("request_craft", "refine_scrap_standard")
|
c.call("request_craft", "refine_scrap_standard")
|
||||||
# Assert
|
# Assert
|
||||||
assert_that(_failed_reason).contains("404")
|
assert_that(_failed_reason).contains("404")
|
||||||
|
|
||||||
|
|
||||||
|
func test_request_craft_clears_busy_after_sync_mock_response() -> void:
|
||||||
|
# Arrange
|
||||||
|
var transport := MockHttpTransport.new()
|
||||||
|
transport.body_json = _success_craft_json()
|
||||||
|
var c := _make_client(transport)
|
||||||
|
# Act
|
||||||
|
var started: bool = bool(c.call("request_craft", "refine_scrap_standard", 1))
|
||||||
|
# Assert
|
||||||
|
assert_that(started).is_true()
|
||||||
|
assert_that(bool(c.call("is_busy"))).is_false()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue