chorus/tests/relationships.rs

105 lines
3.6 KiB
Rust
Raw Normal View History

2023-07-28 17:33:23 +02:00
use chorus::types::{self, Relationship, RelationshipType};
mod common;
#[tokio::test]
async fn test_get_mutual_relationships() {
let mut bundle = common::setup().await;
2023-07-28 17:33:23 +02:00
let mut other_user = bundle.create_user("integrationtestuser2").await;
let user = &mut bundle.user;
2023-06-18 13:59:11 +02:00
let friend_request_schema = types::FriendRequestSendSchema {
username: user.object.username.clone(),
discriminator: Some(user.object.discriminator.clone()),
};
2023-07-28 17:33:23 +02:00
let _ = other_user.send_friend_request(friend_request_schema).await;
let relationships = user
2023-06-22 13:14:07 +02:00
.get_mutual_relationships(other_user.object.id)
.await
.unwrap();
println!("{:?}", relationships);
common::teardown(bundle).await
}
#[tokio::test]
async fn test_get_relationships() {
let mut bundle = common::setup().await;
2023-07-28 17:33:23 +02:00
let mut other_user = bundle.create_user("integrationtestuser2").await;
let user = &mut bundle.user;
let friend_request_schema = types::FriendRequestSendSchema {
username: user.object.username.clone(),
discriminator: Some(user.object.discriminator.clone()),
};
2023-07-28 17:33:23 +02:00
other_user
.send_friend_request(friend_request_schema)
.await
.unwrap();
let relationships = user.get_relationships().await.unwrap();
2023-06-19 18:11:53 +02:00
assert_eq!(relationships.get(0).unwrap().id, other_user.object.id);
common::teardown(bundle).await
}
#[tokio::test]
async fn test_modify_relationship_friends() {
let mut bundle = common::setup().await;
2023-07-28 17:33:23 +02:00
let mut other_user = bundle.create_user("integrationtestuser2").await;
2023-06-19 18:11:53 +02:00
let user = &mut bundle.user;
2023-07-28 17:33:23 +02:00
let _ = other_user
2023-06-22 13:14:07 +02:00
.modify_user_relationship(user.object.id, types::RelationshipType::Friends)
2023-06-19 18:11:53 +02:00
.await;
let relationships = user.get_relationships().await.unwrap();
assert_eq!(relationships.get(0).unwrap().id, other_user.object.id);
assert_eq!(
relationships.get(0).unwrap().relationship_type,
RelationshipType::Incoming
);
let relationships = other_user.get_relationships().await.unwrap();
assert_eq!(relationships.get(0).unwrap().id, user.object.id);
assert_eq!(
relationships.get(0).unwrap().relationship_type,
RelationshipType::Outgoing
);
2023-07-28 17:33:23 +02:00
let _ = user
.modify_user_relationship(other_user.object.id, RelationshipType::Friends)
2023-06-22 13:14:07 +02:00
.await;
2023-06-19 18:11:53 +02:00
assert_eq!(
other_user
.get_relationships()
.await
.unwrap()
.get(0)
.unwrap()
.relationship_type,
RelationshipType::Friends
);
2023-07-28 17:33:23 +02:00
let _ = user.remove_relationship(other_user.object.id).await;
2023-06-19 18:11:53 +02:00
assert_eq!(
other_user.get_relationships().await.unwrap(),
Vec::<Relationship>::new()
);
common::teardown(bundle).await
}
2023-06-19 18:46:49 +02:00
#[tokio::test]
async fn test_modify_relationship_block() {
let mut bundle = common::setup().await;
2023-07-28 17:33:23 +02:00
let mut other_user = bundle.create_user("integrationtestuser2").await;
2023-06-19 18:46:49 +02:00
let user = &mut bundle.user;
2023-07-28 17:33:23 +02:00
let _ = other_user
2023-06-22 13:14:07 +02:00
.modify_user_relationship(user.object.id, types::RelationshipType::Blocked)
2023-06-19 18:46:49 +02:00
.await;
let relationships = user.get_relationships().await.unwrap();
assert_eq!(relationships, Vec::<Relationship>::new());
let relationships = other_user.get_relationships().await.unwrap();
assert_eq!(relationships.get(0).unwrap().id, user.object.id);
assert_eq!(
relationships.get(0).unwrap().relationship_type,
RelationshipType::Blocked
);
2023-07-28 17:33:23 +02:00
let _ = other_user.remove_relationship(user.object.id).await;
2023-06-19 18:46:49 +02:00
assert_eq!(
other_user.get_relationships().await.unwrap(),
Vec::<Relationship>::new()
);
common::teardown(bundle).await
}