Change tests to deal with `Arc<RwLock<T>>`'s
This commit is contained in:
parent
041ee223c3
commit
33d5675cc4
|
@ -8,11 +8,11 @@ mod common;
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn get_channel() {
|
async fn get_channel() {
|
||||||
let mut bundle = common::setup().await;
|
let mut bundle = common::setup().await;
|
||||||
let bundle_channel = bundle.channel.read().unwrap();
|
let bundle_channel = bundle.channel.read().unwrap().clone();
|
||||||
let bundle_user = &mut bundle.user;
|
let bundle_user = &mut bundle.user;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
*bundle_channel,
|
bundle_channel,
|
||||||
Channel::get(bundle_user, bundle_channel.id).await.unwrap()
|
Channel::get(bundle_user, bundle_channel.id).await.unwrap()
|
||||||
);
|
);
|
||||||
common::teardown(bundle).await
|
common::teardown(bundle).await
|
||||||
|
@ -21,7 +21,8 @@ async fn get_channel() {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn delete_channel() {
|
async fn delete_channel() {
|
||||||
let mut bundle = common::setup().await;
|
let mut bundle = common::setup().await;
|
||||||
let result = Channel::delete(*bundle.channel.write().unwrap(), &mut bundle.user).await;
|
let channel_guard = bundle.channel.write().unwrap().clone();
|
||||||
|
let result = Channel::delete(channel_guard, &mut bundle.user).await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
common::teardown(bundle).await
|
common::teardown(bundle).await
|
||||||
}
|
}
|
||||||
|
@ -30,7 +31,7 @@ async fn delete_channel() {
|
||||||
async fn modify_channel() {
|
async fn modify_channel() {
|
||||||
const CHANNEL_NAME: &str = "beepboop";
|
const CHANNEL_NAME: &str = "beepboop";
|
||||||
let mut bundle = common::setup().await;
|
let mut bundle = common::setup().await;
|
||||||
let channel = &mut bundle.channel;
|
let channel = &mut bundle.channel.read().unwrap().clone();
|
||||||
let modify_data: types::ChannelModifySchema = types::ChannelModifySchema {
|
let modify_data: types::ChannelModifySchema = types::ChannelModifySchema {
|
||||||
name: Some(CHANNEL_NAME.to_string()),
|
name: Some(CHANNEL_NAME.to_string()),
|
||||||
channel_type: None,
|
channel_type: None,
|
||||||
|
@ -50,12 +51,7 @@ async fn modify_channel() {
|
||||||
default_thread_rate_limit_per_user: None,
|
default_thread_rate_limit_per_user: None,
|
||||||
video_quality_mode: None,
|
video_quality_mode: None,
|
||||||
};
|
};
|
||||||
let modified_channel = Channel::modify(
|
let modified_channel = Channel::modify(channel, modify_data, &mut bundle.user)
|
||||||
channel.read().as_ref().unwrap(),
|
|
||||||
modify_data,
|
|
||||||
channel.read().unwrap().id,
|
|
||||||
&mut bundle.user,
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(modified_channel.name, Some(CHANNEL_NAME.to_string()));
|
assert_eq!(modified_channel.name, Some(CHANNEL_NAME.to_string()));
|
||||||
|
@ -64,23 +60,19 @@ async fn modify_channel() {
|
||||||
PermissionFlags::MANAGE_CHANNELS,
|
PermissionFlags::MANAGE_CHANNELS,
|
||||||
PermissionFlags::MANAGE_MESSAGES,
|
PermissionFlags::MANAGE_MESSAGES,
|
||||||
]));
|
]));
|
||||||
let user_id: types::Snowflake = bundle.user.read().unwrap().object.read().unwrap().id;
|
let user_id: types::Snowflake = bundle.user.object.read().unwrap().id;
|
||||||
let permission_override = PermissionOverwrite {
|
let permission_override = PermissionOverwrite {
|
||||||
id: user_id,
|
id: user_id,
|
||||||
overwrite_type: "1".to_string(),
|
overwrite_type: "1".to_string(),
|
||||||
allow: permission_override,
|
allow: permission_override,
|
||||||
deny: "0".to_string(),
|
deny: "0".to_string(),
|
||||||
};
|
};
|
||||||
|
let channel_id: Snowflake = bundle.channel.read().unwrap().id;
|
||||||
Channel::edit_permissions(
|
Channel::edit_permissions(&mut bundle.user, channel_id, permission_override.clone())
|
||||||
&mut bundle.user,
|
|
||||||
bundle.channel.id,
|
|
||||||
permission_override.clone(),
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Channel::delete_permission(&mut bundle.user, bundle.channel.id, permission_override.id)
|
Channel::delete_permission(&mut bundle.user, channel_id, permission_override.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -90,7 +82,7 @@ async fn modify_channel() {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn get_channel_messages() {
|
async fn get_channel_messages() {
|
||||||
let mut bundle = common::setup().await;
|
let mut bundle = common::setup().await;
|
||||||
|
let channel_id: Snowflake = bundle.channel.read().unwrap().id;
|
||||||
// First create some messages to read
|
// First create some messages to read
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
let _ = bundle
|
let _ = bundle
|
||||||
|
@ -100,7 +92,7 @@ async fn get_channel_messages() {
|
||||||
content: Some("A Message!".to_string()),
|
content: Some("A Message!".to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
bundle.channel.id,
|
channel_id,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -109,7 +101,7 @@ async fn get_channel_messages() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Channel::messages(
|
Channel::messages(
|
||||||
GetChannelMessagesSchema::before(Snowflake::generate()),
|
GetChannelMessagesSchema::before(Snowflake::generate()),
|
||||||
bundle.channel.id,
|
channel_id,
|
||||||
&mut bundle.user,
|
&mut bundle.user,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -133,7 +125,7 @@ async fn get_channel_messages() {
|
||||||
|
|
||||||
assert!(Channel::messages(
|
assert!(Channel::messages(
|
||||||
GetChannelMessagesSchema::after(Snowflake::generate()),
|
GetChannelMessagesSchema::after(Snowflake::generate()),
|
||||||
bundle.channel.id,
|
channel_id,
|
||||||
&mut bundle.user,
|
&mut bundle.user,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -27,9 +27,7 @@ async fn guild_creation_deletion() {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn get_channels() {
|
async fn get_channels() {
|
||||||
let mut bundle = common::setup().await;
|
let mut bundle = common::setup().await;
|
||||||
println!(
|
let guild = bundle.guild.read().unwrap().clone();
|
||||||
"{:?}",
|
println!("{:?}", guild.channels(&mut bundle.user).await.unwrap());
|
||||||
bundle.guild.channels(&mut bundle.user).await.unwrap()
|
|
||||||
);
|
|
||||||
common::teardown(bundle).await;
|
common::teardown(bundle).await;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,12 @@ use chorus::types::CreateChannelInviteSchema;
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn create_accept_invite() {
|
async fn create_accept_invite() {
|
||||||
let mut bundle = common::setup().await;
|
let mut bundle = common::setup().await;
|
||||||
let channel = bundle.channel.clone();
|
let channel = bundle.channel.read().unwrap().clone();
|
||||||
let mut other_user = bundle.create_user("testuser1312").await;
|
let mut other_user = bundle.create_user("testuser1312").await;
|
||||||
let user = &mut bundle.user;
|
let user = &mut bundle.user;
|
||||||
let create_channel_invite_schema = CreateChannelInviteSchema::default();
|
let create_channel_invite_schema = CreateChannelInviteSchema::default();
|
||||||
assert!(chorus::types::Guild::get(bundle.guild.id, &mut other_user)
|
let guild = bundle.guild.read().unwrap().clone();
|
||||||
|
assert!(chorus::types::Guild::get(guild.id, &mut other_user)
|
||||||
.await
|
.await
|
||||||
.is_err());
|
.is_err());
|
||||||
let invite = user
|
let invite = user
|
||||||
|
@ -16,7 +17,7 @@ async fn create_accept_invite() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
other_user.accept_invite(&invite.code, None).await.unwrap();
|
other_user.accept_invite(&invite.code, None).await.unwrap();
|
||||||
assert!(chorus::types::Guild::get(bundle.guild.id, &mut other_user)
|
assert!(chorus::types::Guild::get(guild.id, &mut other_user)
|
||||||
.await
|
.await
|
||||||
.is_ok());
|
.is_ok());
|
||||||
common::teardown(bundle).await;
|
common::teardown(bundle).await;
|
||||||
|
|
|
@ -5,8 +5,8 @@ mod common;
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn add_remove_role() -> ChorusResult<()> {
|
async fn add_remove_role() -> ChorusResult<()> {
|
||||||
let mut bundle = common::setup().await;
|
let mut bundle = common::setup().await;
|
||||||
let guild = bundle.guild.id;
|
let guild = bundle.guild.read().unwrap().id;
|
||||||
let role = bundle.role.id;
|
let role = bundle.role.read().unwrap().id;
|
||||||
let member_id = bundle.user.object.read().unwrap().id;
|
let member_id = bundle.user.object.read().unwrap().id;
|
||||||
GuildMember::add_role(&mut bundle.user, guild, member_id, role).await?;
|
GuildMember::add_role(&mut bundle.user, guild, member_id, role).await?;
|
||||||
let member = GuildMember::get(&mut bundle.user, guild, member_id)
|
let member = GuildMember::get(&mut bundle.user, guild, member_id)
|
||||||
|
|
|
@ -12,11 +12,8 @@ async fn send_message() {
|
||||||
content: Some("A Message!".to_string()),
|
content: Some("A Message!".to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let _ = bundle
|
let channel = bundle.channel.read().unwrap().clone();
|
||||||
.user
|
let _ = bundle.user.send_message(message, channel.id).await.unwrap();
|
||||||
.send_message(message, bundle.channel.id)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
common::teardown(bundle).await
|
common::teardown(bundle).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,13 +47,9 @@ async fn send_message_attachment() {
|
||||||
attachments: Some(vec![attachment.clone()]),
|
attachments: Some(vec![attachment.clone()]),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
let channel = bundle.channel.read().unwrap().clone();
|
||||||
let vec_attach = vec![attachment.clone()];
|
let vec_attach = vec![attachment.clone()];
|
||||||
let _arg = Some(&vec_attach);
|
let _arg = Some(&vec_attach);
|
||||||
bundle
|
bundle.user.send_message(message, channel.id).await.unwrap();
|
||||||
.user
|
|
||||||
.send_message(message, bundle.channel.id)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
common::teardown(bundle).await
|
common::teardown(bundle).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,12 +17,12 @@ async fn create_and_get_roles() {
|
||||||
position: None,
|
position: None,
|
||||||
color: None,
|
color: None,
|
||||||
};
|
};
|
||||||
let guild = bundle.guild.id;
|
let guild_id = bundle.guild.read().unwrap().id;
|
||||||
let role = types::RoleObject::create(&mut bundle.user, guild, role_create_schema)
|
let role = types::RoleObject::create(&mut bundle.user, guild_id, role_create_schema)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let expected = types::RoleObject::get_all(&mut bundle.user, guild)
|
let expected = types::RoleObject::get_all(&mut bundle.user, guild_id)
|
||||||
.await
|
.await
|
||||||
.unwrap()[2]
|
.unwrap()[2]
|
||||||
.clone();
|
.clone();
|
||||||
|
@ -34,9 +34,9 @@ async fn create_and_get_roles() {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn get_singular_role() {
|
async fn get_singular_role() {
|
||||||
let mut bundle = common::setup().await;
|
let mut bundle = common::setup().await;
|
||||||
let guild_id = bundle.guild.id;
|
let guild_id = bundle.guild.read().unwrap().id;
|
||||||
let role_id = bundle.role.id;
|
let role_id = bundle.role.read().unwrap().id;
|
||||||
let role = bundle.role.clone();
|
let role = bundle.role.read().unwrap().clone();
|
||||||
let same_role = chorus::types::RoleObject::get(&mut bundle.user, guild_id, role_id)
|
let same_role = chorus::types::RoleObject::get(&mut bundle.user, guild_id, role_id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
Loading…
Reference in New Issue