2023-06-25 11:33:50 +02:00
|
|
|
use chorus::types::{self, RegisterSchema, Relationship, RelationshipType};
|
2023-06-15 18:48:01 +02:00
|
|
|
|
|
|
|
mod common;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_get_mutual_relationships() {
|
2023-06-25 11:33:50 +02:00
|
|
|
let register_schema = RegisterSchema {
|
|
|
|
username: "integrationtestuser2".to_string(),
|
|
|
|
consent: true,
|
2023-06-19 10:27:32 +02:00
|
|
|
date_of_birth: Some("2000-01-01".to_string()),
|
2023-06-25 11:33:50 +02:00
|
|
|
..Default::default()
|
|
|
|
};
|
2023-06-15 18:48:01 +02:00
|
|
|
|
2023-06-18 15:39:40 +02:00
|
|
|
let mut bundle = common::setup().await;
|
|
|
|
let belongs_to = &mut bundle.instance;
|
|
|
|
let user = &mut bundle.user;
|
2023-06-18 13:59:11 +02:00
|
|
|
let mut other_user = belongs_to.register_account(®ister_schema).await.unwrap();
|
|
|
|
let friend_request_schema = types::FriendRequestSendSchema {
|
|
|
|
username: user.object.username.clone(),
|
|
|
|
discriminator: Some(user.object.discriminator.clone()),
|
|
|
|
};
|
2023-07-09 18:38:02 +02:00
|
|
|
let _ = other_user.send_friend_request(friend_request_schema).await;
|
2023-06-15 18:48:01 +02:00
|
|
|
let relationships = user
|
2023-06-22 13:14:07 +02:00
|
|
|
.get_mutual_relationships(other_user.object.id)
|
2023-06-15 18:48:01 +02:00
|
|
|
.await
|
|
|
|
.unwrap();
|
2023-06-18 15:39:40 +02:00
|
|
|
println!("{:?}", relationships);
|
|
|
|
common::teardown(bundle).await
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_get_relationships() {
|
2023-06-25 11:33:50 +02:00
|
|
|
let register_schema = RegisterSchema {
|
|
|
|
username: "integrationtestuser2".to_string(),
|
|
|
|
consent: true,
|
2023-06-19 10:27:32 +02:00
|
|
|
date_of_birth: Some("2000-01-01".to_string()),
|
2023-06-25 11:33:50 +02:00
|
|
|
..Default::default()
|
|
|
|
};
|
2023-06-18 15:39:40 +02:00
|
|
|
|
|
|
|
let mut bundle = common::setup().await;
|
|
|
|
let belongs_to = &mut bundle.instance;
|
|
|
|
let user = &mut bundle.user;
|
|
|
|
let mut other_user = belongs_to.register_account(®ister_schema).await.unwrap();
|
|
|
|
let friend_request_schema = types::FriendRequestSendSchema {
|
|
|
|
username: user.object.username.clone(),
|
|
|
|
discriminator: Some(user.object.discriminator.clone()),
|
|
|
|
};
|
2023-07-09 18:38:02 +02:00
|
|
|
other_user
|
|
|
|
.send_friend_request(friend_request_schema)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2023-06-18 15:39:40 +02:00
|
|
|
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() {
|
2023-06-25 11:33:50 +02:00
|
|
|
let register_schema = RegisterSchema {
|
|
|
|
username: "integrationtestuser2".to_string(),
|
|
|
|
consent: true,
|
2023-06-19 18:11:53 +02:00
|
|
|
date_of_birth: Some("2000-01-01".to_string()),
|
2023-06-25 11:33:50 +02:00
|
|
|
..Default::default()
|
|
|
|
};
|
2023-06-19 18:11:53 +02:00
|
|
|
|
|
|
|
let mut bundle = common::setup().await;
|
|
|
|
let belongs_to = &mut bundle.instance;
|
|
|
|
let user = &mut bundle.user;
|
|
|
|
let mut other_user = belongs_to.register_account(®ister_schema).await.unwrap();
|
2023-07-09 18:38:02 +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-09 18:38:02 +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-09 18:38:02 +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()
|
|
|
|
);
|
2023-06-18 15:39:40 +02:00
|
|
|
common::teardown(bundle).await
|
2023-06-15 18:48:01 +02:00
|
|
|
}
|
2023-06-19 18:46:49 +02:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_modify_relationship_block() {
|
2023-06-25 11:33:50 +02:00
|
|
|
let register_schema = RegisterSchema {
|
|
|
|
username: "integrationtestuser2".to_string(),
|
|
|
|
consent: true,
|
2023-06-19 18:46:49 +02:00
|
|
|
date_of_birth: Some("2000-01-01".to_string()),
|
2023-06-25 11:33:50 +02:00
|
|
|
..Default::default()
|
|
|
|
};
|
2023-06-19 18:46:49 +02:00
|
|
|
|
|
|
|
let mut bundle = common::setup().await;
|
|
|
|
let belongs_to = &mut bundle.instance;
|
|
|
|
let user = &mut bundle.user;
|
|
|
|
let mut other_user = belongs_to.register_account(®ister_schema).await.unwrap();
|
2023-07-09 18:38:02 +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-09 18:38:02 +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
|
|
|
|
}
|