Add recursive-updating-structs test
This commit is contained in:
parent
7147ac5daf
commit
c9d9e77f16
|
@ -1,7 +1,11 @@
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
use chorus::gateway::*;
|
use chorus::gateway::*;
|
||||||
use chorus::types::{self, ChannelModifySchema};
|
use chorus::types::{
|
||||||
|
self, ChannelModifySchema, Composite, PermissionFlags, RoleCreateModifySchema, RoleObject,
|
||||||
|
};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
/// Tests establishing a connection (hello and heartbeats) on the local gateway;
|
/// Tests establishing a connection (hello and heartbeats) on the local gateway;
|
||||||
|
@ -58,3 +62,51 @@ async fn test_self_updating_structs() {
|
||||||
|
|
||||||
common::teardown(bundle).await
|
common::teardown(bundle).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_recursive_self_updating_structs() {
|
||||||
|
let mut bundle = common::setup().await;
|
||||||
|
|
||||||
|
let guild = bundle
|
||||||
|
.user
|
||||||
|
.gateway
|
||||||
|
.observe_and_into_inner(bundle.guild.clone())
|
||||||
|
.await;
|
||||||
|
assert!(guild.roles.is_none());
|
||||||
|
let id = guild.id;
|
||||||
|
let permissions = PermissionFlags::CONNECT | PermissionFlags::MANAGE_EVENTS;
|
||||||
|
let permissions = Some(permissions.to_string());
|
||||||
|
let mut role_create_schema = RoleCreateModifySchema {
|
||||||
|
name: Some("among us".to_string()),
|
||||||
|
permissions,
|
||||||
|
hoist: Some(true),
|
||||||
|
icon: None,
|
||||||
|
unicode_emoji: Some("".to_string()),
|
||||||
|
mentionable: Some(true),
|
||||||
|
position: None,
|
||||||
|
color: None,
|
||||||
|
};
|
||||||
|
let role = RoleObject::create(&mut bundle.user, id, role_create_schema.clone())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let role_watch = bundle
|
||||||
|
.user
|
||||||
|
.gateway
|
||||||
|
.observer_channel(Arc::new(RwLock::new(role.clone())))
|
||||||
|
.await;
|
||||||
|
let guild = bundle
|
||||||
|
.user
|
||||||
|
.gateway
|
||||||
|
.observe_and_into_inner(bundle.guild.clone())
|
||||||
|
.await;
|
||||||
|
assert!(guild.roles.is_some());
|
||||||
|
role_create_schema.name = Some("enbyenvy".to_string());
|
||||||
|
RoleObject::modify(&mut bundle.user, id, role.id, role_create_schema)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let newrole = role_watch.borrow().read().unwrap().clone();
|
||||||
|
assert_eq!(newrole.name, "enbyenvy".to_string());
|
||||||
|
let guild_role = role_watch.borrow().read().unwrap().clone();
|
||||||
|
assert_eq!(guild_role.name, "enbyenvy".to_string());
|
||||||
|
common::teardown(bundle).await;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue