straywild/tests/friend_relationship_validation.gd

77 lines
2.3 KiB
GDScript3
Raw Normal View History

extends SceneTree
const FRIEND_FINGERPRINT := (
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
)
func _initialize() -> void:
call_deferred("_run")
func _run() -> void:
var data_root := PlayerDataRoot.new()
root.add_child(data_root)
var portable_path := ProjectSettings.globalize_path(
"user://friend-relationship-validation"
)
var created := data_root.create_unbound_root(portable_path)
assert(bool(created.get("ok", false)))
assert(data_root.activate_process_root(portable_path))
var store := PlayerRelationshipStore.new()
root.add_child(store)
store.configure_storage(
data_root.path_for(&"player_relationships"), data_root
)
var local_capabilities := store.create_friend_capabilities()
var remote_capabilities := store.create_friend_capabilities()
assert(not local_capabilities.is_empty())
assert(not remote_capabilities.is_empty())
assert(store.add_friend(
FRIEND_FINGERPRINT,
"Pond Friend",
local_capabilities,
{
"presence_channel": remote_capabilities["presence_channel"],
"invite_token": remote_capabilities["invite_token"],
},
))
assert(store.is_friend(FRIEND_FINGERPRINT))
var reloaded := PlayerRelationshipStore.new()
root.add_child(reloaded)
reloaded.configure_storage(
data_root.path_for(&"player_relationships"), data_root
)
assert(reloaded.is_friend(FRIEND_FINGERPRINT))
var friend := reloaded.get_friend_record(FRIEND_FINGERPRINT)
assert(
str(friend["remote_presence_channel"])
== str(remote_capabilities["presence_channel"])
)
assert(
str(friend["remote_invite_token"])
== str(remote_capabilities["invite_token"])
)
assert(reloaded.set_blocked(FRIEND_FINGERPRINT, "Pond Friend", true))
assert(reloaded.is_blocked(FRIEND_FINGERPRINT))
assert(reloaded.is_muted(FRIEND_FINGERPRINT))
assert(not reloaded.is_friend(FRIEND_FINGERPRINT))
assert(reloaded.set_blocked(FRIEND_FINGERPRINT, "Pond Friend", false))
assert(not reloaded.is_blocked(FRIEND_FINGERPRINT))
assert(not reloaded.is_muted(FRIEND_FINGERPRINT))
assert(not reloaded.is_friend(FRIEND_FINGERPRINT))
var hello := NetworkProtocol.make_client_hello(
"profile",
"Pond Friend",
"nonce",
)
assert(
NetworkProtocol.FRIENDS_CAPABILITY
in PackedStringArray(hello.get("capability_flags", []))
)
print("Friend relationship validation: PASS")
quit()