2023-12-20 16:08:19 +00:00
|
|
|
extern crate ibis;
|
2023-11-16 09:25:54 +00:00
|
|
|
|
2023-11-16 14:27:35 +00:00
|
|
|
mod common;
|
|
|
|
|
2023-11-24 14:48:43 +00:00
|
|
|
use crate::common::{
|
2024-01-03 16:06:52 +00:00
|
|
|
create_article, edit_article, edit_article_with_conflict, follow_instance, get, TestData,
|
|
|
|
CLIENT, TEST_ARTICLE_DEFAULT_TEXT,
|
2023-11-24 14:48:43 +00:00
|
|
|
};
|
2024-01-03 16:06:52 +00:00
|
|
|
use crate::common::{fork_article, login};
|
2023-12-19 14:32:14 +00:00
|
|
|
use crate::common::{get_conflicts, register};
|
2024-01-03 16:06:52 +00:00
|
|
|
use ibis::backend::api::article::{CreateArticleData, EditArticleData, ForkArticleData};
|
|
|
|
use ibis::backend::api::{ResolveObject, SearchArticleData};
|
|
|
|
use ibis::backend::database::instance::{DbInstance, InstanceView};
|
|
|
|
use ibis::backend::error::MyResult;
|
|
|
|
use ibis::common::ArticleView;
|
|
|
|
use ibis::common::DbArticle;
|
|
|
|
use ibis::frontend::api::get_article;
|
|
|
|
use ibis::frontend::api::get_query;
|
|
|
|
use ibis::frontend::api::handle_json_res;
|
2023-12-01 13:04:51 +00:00
|
|
|
use pretty_assertions::{assert_eq, assert_ne};
|
2023-11-16 11:48:57 +00:00
|
|
|
use url::Url;
|
|
|
|
|
2023-11-15 12:05:07 +00:00
|
|
|
#[tokio::test]
|
2023-11-22 14:59:22 +00:00
|
|
|
async fn test_create_read_and_edit_article() -> MyResult<()> {
|
2023-12-13 15:40:20 +00:00
|
|
|
let data = TestData::start().await;
|
2023-11-15 12:05:07 +00:00
|
|
|
|
2023-11-16 12:38:41 +00:00
|
|
|
// create article
|
2023-11-28 13:29:51 +00:00
|
|
|
let title = "Manu_Chao".to_string();
|
2023-12-13 15:40:20 +00:00
|
|
|
let create_res = create_article(&data.alpha, title.clone()).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(title, create_res.article.title);
|
|
|
|
assert!(create_res.article.local);
|
2023-11-16 12:38:41 +00:00
|
|
|
|
|
|
|
// now article can be read
|
2023-12-01 11:11:19 +00:00
|
|
|
let get_res = get_article(&data.alpha.hostname, create_res.article.id).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(title, get_res.article.title);
|
|
|
|
assert_eq!(TEST_ARTICLE_DEFAULT_TEXT, get_res.article.text);
|
|
|
|
assert!(get_res.article.local);
|
2023-11-16 12:38:41 +00:00
|
|
|
|
2023-11-28 13:29:51 +00:00
|
|
|
// error on article which wasnt federated
|
2023-12-01 11:11:19 +00:00
|
|
|
let not_found = get_article(&data.beta.hostname, create_res.article.id).await;
|
2023-11-28 13:29:51 +00:00
|
|
|
assert!(not_found.is_err());
|
|
|
|
|
2023-11-22 14:59:22 +00:00
|
|
|
// edit article
|
|
|
|
let edit_form = EditArticleData {
|
2023-11-30 14:55:05 +00:00
|
|
|
article_id: create_res.article.id,
|
2023-11-22 14:59:22 +00:00
|
|
|
new_text: "Lorem Ipsum 2".to_string(),
|
2023-12-05 00:17:02 +00:00
|
|
|
previous_version_id: get_res.latest_version,
|
2023-11-27 15:34:45 +00:00
|
|
|
resolve_conflict_id: None,
|
2023-11-22 14:59:22 +00:00
|
|
|
};
|
2023-12-13 15:40:20 +00:00
|
|
|
let edit_res = edit_article(&data.alpha, &edit_form).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(edit_form.new_text, edit_res.article.text);
|
2023-11-27 10:25:29 +00:00
|
|
|
assert_eq!(2, edit_res.edits.len());
|
2023-11-22 14:59:22 +00:00
|
|
|
|
2023-11-28 14:11:05 +00:00
|
|
|
let search_form = SearchArticleData {
|
2023-11-30 14:14:30 +00:00
|
|
|
query: title.clone(),
|
2023-11-28 14:11:05 +00:00
|
|
|
};
|
|
|
|
let search_res: Vec<DbArticle> =
|
2023-12-01 11:11:19 +00:00
|
|
|
get_query(&data.alpha.hostname, "search", Some(search_form)).await?;
|
2023-11-28 14:11:05 +00:00
|
|
|
assert_eq!(1, search_res.len());
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(edit_res.article, search_res[0]);
|
2023-11-28 14:11:05 +00:00
|
|
|
|
|
|
|
data.stop()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_create_duplicate_article() -> MyResult<()> {
|
2023-12-13 15:40:20 +00:00
|
|
|
let data = TestData::start().await;
|
2023-11-28 14:11:05 +00:00
|
|
|
|
|
|
|
// create article
|
|
|
|
let title = "Manu_Chao".to_string();
|
2023-12-13 15:40:20 +00:00
|
|
|
let create_res = create_article(&data.alpha, title.clone()).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(title, create_res.article.title);
|
|
|
|
assert!(create_res.article.local);
|
2023-11-28 14:11:05 +00:00
|
|
|
|
2023-12-13 15:40:20 +00:00
|
|
|
let create_res = create_article(&data.alpha, title.clone()).await;
|
2023-11-28 14:11:05 +00:00
|
|
|
assert!(create_res.is_err());
|
|
|
|
|
2023-11-17 13:36:56 +00:00
|
|
|
data.stop()
|
2023-11-15 12:05:07 +00:00
|
|
|
}
|
2023-11-15 14:07:02 +00:00
|
|
|
|
|
|
|
#[tokio::test]
|
2023-11-16 09:25:54 +00:00
|
|
|
async fn test_follow_instance() -> MyResult<()> {
|
2023-12-13 15:40:20 +00:00
|
|
|
let data = TestData::start().await;
|
2023-11-15 14:07:02 +00:00
|
|
|
|
2023-11-16 11:48:57 +00:00
|
|
|
// check initial state
|
2023-12-02 01:38:57 +00:00
|
|
|
let alpha_instance: InstanceView = get(&data.alpha.hostname, "instance").await?;
|
|
|
|
assert_eq!(0, alpha_instance.followers.len());
|
2023-12-04 14:10:07 +00:00
|
|
|
assert_eq!(0, alpha_instance.following.len());
|
2023-12-02 01:38:57 +00:00
|
|
|
let beta_instance: InstanceView = get(&data.beta.hostname, "instance").await?;
|
2023-11-16 11:48:57 +00:00
|
|
|
assert_eq!(0, beta_instance.followers.len());
|
2023-12-04 14:10:07 +00:00
|
|
|
assert_eq!(0, beta_instance.following.len());
|
2023-11-16 11:48:57 +00:00
|
|
|
|
2023-12-14 16:06:44 +00:00
|
|
|
follow_instance(&data.alpha, &data.beta.hostname).await?;
|
2023-11-16 11:48:57 +00:00
|
|
|
|
|
|
|
// check that follow was federated
|
2023-12-04 14:10:07 +00:00
|
|
|
let alpha_instance: InstanceView = get(&data.alpha.hostname, "instance").await?;
|
|
|
|
assert_eq!(1, alpha_instance.following.len());
|
|
|
|
assert_eq!(0, alpha_instance.followers.len());
|
|
|
|
assert_eq!(
|
|
|
|
beta_instance.instance.ap_id,
|
|
|
|
alpha_instance.following[0].ap_id
|
|
|
|
);
|
|
|
|
|
2023-12-02 01:38:57 +00:00
|
|
|
let beta_instance: InstanceView = get(&data.beta.hostname, "instance").await?;
|
2023-12-04 14:10:07 +00:00
|
|
|
assert_eq!(0, beta_instance.following.len());
|
2023-11-16 11:48:57 +00:00
|
|
|
assert_eq!(1, beta_instance.followers.len());
|
2023-12-14 16:06:44 +00:00
|
|
|
// TODO: compare full ap_id of alpha user, but its not available through api yet
|
2023-12-04 14:10:07 +00:00
|
|
|
assert_eq!(
|
2023-12-14 16:06:44 +00:00
|
|
|
alpha_instance.instance.ap_id.inner().domain(),
|
|
|
|
beta_instance.followers[0].ap_id.inner().domain()
|
2023-12-04 14:10:07 +00:00
|
|
|
);
|
2023-11-16 09:25:54 +00:00
|
|
|
|
2023-11-17 13:36:56 +00:00
|
|
|
data.stop()
|
2023-11-16 09:25:54 +00:00
|
|
|
}
|
2023-12-01 11:11:19 +00:00
|
|
|
|
2023-11-16 15:40:43 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn test_synchronize_articles() -> MyResult<()> {
|
2023-12-13 15:40:20 +00:00
|
|
|
let data = TestData::start().await;
|
2023-11-16 15:40:43 +00:00
|
|
|
|
|
|
|
// create article on alpha
|
2023-11-24 14:48:43 +00:00
|
|
|
let title = "Manu_Chao".to_string();
|
2023-12-13 15:40:20 +00:00
|
|
|
let create_res = create_article(&data.alpha, title.clone()).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(title, create_res.article.title);
|
2023-11-27 10:25:29 +00:00
|
|
|
assert_eq!(1, create_res.edits.len());
|
2023-11-30 14:55:05 +00:00
|
|
|
assert!(create_res.article.local);
|
2023-11-16 15:40:43 +00:00
|
|
|
|
2023-11-24 15:09:17 +00:00
|
|
|
// edit the article
|
|
|
|
let edit_form = EditArticleData {
|
2023-11-30 14:55:05 +00:00
|
|
|
article_id: create_res.article.id,
|
2023-11-27 10:25:29 +00:00
|
|
|
new_text: "Lorem Ipsum 2\n".to_string(),
|
2023-12-05 00:17:02 +00:00
|
|
|
previous_version_id: create_res.latest_version,
|
2023-11-27 15:34:45 +00:00
|
|
|
resolve_conflict_id: None,
|
2023-11-24 15:09:17 +00:00
|
|
|
};
|
2023-12-13 15:40:20 +00:00
|
|
|
edit_article(&data.alpha, &edit_form).await?;
|
2023-11-24 15:09:17 +00:00
|
|
|
|
2023-11-16 15:40:43 +00:00
|
|
|
// article is not yet on beta
|
2023-12-01 11:11:19 +00:00
|
|
|
let get_res = get_article(&data.beta.hostname, create_res.article.id).await;
|
2023-11-16 15:40:43 +00:00
|
|
|
assert!(get_res.is_err());
|
|
|
|
|
|
|
|
// fetch alpha instance on beta, articles are also fetched automatically
|
|
|
|
let resolve_object = ResolveObject {
|
2023-12-01 11:11:19 +00:00
|
|
|
id: Url::parse(&format!("http://{}", &data.alpha.hostname))?,
|
2023-11-16 15:40:43 +00:00
|
|
|
};
|
2023-12-01 11:11:19 +00:00
|
|
|
get_query::<DbInstance, _>(
|
|
|
|
&data.beta.hostname,
|
|
|
|
"resolve_instance",
|
|
|
|
Some(resolve_object),
|
|
|
|
)
|
|
|
|
.await?;
|
2023-11-16 15:40:43 +00:00
|
|
|
|
|
|
|
// get the article and compare
|
2023-12-01 11:11:19 +00:00
|
|
|
let get_res = get_article(&data.beta.hostname, create_res.article.id).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(create_res.article.ap_id, get_res.article.ap_id);
|
|
|
|
assert_eq!(title, get_res.article.title);
|
2023-11-27 10:25:29 +00:00
|
|
|
assert_eq!(2, get_res.edits.len());
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(edit_form.new_text, get_res.article.text);
|
|
|
|
assert!(!get_res.article.local);
|
2023-11-16 15:40:43 +00:00
|
|
|
|
2023-11-17 13:36:56 +00:00
|
|
|
data.stop()
|
2023-11-16 15:40:43 +00:00
|
|
|
}
|
2023-11-17 13:22:31 +00:00
|
|
|
|
|
|
|
#[tokio::test]
|
2023-11-22 14:59:22 +00:00
|
|
|
async fn test_edit_local_article() -> MyResult<()> {
|
2023-12-13 15:40:20 +00:00
|
|
|
let data = TestData::start().await;
|
2023-11-17 13:36:56 +00:00
|
|
|
|
2023-12-14 16:06:44 +00:00
|
|
|
follow_instance(&data.alpha, &data.beta.hostname).await?;
|
2023-11-17 13:22:31 +00:00
|
|
|
|
|
|
|
// create new article
|
2023-11-24 14:48:43 +00:00
|
|
|
let title = "Manu_Chao".to_string();
|
2023-12-13 15:40:20 +00:00
|
|
|
let create_res = create_article(&data.beta, title.clone()).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(title, create_res.article.title);
|
|
|
|
assert!(create_res.article.local);
|
2023-11-17 13:22:31 +00:00
|
|
|
|
|
|
|
// article should be federated to alpha
|
2023-12-01 11:11:19 +00:00
|
|
|
let get_res = get_article(&data.alpha.hostname, create_res.article.id).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(create_res.article.title, get_res.article.title);
|
2023-11-27 10:25:29 +00:00
|
|
|
assert_eq!(1, get_res.edits.len());
|
2023-11-30 14:55:05 +00:00
|
|
|
assert!(!get_res.article.local);
|
|
|
|
assert_eq!(create_res.article.text, get_res.article.text);
|
2023-11-17 13:22:31 +00:00
|
|
|
|
|
|
|
// edit the article
|
2023-11-21 15:27:18 +00:00
|
|
|
let edit_form = EditArticleData {
|
2023-11-30 14:55:05 +00:00
|
|
|
article_id: create_res.article.id,
|
2023-11-17 13:22:31 +00:00
|
|
|
new_text: "Lorem Ipsum 2".to_string(),
|
2023-12-05 00:17:02 +00:00
|
|
|
previous_version_id: get_res.latest_version,
|
2023-11-27 15:34:45 +00:00
|
|
|
resolve_conflict_id: None,
|
2023-11-17 13:22:31 +00:00
|
|
|
};
|
2023-12-13 15:40:20 +00:00
|
|
|
let edit_res = edit_article(&data.beta, &edit_form).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(edit_res.article.text, edit_form.new_text);
|
2023-11-27 10:25:29 +00:00
|
|
|
assert_eq!(edit_res.edits.len(), 2);
|
2023-11-21 15:27:18 +00:00
|
|
|
assert!(edit_res.edits[0]
|
2023-11-30 14:55:05 +00:00
|
|
|
.ap_id
|
2023-11-21 15:27:18 +00:00
|
|
|
.to_string()
|
2023-11-30 14:55:05 +00:00
|
|
|
.starts_with(&edit_res.article.ap_id.to_string()));
|
2023-11-17 13:22:31 +00:00
|
|
|
|
|
|
|
// edit should be federated to alpha
|
2023-12-01 11:11:19 +00:00
|
|
|
let get_res = get_article(&data.alpha.hostname, edit_res.article.id).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(edit_res.article.title, get_res.article.title);
|
2023-11-27 10:25:29 +00:00
|
|
|
assert_eq!(edit_res.edits.len(), 2);
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(edit_res.article.text, get_res.article.text);
|
2023-11-22 14:59:22 +00:00
|
|
|
|
|
|
|
data.stop()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_edit_remote_article() -> MyResult<()> {
|
2023-12-13 15:40:20 +00:00
|
|
|
let data = TestData::start().await;
|
2023-11-22 14:59:22 +00:00
|
|
|
|
2023-12-14 16:06:44 +00:00
|
|
|
follow_instance(&data.alpha, &data.beta.hostname).await?;
|
|
|
|
follow_instance(&data.gamma, &data.beta.hostname).await?;
|
2023-11-22 14:59:22 +00:00
|
|
|
|
|
|
|
// create new article
|
2023-11-24 14:48:43 +00:00
|
|
|
let title = "Manu_Chao".to_string();
|
2023-12-13 15:40:20 +00:00
|
|
|
let create_res = create_article(&data.beta, title.clone()).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(title, create_res.article.title);
|
|
|
|
assert!(create_res.article.local);
|
2023-11-22 14:59:22 +00:00
|
|
|
|
|
|
|
// article should be federated to alpha and gamma
|
2023-12-01 11:11:19 +00:00
|
|
|
let get_res = get_article(&data.alpha.hostname, create_res.article.id).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(create_res.article.title, get_res.article.title);
|
2023-11-27 10:25:29 +00:00
|
|
|
assert_eq!(1, get_res.edits.len());
|
2023-11-30 14:55:05 +00:00
|
|
|
assert!(!get_res.article.local);
|
2023-11-22 14:59:22 +00:00
|
|
|
|
2023-12-01 11:11:19 +00:00
|
|
|
let get_res = get_article(&data.gamma.hostname, create_res.article.id).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(create_res.article.title, get_res.article.title);
|
|
|
|
assert_eq!(create_res.article.text, get_res.article.text);
|
2023-11-22 14:59:22 +00:00
|
|
|
|
|
|
|
let edit_form = EditArticleData {
|
2023-11-30 14:55:05 +00:00
|
|
|
article_id: create_res.article.id,
|
2023-11-22 14:59:22 +00:00
|
|
|
new_text: "Lorem Ipsum 2".to_string(),
|
2023-12-05 00:17:02 +00:00
|
|
|
previous_version_id: get_res.latest_version,
|
2023-11-27 15:34:45 +00:00
|
|
|
resolve_conflict_id: None,
|
2023-11-22 14:59:22 +00:00
|
|
|
};
|
2023-12-13 15:40:20 +00:00
|
|
|
let edit_res = edit_article(&data.alpha, &edit_form).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(edit_form.new_text, edit_res.article.text);
|
2023-11-27 10:25:29 +00:00
|
|
|
assert_eq!(2, edit_res.edits.len());
|
2023-11-30 14:55:05 +00:00
|
|
|
assert!(!edit_res.article.local);
|
2023-11-22 14:59:22 +00:00
|
|
|
assert!(edit_res.edits[0]
|
2023-11-30 14:55:05 +00:00
|
|
|
.ap_id
|
2023-11-22 14:59:22 +00:00
|
|
|
.to_string()
|
2023-11-30 14:55:05 +00:00
|
|
|
.starts_with(&edit_res.article.ap_id.to_string()));
|
2023-11-22 14:59:22 +00:00
|
|
|
|
|
|
|
// edit should be federated to beta and gamma
|
2023-12-01 11:11:19 +00:00
|
|
|
let get_res = get_article(&data.alpha.hostname, create_res.article.id).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(edit_res.article.title, get_res.article.title);
|
2023-11-27 10:25:29 +00:00
|
|
|
assert_eq!(edit_res.edits.len(), 2);
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(edit_res.article.text, get_res.article.text);
|
2023-11-22 14:59:22 +00:00
|
|
|
|
2023-12-01 11:11:19 +00:00
|
|
|
let get_res = get_article(&data.gamma.hostname, create_res.article.id).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(edit_res.article.title, get_res.article.title);
|
2023-11-27 10:25:29 +00:00
|
|
|
assert_eq!(edit_res.edits.len(), 2);
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(edit_res.article.text, get_res.article.text);
|
2023-11-17 13:22:31 +00:00
|
|
|
|
2023-11-17 13:36:56 +00:00
|
|
|
data.stop()
|
2023-11-17 13:22:31 +00:00
|
|
|
}
|
2023-11-22 15:41:34 +00:00
|
|
|
|
|
|
|
#[tokio::test]
|
2023-11-27 15:34:45 +00:00
|
|
|
async fn test_local_edit_conflict() -> MyResult<()> {
|
2023-12-13 15:40:20 +00:00
|
|
|
let data = TestData::start().await;
|
2023-11-27 15:34:45 +00:00
|
|
|
|
|
|
|
// create new article
|
|
|
|
let title = "Manu_Chao".to_string();
|
2023-12-13 15:40:20 +00:00
|
|
|
let create_res = create_article(&data.alpha, title.clone()).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(title, create_res.article.title);
|
|
|
|
assert!(create_res.article.local);
|
2023-11-27 15:34:45 +00:00
|
|
|
|
|
|
|
// one user edits article
|
|
|
|
let edit_form = EditArticleData {
|
2023-11-30 14:55:05 +00:00
|
|
|
article_id: create_res.article.id,
|
2023-11-27 15:34:45 +00:00
|
|
|
new_text: "Lorem Ipsum\n".to_string(),
|
2023-12-05 00:17:02 +00:00
|
|
|
previous_version_id: create_res.latest_version.clone(),
|
2023-11-27 15:34:45 +00:00
|
|
|
resolve_conflict_id: None,
|
|
|
|
};
|
2023-12-13 15:40:20 +00:00
|
|
|
let edit_res = edit_article(&data.alpha, &edit_form).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(edit_res.article.text, edit_form.new_text);
|
2023-11-27 15:34:45 +00:00
|
|
|
assert_eq!(2, edit_res.edits.len());
|
|
|
|
|
|
|
|
// another user edits article, without being aware of previous edit
|
|
|
|
let edit_form = EditArticleData {
|
2023-11-30 14:55:05 +00:00
|
|
|
article_id: create_res.article.id,
|
2023-11-27 15:34:45 +00:00
|
|
|
new_text: "Ipsum Lorem\n".to_string(),
|
2023-12-05 00:17:02 +00:00
|
|
|
previous_version_id: create_res.latest_version,
|
2023-11-27 15:34:45 +00:00
|
|
|
resolve_conflict_id: None,
|
|
|
|
};
|
2023-12-13 15:40:20 +00:00
|
|
|
let edit_res = edit_article_with_conflict(&data.alpha, &edit_form)
|
2023-11-27 15:34:45 +00:00
|
|
|
.await?
|
|
|
|
.unwrap();
|
2023-11-28 12:13:36 +00:00
|
|
|
assert_eq!("<<<<<<< ours\nIpsum Lorem\n||||||| original\nsome\nexample\ntext\n=======\nLorem Ipsum\n>>>>>>> theirs\n", edit_res.three_way_merge);
|
2023-11-27 15:34:45 +00:00
|
|
|
|
2023-12-19 14:32:14 +00:00
|
|
|
let conflicts = get_conflicts(&data.alpha).await?;
|
2023-11-27 15:34:45 +00:00
|
|
|
assert_eq!(1, conflicts.len());
|
|
|
|
assert_eq!(conflicts[0], edit_res);
|
|
|
|
|
|
|
|
let edit_form = EditArticleData {
|
2023-11-30 14:55:05 +00:00
|
|
|
article_id: create_res.article.id,
|
2023-11-27 15:34:45 +00:00
|
|
|
new_text: "Lorem Ipsum and Ipsum Lorem\n".to_string(),
|
2023-12-05 00:17:02 +00:00
|
|
|
previous_version_id: edit_res.previous_version_id,
|
2023-11-27 15:34:45 +00:00
|
|
|
resolve_conflict_id: Some(edit_res.id),
|
|
|
|
};
|
2023-12-13 15:40:20 +00:00
|
|
|
let edit_res = edit_article(&data.alpha, &edit_form).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(edit_form.new_text, edit_res.article.text);
|
2023-11-27 15:34:45 +00:00
|
|
|
|
2023-12-19 14:32:14 +00:00
|
|
|
let conflicts = get_conflicts(&data.alpha).await?;
|
2023-11-27 15:34:45 +00:00
|
|
|
assert_eq!(0, conflicts.len());
|
|
|
|
|
|
|
|
data.stop()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_federated_edit_conflict() -> MyResult<()> {
|
2023-12-13 15:40:20 +00:00
|
|
|
let data = TestData::start().await;
|
2023-11-22 15:41:34 +00:00
|
|
|
|
2023-12-14 16:06:44 +00:00
|
|
|
follow_instance(&data.alpha, &data.beta.hostname).await?;
|
2023-11-22 15:41:34 +00:00
|
|
|
|
|
|
|
// create new article
|
2023-11-24 14:48:43 +00:00
|
|
|
let title = "Manu_Chao".to_string();
|
2023-12-13 15:40:20 +00:00
|
|
|
let create_res = create_article(&data.beta, title.clone()).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(title, create_res.article.title);
|
|
|
|
assert!(create_res.article.local);
|
2023-11-22 15:41:34 +00:00
|
|
|
|
2023-11-24 14:31:31 +00:00
|
|
|
// fetch article to gamma
|
|
|
|
let resolve_object = ResolveObject {
|
2023-11-30 14:55:05 +00:00
|
|
|
id: create_res.article.ap_id.inner().clone(),
|
2023-11-24 14:31:31 +00:00
|
|
|
};
|
2023-12-01 13:04:51 +00:00
|
|
|
let resolve_res: ArticleView = get_query(
|
2023-12-01 11:11:19 +00:00
|
|
|
&data.gamma.hostname,
|
|
|
|
"resolve_article",
|
|
|
|
Some(resolve_object),
|
|
|
|
)
|
|
|
|
.await?;
|
2023-12-01 13:04:51 +00:00
|
|
|
assert_eq!(create_res.article.text, resolve_res.article.text);
|
2023-11-24 14:31:31 +00:00
|
|
|
|
2023-11-22 15:41:34 +00:00
|
|
|
// alpha edits article
|
|
|
|
let edit_form = EditArticleData {
|
2023-11-30 14:55:05 +00:00
|
|
|
article_id: create_res.article.id,
|
2023-11-27 10:25:29 +00:00
|
|
|
new_text: "Lorem Ipsum\n".to_string(),
|
2023-12-05 00:17:02 +00:00
|
|
|
previous_version_id: create_res.latest_version.clone(),
|
2023-11-27 15:34:45 +00:00
|
|
|
resolve_conflict_id: None,
|
2023-11-22 15:41:34 +00:00
|
|
|
};
|
2023-12-13 15:40:20 +00:00
|
|
|
let edit_res = edit_article(&data.alpha, &edit_form).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(edit_res.article.text, edit_form.new_text);
|
2023-11-27 10:25:29 +00:00
|
|
|
assert_eq!(2, edit_res.edits.len());
|
2023-11-30 14:55:05 +00:00
|
|
|
assert!(!edit_res.article.local);
|
2023-11-27 10:25:29 +00:00
|
|
|
assert!(edit_res.edits[1]
|
2023-11-30 14:55:05 +00:00
|
|
|
.ap_id
|
2023-11-22 15:41:34 +00:00
|
|
|
.to_string()
|
2023-11-30 14:55:05 +00:00
|
|
|
.starts_with(&edit_res.article.ap_id.to_string()));
|
2023-11-22 15:41:34 +00:00
|
|
|
|
2023-11-24 15:09:17 +00:00
|
|
|
// gamma also edits, as its not the latest version there is a conflict. local version should
|
|
|
|
// not be updated with this conflicting version, instead user needs to handle the conflict
|
2023-11-22 15:41:34 +00:00
|
|
|
let edit_form = EditArticleData {
|
2023-11-30 14:55:05 +00:00
|
|
|
article_id: create_res.article.id,
|
2023-11-27 10:25:29 +00:00
|
|
|
new_text: "aaaa\n".to_string(),
|
2023-12-05 00:17:02 +00:00
|
|
|
previous_version_id: create_res.latest_version,
|
2023-11-27 15:34:45 +00:00
|
|
|
resolve_conflict_id: None,
|
2023-11-22 15:41:34 +00:00
|
|
|
};
|
2023-12-13 15:40:20 +00:00
|
|
|
let edit_res = edit_article(&data.gamma, &edit_form).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_ne!(edit_form.new_text, edit_res.article.text);
|
2023-12-05 11:54:38 +00:00
|
|
|
assert_eq!(1, edit_res.edits.len());
|
2023-11-30 14:55:05 +00:00
|
|
|
assert!(!edit_res.article.local);
|
2023-11-22 15:41:34 +00:00
|
|
|
|
2023-12-19 14:32:14 +00:00
|
|
|
let conflicts = get_conflicts(&data.gamma).await?;
|
2023-11-27 10:25:29 +00:00
|
|
|
assert_eq!(1, conflicts.len());
|
|
|
|
|
2023-11-27 15:34:45 +00:00
|
|
|
// resolve the conflict
|
|
|
|
let edit_form = EditArticleData {
|
2023-11-30 14:55:05 +00:00
|
|
|
article_id: create_res.article.id,
|
2023-11-27 15:34:45 +00:00
|
|
|
new_text: "aaaa\n".to_string(),
|
2023-12-05 00:17:02 +00:00
|
|
|
previous_version_id: conflicts[0].previous_version_id.clone(),
|
|
|
|
resolve_conflict_id: Some(conflicts[0].id.clone()),
|
2023-11-27 15:34:45 +00:00
|
|
|
};
|
2023-12-13 15:40:20 +00:00
|
|
|
let edit_res = edit_article(&data.gamma, &edit_form).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(edit_form.new_text, edit_res.article.text);
|
2023-11-27 15:34:45 +00:00
|
|
|
assert_eq!(3, edit_res.edits.len());
|
|
|
|
|
2023-12-19 14:32:14 +00:00
|
|
|
let conflicts = get_conflicts(&data.gamma).await?;
|
2023-11-27 15:34:45 +00:00
|
|
|
assert_eq!(0, conflicts.len());
|
2023-11-24 15:09:17 +00:00
|
|
|
|
2023-11-22 15:41:34 +00:00
|
|
|
data.stop()
|
|
|
|
}
|
2023-11-28 12:13:36 +00:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_overlapping_edits_no_conflict() -> MyResult<()> {
|
2023-12-13 15:40:20 +00:00
|
|
|
let data = TestData::start().await;
|
2023-11-28 12:13:36 +00:00
|
|
|
|
|
|
|
// create new article
|
|
|
|
let title = "Manu_Chao".to_string();
|
2023-12-13 15:40:20 +00:00
|
|
|
let create_res = create_article(&data.alpha, title.clone()).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(title, create_res.article.title);
|
|
|
|
assert!(create_res.article.local);
|
2023-11-28 12:13:36 +00:00
|
|
|
|
|
|
|
// one user edits article
|
|
|
|
let edit_form = EditArticleData {
|
2023-11-30 14:55:05 +00:00
|
|
|
article_id: create_res.article.id,
|
2023-11-28 12:13:36 +00:00
|
|
|
new_text: "my\nexample\ntext\n".to_string(),
|
2023-12-05 00:17:02 +00:00
|
|
|
previous_version_id: create_res.latest_version.clone(),
|
2023-11-28 12:13:36 +00:00
|
|
|
resolve_conflict_id: None,
|
|
|
|
};
|
2023-12-13 15:40:20 +00:00
|
|
|
let edit_res = edit_article(&data.alpha, &edit_form).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(edit_res.article.text, edit_form.new_text);
|
2023-11-28 12:13:36 +00:00
|
|
|
assert_eq!(2, edit_res.edits.len());
|
|
|
|
|
|
|
|
// another user edits article, without being aware of previous edit
|
|
|
|
let edit_form = EditArticleData {
|
2023-11-30 14:55:05 +00:00
|
|
|
article_id: create_res.article.id,
|
2023-11-28 12:13:36 +00:00
|
|
|
new_text: "some\nexample\narticle\n".to_string(),
|
2023-12-05 00:17:02 +00:00
|
|
|
previous_version_id: create_res.latest_version,
|
2023-11-28 12:13:36 +00:00
|
|
|
resolve_conflict_id: None,
|
|
|
|
};
|
2023-12-13 15:40:20 +00:00
|
|
|
let edit_res = edit_article(&data.alpha, &edit_form).await?;
|
2023-12-19 14:32:14 +00:00
|
|
|
let conflicts = get_conflicts(&data.alpha).await?;
|
2023-11-28 12:13:36 +00:00
|
|
|
assert_eq!(0, conflicts.len());
|
|
|
|
assert_eq!(3, edit_res.edits.len());
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!("my\nexample\narticle\n", edit_res.article.text);
|
2023-11-28 12:13:36 +00:00
|
|
|
|
|
|
|
data.stop()
|
|
|
|
}
|
2023-11-28 14:11:05 +00:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_fork_article() -> MyResult<()> {
|
2023-12-13 15:40:20 +00:00
|
|
|
let data = TestData::start().await;
|
2023-11-28 14:11:05 +00:00
|
|
|
|
|
|
|
// create article
|
|
|
|
let title = "Manu_Chao".to_string();
|
2023-12-13 15:40:20 +00:00
|
|
|
let create_res = create_article(&data.alpha, title.clone()).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_eq!(title, create_res.article.title);
|
|
|
|
assert!(create_res.article.local);
|
2023-11-28 14:11:05 +00:00
|
|
|
|
|
|
|
// fetch on beta
|
|
|
|
let resolve_object = ResolveObject {
|
2023-11-30 14:55:05 +00:00
|
|
|
id: create_res.article.ap_id.into_inner(),
|
2023-11-28 14:11:05 +00:00
|
|
|
};
|
2023-11-30 14:55:05 +00:00
|
|
|
let resolve_res: ArticleView =
|
2023-12-01 11:11:19 +00:00
|
|
|
get_query(&data.beta.hostname, "resolve_article", Some(resolve_object)).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
let resolved_article = resolve_res.article;
|
|
|
|
assert_eq!(create_res.edits.len(), resolve_res.edits.len());
|
2023-11-28 14:11:05 +00:00
|
|
|
|
|
|
|
// fork the article to local instance
|
|
|
|
let fork_form = ForkArticleData {
|
2023-11-30 14:14:30 +00:00
|
|
|
article_id: resolved_article.id,
|
2023-11-28 14:11:05 +00:00
|
|
|
};
|
2023-12-13 15:58:29 +00:00
|
|
|
let fork_res = fork_article(&data.beta, &fork_form).await?;
|
2023-11-30 14:55:05 +00:00
|
|
|
let forked_article = fork_res.article;
|
|
|
|
assert_eq!(resolved_article.title, forked_article.title);
|
|
|
|
assert_eq!(resolved_article.text, forked_article.text);
|
2023-12-01 13:04:51 +00:00
|
|
|
assert_eq!(resolve_res.edits.len(), fork_res.edits.len());
|
|
|
|
assert_eq!(resolve_res.edits[0].diff, fork_res.edits[0].diff);
|
2023-12-05 00:17:02 +00:00
|
|
|
assert_eq!(resolve_res.edits[0].hash, fork_res.edits[0].hash);
|
2023-12-01 13:04:51 +00:00
|
|
|
assert_ne!(resolve_res.edits[0].id, fork_res.edits[0].id);
|
|
|
|
assert_eq!(resolve_res.latest_version, fork_res.latest_version);
|
2023-11-30 14:55:05 +00:00
|
|
|
assert_ne!(resolved_article.ap_id, forked_article.ap_id);
|
|
|
|
assert!(forked_article.local);
|
2023-11-28 14:11:05 +00:00
|
|
|
|
2023-12-02 01:38:57 +00:00
|
|
|
let beta_instance: InstanceView = get(&data.beta.hostname, "instance").await?;
|
|
|
|
assert_eq!(forked_article.instance_id, beta_instance.instance.id);
|
2023-11-28 14:11:05 +00:00
|
|
|
|
|
|
|
// now search returns two articles for this title (original and forked)
|
|
|
|
let search_form = SearchArticleData {
|
2023-11-30 14:14:30 +00:00
|
|
|
query: title.clone(),
|
2023-11-28 14:11:05 +00:00
|
|
|
};
|
|
|
|
let search_res: Vec<DbArticle> =
|
2023-12-01 11:11:19 +00:00
|
|
|
get_query(&data.beta.hostname, "search", Some(search_form)).await?;
|
2023-11-28 14:11:05 +00:00
|
|
|
assert_eq!(2, search_res.len());
|
|
|
|
|
|
|
|
data.stop()
|
|
|
|
}
|
2023-12-08 21:21:31 +00:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_user_registration_login() -> MyResult<()> {
|
2023-12-13 15:40:20 +00:00
|
|
|
let data = TestData::start().await;
|
2023-12-13 15:58:29 +00:00
|
|
|
let username = "my_user";
|
|
|
|
let password = "hunter2";
|
|
|
|
let register = register(&data.alpha.hostname, username, password).await?;
|
2023-12-12 15:32:57 +00:00
|
|
|
assert!(!register.jwt.is_empty());
|
|
|
|
|
2023-12-13 15:58:29 +00:00
|
|
|
let invalid_login = login(&data.alpha, username, "asd123").await;
|
2023-12-12 15:32:57 +00:00
|
|
|
assert!(invalid_login.is_err());
|
|
|
|
|
2023-12-13 15:58:29 +00:00
|
|
|
let valid_login = login(&data.alpha, username, password).await?;
|
2023-12-12 15:32:57 +00:00
|
|
|
assert!(!valid_login.jwt.is_empty());
|
2023-12-08 21:21:31 +00:00
|
|
|
|
2023-12-13 15:40:20 +00:00
|
|
|
let title = "Manu_Chao".to_string();
|
|
|
|
let create_form = CreateArticleData {
|
|
|
|
title: title.clone(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let req = CLIENT
|
|
|
|
.post(format!("http://{}/api/v1/article", &data.alpha.hostname))
|
|
|
|
.form(&create_form)
|
|
|
|
.bearer_auth(valid_login.jwt);
|
|
|
|
let create_res: ArticleView = handle_json_res(req).await?;
|
|
|
|
assert_eq!(title, create_res.article.title);
|
|
|
|
|
2023-12-08 21:21:31 +00:00
|
|
|
data.stop()
|
2023-12-12 15:32:57 +00:00
|
|
|
}
|