Rewrite recursive update test (still fails sob)

This commit is contained in:
bitfl0wer 2023-08-16 22:04:24 +02:00
parent 29b9050e6d
commit 7c8ad3ffcf
1 changed files with 46 additions and 2 deletions

View File

@ -1,7 +1,9 @@
mod common;
use std::sync::{Arc, RwLock};
use chorus::gateway::*;
use chorus::types::{self, ChannelModifySchema};
use chorus::types::{self, ChannelModifySchema, RoleCreateModifySchema, RoleObject};
#[tokio::test]
/// Tests establishing a connection (hello and heartbeats) on the local gateway;
@ -62,6 +64,48 @@ async fn test_self_updating_structs() {
#[tokio::test]
async fn test_recursive_self_updating_structs() {
// Setup
let bundle = common::setup().await;
let mut bundle = common::setup().await;
let guild = bundle.guild.clone();
// Observe Guild, make sure it has no channels
let guild = bundle.user.gateway.observe(guild.clone()).await;
let inner_guild = guild.read().unwrap().clone();
assert!(inner_guild.roles.is_none());
// Create Role
let permissions = types::PermissionFlags::CONNECT | types::PermissionFlags::MANAGE_EVENTS;
let permissions = Some(permissions.to_string());
let mut role_create_schema: types::RoleCreateModifySchema = RoleCreateModifySchema {
name: Some("cool person".to_string()),
permissions,
hoist: Some(true),
icon: None,
unicode_emoji: Some("".to_string()),
mentionable: Some(true),
position: None,
color: None,
};
let guild_id = inner_guild.id;
let role = RoleObject::create(&mut bundle.user, guild_id, role_create_schema.clone())
.await
.unwrap();
// Watch role;
bundle
.user
.gateway
.observe(Arc::new(RwLock::new(role.clone())))
.await;
// Update Guild and check for Guild
let guild = bundle.user.gateway.observe(guild.clone()).await;
let inner_guild = guild.read().unwrap().clone();
assert!(inner_guild.roles.is_some());
// Update the Role
role_create_schema.name = Some("yippieee".to_string());
RoleObject::modify(&mut bundle.user, guild_id, role.id, role_create_schema)
.await
.unwrap();
// Check if the change propagated
let guild_roles = guild.read().unwrap().clone().roles;
let guild_role = guild_roles.unwrap();
let guild_role_inner = guild_role.get(0).unwrap().read().unwrap().clone();
assert_eq!(guild_role_inner.name, "yippieee".to_string());
common::teardown(bundle).await;
}