NEO-153: gdformat contract_client and test merge helper.
parent
b9ffd7553b
commit
8289f2076d
|
|
@ -163,7 +163,10 @@ static func merge_contract_row_into_snapshot(snapshot: Dictionary, row: Dictiona
|
|||
var replaced := false
|
||||
for i in contracts.size():
|
||||
var existing: Variant = contracts[i]
|
||||
if existing is Dictionary and str((existing as Dictionary).get("contractInstanceId", "")) == iid:
|
||||
if (
|
||||
existing is Dictionary
|
||||
and str((existing as Dictionary).get("contractInstanceId", "")) == iid
|
||||
):
|
||||
contracts[i] = row.duplicate(true)
|
||||
replaced = true
|
||||
break
|
||||
|
|
|
|||
|
|
@ -219,3 +219,25 @@ func test_issue_deny_emits_result_with_reason_code() -> void:
|
|||
await assert_signal(c).is_emitted("contract_issue_result_received", any())
|
||||
assert_bool(_issue_capture.get("issued", true)).is_false()
|
||||
assert_that(str(_issue_capture.get("reasonCode", ""))).is_equal("economy_cap_exceeded")
|
||||
|
||||
|
||||
func test_merge_contract_row_replaces_matching_instance_id() -> void:
|
||||
# Arrange
|
||||
var snapshot := {
|
||||
"schemaVersion": 1,
|
||||
"playerId": "dev-local-1",
|
||||
"contracts":
|
||||
[
|
||||
{
|
||||
"contractInstanceId": "ci_old",
|
||||
"status": "active",
|
||||
}
|
||||
],
|
||||
}
|
||||
var row := {"contractInstanceId": "ci_old", "status": "completed"}
|
||||
# Act
|
||||
var merged: Dictionary = ContractClient.merge_contract_row_into_snapshot(snapshot, row)
|
||||
# Assert
|
||||
var contracts: Array = merged.get("contracts", []) as Array
|
||||
assert_that(contracts.size()).is_equal(1)
|
||||
assert_that(str((contracts[0] as Dictionary).get("status", ""))).is_equal("completed")
|
||||
|
|
|
|||
Loading…
Reference in New Issue