139 lines
6.4 KiB
GDScript
139 lines
6.4 KiB
GDScript
extends SceneTree
|
|
|
|
const Controller = preload("res://entry/reward_choice_page_controller.gd")
|
|
|
|
var failures: Array[String] = []
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("run_test")
|
|
|
|
|
|
func run_test() -> void:
|
|
var controller := Controller.new()
|
|
var company := _fixture_company()
|
|
var battle := _fixture_battle()
|
|
var draft: Dictionary = battle.reward_draft
|
|
|
|
var empty_selection: Dictionary = controller.snapshot(company, battle, draft, "", "", "en")
|
|
expect(empty_selection.ok and empty_selection.page_id == "reward_choice", "snapshot identifies Reward Choice")
|
|
expect(empty_selection.company.owned_count == 4 and empty_selection.contract.coin == 51, "snapshot copies Company and Contract facts")
|
|
expect(empty_selection.battle.status == "result" and empty_selection.battle.operation_id == "battle-op-001", "snapshot copies settled Battle identity")
|
|
expect(empty_selection.paid.coin_before == 24 and empty_selection.paid.coin_after == 51 and empty_selection.paid.battle_reward_coin == 27, "snapshot copies paid battle Coin facts")
|
|
expect(empty_selection.reward.status == "open" and empty_selection.reward.options_count == 2 and not empty_selection.reward.selected, "snapshot copies open draft and empty selection")
|
|
expect(empty_selection.commands.select_enabled and not empty_selection.commands.claim_enabled and empty_selection.commands.skip_enabled, "empty selection exposes truthful commands")
|
|
expect(empty_selection.continuation.after_claim == "battle_recovery" and empty_selection.receipt.duplicate_safe, "snapshot exposes Recovery continuation and receipt identity")
|
|
|
|
var selected: Dictionary = controller.snapshot(company, battle, draft, "reward-1", "selected", "zh_CN")
|
|
expect(selected.ok and selected.reward.selected and selected.reward.selected_reward_id == "reward-1", "selected option is normalized")
|
|
expect(selected.reward.selected_option.catalog_id == "EQ-001" and selected.commands.claim_enabled, "selected option and Claim eligibility are copied")
|
|
expect(selected.notice == "selected", "notice is copied")
|
|
|
|
selected.reward.selected_option.catalog_id = "changed"
|
|
selected.reward.draft.options[0].catalog_id = "changed"
|
|
selected.result.outcome = "changed"
|
|
expect(String(draft.options[0].catalog_id) == "EQ-001", "reward option is deeply copied")
|
|
expect(String(battle.result.outcome) == "victory", "result facts are deeply copied")
|
|
|
|
var missing: Dictionary = controller.snapshot({}, battle, draft)
|
|
expect(not missing.ok and missing.code == "COMPANY_REQUIRED", "missing Company is rejected")
|
|
var active := battle.duplicate(true)
|
|
active.status = "active"
|
|
var unsettled: Dictionary = controller.snapshot(company, active, active.reward_draft)
|
|
expect(not unsettled.ok and unsettled.code == "REWARD_CHOICE_BATTLE_NOT_SETTLED", "unsettled Battle is rejected")
|
|
var closed_draft := draft.duplicate(true)
|
|
closed_draft.status = "claimed"
|
|
var closed: Dictionary = controller.snapshot(company, battle, closed_draft)
|
|
expect(not closed.ok and closed.code == "REWARD_CHOICE_DRAFT_NOT_OPEN", "closed draft is rejected")
|
|
var unknown: Dictionary = controller.snapshot(company, battle, draft, "missing")
|
|
expect(not unknown.ok and unknown.code == "REWARD_CHOICE_SELECTION_INVALID", "unknown reward selection is rejected")
|
|
var duplicate := draft.duplicate(true)
|
|
duplicate.options.append({"reward_id": "reward-1", "kind": "coin"})
|
|
var duplicate_result: Dictionary = controller.snapshot(company, battle, duplicate)
|
|
expect(not duplicate_result.ok and duplicate_result.code == "REWARD_CHOICE_REWARD_ID_DUPLICATE", "duplicate reward ID is rejected")
|
|
var short := draft.duplicate(true)
|
|
short.options = [short.options[0]]
|
|
var short_result: Dictionary = controller.snapshot(company, battle, short)
|
|
expect(not short_result.ok and short_result.code == "REWARD_CHOICE_OPTIONS_REQUIRED", "single-option draft is rejected")
|
|
var missing_receipt_company := company.duplicate(true)
|
|
missing_receipt_company.active_contract.battle_settlement_receipts = []
|
|
var missing_receipt_battle := battle.duplicate(true)
|
|
missing_receipt_battle.erase("settlement_receipt")
|
|
var missing_receipt: Dictionary = controller.snapshot(missing_receipt_company, missing_receipt_battle, missing_receipt_battle.reward_draft)
|
|
expect(not missing_receipt.ok and missing_receipt.code == "REWARD_CHOICE_SETTLEMENT_RECEIPT_REQUIRED", "missing settlement receipt is rejected")
|
|
|
|
if failures.is_empty():
|
|
print("ABG_M29_REWARD_CHOICE_CONTROLLER_OK company=4 settled=result draft=open options=2 selected=none,reward-1 paid_coin=24,51,+27 claim=false,true skip=true recovery=true receipt=duplicate_safe copies=true")
|
|
quit(0)
|
|
else:
|
|
for failure in failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
|
|
|
|
func _fixture_company() -> Dictionary:
|
|
return {
|
|
"company_id": "company-001",
|
|
"owned_recruits": [
|
|
{"recruit_id": "r-1", "rendered_name_snapshot": {"display_name": "Ari"}},
|
|
{"recruit_id": "r-2", "rendered_name_snapshot": {"display_name": "Bram"}},
|
|
{"recruit_id": "r-3", "rendered_name_snapshot": {"display_name": "Cera"}},
|
|
{"recruit_id": "r-4", "rendered_name_snapshot": {"display_name": "Dain"}},
|
|
],
|
|
"active_contract": {
|
|
"contract_id": "CTR-R1-01",
|
|
"run_id": "run-001",
|
|
"status": "result",
|
|
"coin": 51,
|
|
"line_capacity": 4,
|
|
"contract_hash": "contract-hash-001",
|
|
"battle_settlement_receipts": [_fixture_receipt()],
|
|
},
|
|
}
|
|
|
|
|
|
func _fixture_battle() -> Dictionary:
|
|
return {
|
|
"status": "result",
|
|
"operation_id": "battle-op-001",
|
|
"battle_hash": "battle-hash-001",
|
|
"snapshot_id": "snapshot-001",
|
|
"snapshot_hash": "snapshot-hash-001",
|
|
"front_to_rear_ids": ["r-1", "r-2", "r-3", "r-4"],
|
|
"enemy_ids": ["enemy-1", "enemy-2", "enemy-3"],
|
|
"phase_events": [],
|
|
"result": {
|
|
"outcome": "victory",
|
|
"reward_coin": 27,
|
|
"xp_award": 48,
|
|
"coin_before": 24,
|
|
"coin_after": 51,
|
|
"reward_draft_id": "draft-001",
|
|
},
|
|
"reward_draft": {
|
|
"draft_id": "draft-001",
|
|
"operation_id": "battle-op-001",
|
|
"draft_hash": "draft-hash-001",
|
|
"status": "open",
|
|
"options": [
|
|
{"reward_id": "reward-1", "kind": "equipment", "catalog_id": "EQ-001"},
|
|
{"reward_id": "reward-2", "kind": "coin", "amount": 8},
|
|
],
|
|
},
|
|
"settlement_receipt": _fixture_receipt(),
|
|
}
|
|
|
|
|
|
func _fixture_receipt() -> Dictionary:
|
|
return {
|
|
"operation_id": "battle-op-001",
|
|
"battle_operation_id": "battle-op-001",
|
|
"receipt_hash": "settlement-hash-001",
|
|
"outcome_hash": "outcome-hash-001",
|
|
}
|
|
|
|
|
|
func expect(condition: bool, message: String) -> void:
|
|
if not condition:
|
|
failures.append("M29 Reward Choice Controller: %s" % message)
|