69 lines
2.7 KiB
GDScript
69 lines
2.7 KiB
GDScript
extends SceneTree
|
|
|
|
var failures := 0
|
|
var login: Control
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("_run")
|
|
|
|
|
|
func _run() -> void:
|
|
login = load("res://scripts/ui/login_screen.gd").new()
|
|
root.add_child(login)
|
|
await process_frame
|
|
_test_elapsed_timeout_clears_flow()
|
|
_test_transient_failure_keeps_transaction()
|
|
_test_leaving_completion_cancels_flow()
|
|
_test_external_account_password_confirmation()
|
|
login.queue_free()
|
|
await process_frame
|
|
quit(1 if failures > 0 else 0)
|
|
|
|
|
|
func _test_elapsed_timeout_clears_flow() -> void:
|
|
login.steam_transaction_id = "expired-transaction"
|
|
login.steam_poll_deadline_msec = 1
|
|
login.poll_timer.start()
|
|
login._poll_steam()
|
|
_assert(login.steam_transaction_id.is_empty(), "elapsed Steam login deadline should clear the transaction")
|
|
_assert(login.poll_timer.is_stopped(), "elapsed Steam login deadline should stop polling")
|
|
|
|
|
|
func _test_transient_failure_keeps_transaction() -> void:
|
|
login.steam_transaction_id = "retry-transaction"
|
|
login.steam_poll_deadline_msec = Time.get_ticks_msec() + 300000
|
|
login.steam_poll_failures = 2
|
|
login._on_steam_status(HTTPRequest.RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray())
|
|
_assert(login.steam_transaction_id == "retry-transaction", "temporary connection failures should preserve the Steam transaction")
|
|
_assert(login.steam_poll_failures == 3, "temporary connection failures should be tracked without consuming the deadline")
|
|
|
|
|
|
func _test_leaving_completion_cancels_flow() -> void:
|
|
login.mode = "steam"
|
|
login.steam_transaction_id = "cancel-transaction"
|
|
login.poll_timer.start()
|
|
login._set_mode("login")
|
|
_assert(login.steam_transaction_id.is_empty(), "leaving Steam account completion should clear its transaction")
|
|
_assert(login.poll_timer.is_stopped(), "leaving Steam account completion should stop polling")
|
|
|
|
|
|
func _test_external_account_password_confirmation() -> void:
|
|
login._on_steam_action_changed(0)
|
|
_assert(login.steam_confirm_input.visible, "new external accounts should show password confirmation")
|
|
_assert(login.steam_confirm_input.secret, "external password confirmation should be masked")
|
|
_assert(
|
|
login._validate_account("new_user", "[email protected]", "password-one", "password-two") == "Passwords do not match.",
|
|
"external account creation should reject mismatched passwords")
|
|
login.steam_confirm_input.text = "password-one"
|
|
login._on_steam_action_changed(1)
|
|
_assert(not login.steam_confirm_input.visible, "existing-account linking should hide password confirmation")
|
|
_assert(login.steam_confirm_input.text.is_empty(), "hidden confirmation text should be cleared")
|
|
|
|
|
|
func _assert(condition: bool, message: String) -> void:
|
|
if condition:
|
|
return
|
|
failures += 1
|
|
push_error(message)
|