mirror of
https://github.com/Nutomic/ibis.git
synced 2024-11-22 18:01:10 +00:00
adding more helper functions for tests
This commit is contained in:
parent
9a5a195bfd
commit
d224016327
2 changed files with 48 additions and 91 deletions
|
@ -1,4 +1,6 @@
|
||||||
use fediwiki::api::{EditArticleData, FollowInstance, GetArticleData, ResolveObject};
|
use fediwiki::api::{
|
||||||
|
CreateArticleData, EditArticleData, FollowInstance, GetArticleData, ResolveObject,
|
||||||
|
};
|
||||||
use fediwiki::error::MyResult;
|
use fediwiki::error::MyResult;
|
||||||
use fediwiki::federation::objects::article::DbArticle;
|
use fediwiki::federation::objects::article::DbArticle;
|
||||||
use fediwiki::federation::objects::instance::DbInstance;
|
use fediwiki::federation::objects::instance::DbInstance;
|
||||||
|
@ -64,6 +66,18 @@ impl TestData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn create_article(hostname: &str, title: String) -> MyResult<DbArticle> {
|
||||||
|
let create_form = CreateArticleData { title };
|
||||||
|
post(hostname, "article", &create_form).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_article(hostname: &str, title: &str) -> MyResult<DbArticle> {
|
||||||
|
let get_article = GetArticleData {
|
||||||
|
title: title.to_string(),
|
||||||
|
};
|
||||||
|
get_query::<DbArticle, _>(hostname, "article", Some(get_article.clone())).await
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn edit_article(
|
pub async fn edit_article(
|
||||||
hostname: &str,
|
hostname: &str,
|
||||||
title: &str,
|
title: &str,
|
||||||
|
@ -102,7 +116,7 @@ where
|
||||||
Ok(alpha_instance)
|
Ok(alpha_instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn post<T: Serialize, R>(hostname: &str, endpoint: &str, form: &T) -> MyResult<R>
|
async fn post<T: Serialize, R>(hostname: &str, endpoint: &str, form: &T) -> MyResult<R>
|
||||||
where
|
where
|
||||||
R: for<'de> Deserialize<'de>,
|
R: for<'de> Deserialize<'de>,
|
||||||
{
|
{
|
||||||
|
|
121
tests/test.rs
121
tests/test.rs
|
@ -2,9 +2,11 @@ extern crate fediwiki;
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
use crate::common::{edit_article, follow_instance, get_query, post, TestData};
|
use crate::common::{
|
||||||
|
create_article, edit_article, follow_instance, get_article, get_query, TestData,
|
||||||
|
};
|
||||||
use common::get;
|
use common::get;
|
||||||
use fediwiki::api::{CreateArticleData, EditArticleData, GetArticleData, ResolveObject};
|
use fediwiki::api::{EditArticleData, ResolveObject};
|
||||||
use fediwiki::error::MyResult;
|
use fediwiki::error::MyResult;
|
||||||
use fediwiki::federation::objects::article::DbArticle;
|
use fediwiki::federation::objects::article::DbArticle;
|
||||||
use fediwiki::federation::objects::instance::DbInstance;
|
use fediwiki::federation::objects::instance::DbInstance;
|
||||||
|
@ -17,33 +19,18 @@ async fn test_create_read_and_edit_article() -> MyResult<()> {
|
||||||
let data = TestData::start();
|
let data = TestData::start();
|
||||||
|
|
||||||
// error on nonexistent article
|
// error on nonexistent article
|
||||||
let get_article = GetArticleData {
|
let title = "Manu_Chao".to_string();
|
||||||
title: "Manu_Chao".to_string(),
|
let not_found = get_article(data.hostname_alpha, &title).await;
|
||||||
};
|
|
||||||
let not_found = get_query::<DbArticle, _>(
|
|
||||||
data.hostname_alpha,
|
|
||||||
&"article".to_string(),
|
|
||||||
Some(get_article.clone()),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
assert!(not_found.is_err());
|
assert!(not_found.is_err());
|
||||||
|
|
||||||
// create article
|
// create article
|
||||||
let create_article = CreateArticleData {
|
let create_res = create_article(data.hostname_alpha, title.clone()).await?;
|
||||||
title: get_article.title.to_string(),
|
assert_eq!(title, create_res.title);
|
||||||
};
|
|
||||||
let create_res: DbArticle = post(data.hostname_alpha, "article", &create_article).await?;
|
|
||||||
assert_eq!(create_article.title, create_res.title);
|
|
||||||
assert!(create_res.local);
|
assert!(create_res.local);
|
||||||
|
|
||||||
// now article can be read
|
// now article can be read
|
||||||
let get_res: DbArticle = get_query(
|
let get_res = get_article(data.hostname_alpha, &create_res.title).await?;
|
||||||
data.hostname_alpha,
|
assert_eq!(title, get_res.title);
|
||||||
&"article".to_string(),
|
|
||||||
Some(get_article.clone()),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
assert_eq!(create_article.title, get_res.title);
|
|
||||||
assert!(get_res.text.is_empty());
|
assert!(get_res.text.is_empty());
|
||||||
assert!(get_res.local);
|
assert!(get_res.local);
|
||||||
|
|
||||||
|
@ -88,24 +75,14 @@ async fn test_synchronize_articles() -> MyResult<()> {
|
||||||
let data = TestData::start();
|
let data = TestData::start();
|
||||||
|
|
||||||
// create article on alpha
|
// create article on alpha
|
||||||
let create_article = CreateArticleData {
|
let title = "Manu_Chao".to_string();
|
||||||
title: "Manu_Chao".to_string(),
|
let create_res = create_article(data.hostname_alpha, title.clone()).await?;
|
||||||
};
|
assert_eq!(title, create_res.title);
|
||||||
let create_res: DbArticle = post(data.hostname_alpha, "article", &create_article).await?;
|
|
||||||
assert_eq!(create_article.title, create_res.title);
|
|
||||||
assert_eq!(0, create_res.edits.len());
|
assert_eq!(0, create_res.edits.len());
|
||||||
assert!(create_res.local);
|
assert!(create_res.local);
|
||||||
|
|
||||||
// article is not yet on beta
|
// article is not yet on beta
|
||||||
let get_article = GetArticleData {
|
let get_res = get_article(data.hostname_beta, &create_res.title).await;
|
||||||
title: "Manu_Chao".to_string(),
|
|
||||||
};
|
|
||||||
let get_res = get_query::<DbArticle, _>(
|
|
||||||
data.hostname_beta,
|
|
||||||
&"article".to_string(),
|
|
||||||
Some(get_article.clone()),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
assert!(get_res.is_err());
|
assert!(get_res.is_err());
|
||||||
|
|
||||||
// fetch alpha instance on beta, articles are also fetched automatically
|
// fetch alpha instance on beta, articles are also fetched automatically
|
||||||
|
@ -116,14 +93,9 @@ async fn test_synchronize_articles() -> MyResult<()> {
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// get the article and compare
|
// get the article and compare
|
||||||
let get_res: DbArticle = get_query(
|
let get_res = get_article(data.hostname_beta, &create_res.title).await?;
|
||||||
data.hostname_beta,
|
|
||||||
&"article".to_string(),
|
|
||||||
Some(get_article.clone()),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
assert_eq!(create_res.ap_id, get_res.ap_id);
|
assert_eq!(create_res.ap_id, get_res.ap_id);
|
||||||
assert_eq!(create_article.title, get_res.title);
|
assert_eq!(title, get_res.title);
|
||||||
assert_eq!(0, get_res.edits.len());
|
assert_eq!(0, get_res.edits.len());
|
||||||
assert!(get_res.text.is_empty());
|
assert!(get_res.text.is_empty());
|
||||||
assert!(!get_res.local);
|
assert!(!get_res.local);
|
||||||
|
@ -139,20 +111,13 @@ async fn test_edit_local_article() -> MyResult<()> {
|
||||||
follow_instance(data.hostname_alpha, data.hostname_beta).await?;
|
follow_instance(data.hostname_alpha, data.hostname_beta).await?;
|
||||||
|
|
||||||
// create new article
|
// create new article
|
||||||
let create_form = CreateArticleData {
|
let title = "Manu_Chao".to_string();
|
||||||
title: "Manu_Chao".to_string(),
|
let create_res = create_article(data.hostname_beta, title.clone()).await?;
|
||||||
};
|
assert_eq!(title, create_res.title);
|
||||||
let create_res: DbArticle = post(data.hostname_beta, "article", &create_form).await?;
|
|
||||||
assert_eq!(create_res.title, create_form.title);
|
|
||||||
assert!(create_res.local);
|
assert!(create_res.local);
|
||||||
|
|
||||||
// article should be federated to alpha
|
// article should be federated to alpha
|
||||||
let get_article = GetArticleData {
|
let get_res = get_article(data.hostname_alpha, &create_res.title).await?;
|
||||||
title: create_res.title.clone(),
|
|
||||||
};
|
|
||||||
let get_res =
|
|
||||||
get_query::<DbArticle, _>(data.hostname_alpha, "article", Some(get_article.clone()))
|
|
||||||
.await?;
|
|
||||||
assert_eq!(create_res.title, get_res.title);
|
assert_eq!(create_res.title, get_res.title);
|
||||||
assert_eq!(0, get_res.edits.len());
|
assert_eq!(0, get_res.edits.len());
|
||||||
assert!(!get_res.local);
|
assert!(!get_res.local);
|
||||||
|
@ -172,12 +137,7 @@ async fn test_edit_local_article() -> MyResult<()> {
|
||||||
.starts_with(&edit_res.ap_id.to_string()));
|
.starts_with(&edit_res.ap_id.to_string()));
|
||||||
|
|
||||||
// edit should be federated to alpha
|
// edit should be federated to alpha
|
||||||
let get_article = GetArticleData {
|
let get_res = get_article(data.hostname_alpha, &edit_res.title).await?;
|
||||||
title: edit_res.title.clone(),
|
|
||||||
};
|
|
||||||
let get_res =
|
|
||||||
get_query::<DbArticle, _>(data.hostname_alpha, "article", Some(get_article.clone()))
|
|
||||||
.await?;
|
|
||||||
assert_eq!(edit_res.title, get_res.title);
|
assert_eq!(edit_res.title, get_res.title);
|
||||||
assert_eq!(edit_res.edits.len(), 1);
|
assert_eq!(edit_res.edits.len(), 1);
|
||||||
assert_eq!(edit_res.text, get_res.text);
|
assert_eq!(edit_res.text, get_res.text);
|
||||||
|
@ -194,27 +154,18 @@ async fn test_edit_remote_article() -> MyResult<()> {
|
||||||
follow_instance(data.hostname_gamma, data.hostname_beta).await?;
|
follow_instance(data.hostname_gamma, data.hostname_beta).await?;
|
||||||
|
|
||||||
// create new article
|
// create new article
|
||||||
let create_form = CreateArticleData {
|
let title = "Manu_Chao".to_string();
|
||||||
title: "Manu_Chao".to_string(),
|
let create_res = create_article(data.hostname_beta, title.clone()).await?;
|
||||||
};
|
assert_eq!(title, create_res.title);
|
||||||
let create_res: DbArticle = post(data.hostname_beta, "article", &create_form).await?;
|
|
||||||
assert_eq!(create_res.title, create_form.title);
|
|
||||||
assert!(create_res.local);
|
assert!(create_res.local);
|
||||||
|
|
||||||
// article should be federated to alpha and gamma
|
// article should be federated to alpha and gamma
|
||||||
let get_article = GetArticleData {
|
let get_res = get_article(data.hostname_alpha, &title).await?;
|
||||||
title: create_res.title.clone(),
|
|
||||||
};
|
|
||||||
let get_res =
|
|
||||||
get_query::<DbArticle, _>(data.hostname_alpha, "article", Some(get_article.clone()))
|
|
||||||
.await?;
|
|
||||||
assert_eq!(create_res.title, get_res.title);
|
assert_eq!(create_res.title, get_res.title);
|
||||||
assert_eq!(0, get_res.edits.len());
|
assert_eq!(0, get_res.edits.len());
|
||||||
assert!(!get_res.local);
|
assert!(!get_res.local);
|
||||||
|
|
||||||
let get_res =
|
let get_res = get_article(data.hostname_gamma, &title).await?;
|
||||||
get_query::<DbArticle, _>(data.hostname_gamma, "article", Some(get_article.clone()))
|
|
||||||
.await?;
|
|
||||||
assert_eq!(create_res.title, get_res.title);
|
assert_eq!(create_res.title, get_res.title);
|
||||||
assert_eq!(create_res.text, get_res.text);
|
assert_eq!(create_res.text, get_res.text);
|
||||||
|
|
||||||
|
@ -222,7 +173,7 @@ async fn test_edit_remote_article() -> MyResult<()> {
|
||||||
ap_id: create_res.ap_id,
|
ap_id: create_res.ap_id,
|
||||||
new_text: "Lorem Ipsum 2".to_string(),
|
new_text: "Lorem Ipsum 2".to_string(),
|
||||||
};
|
};
|
||||||
let edit_res = edit_article(data.hostname_alpha, &create_res.title, &edit_form).await?;
|
let edit_res = edit_article(data.hostname_alpha, &title, &edit_form).await?;
|
||||||
assert_eq!(edit_res.text, edit_form.new_text);
|
assert_eq!(edit_res.text, edit_form.new_text);
|
||||||
assert_eq!(edit_res.edits.len(), 1);
|
assert_eq!(edit_res.edits.len(), 1);
|
||||||
assert!(!edit_res.local);
|
assert!(!edit_res.local);
|
||||||
|
@ -232,18 +183,12 @@ async fn test_edit_remote_article() -> MyResult<()> {
|
||||||
.starts_with(&edit_res.ap_id.to_string()));
|
.starts_with(&edit_res.ap_id.to_string()));
|
||||||
|
|
||||||
// edit should be federated to beta and gamma
|
// edit should be federated to beta and gamma
|
||||||
let get_article = GetArticleData {
|
let get_res = get_article(data.hostname_alpha, &title).await?;
|
||||||
title: edit_res.title.clone(),
|
|
||||||
};
|
|
||||||
let get_res =
|
|
||||||
get_query::<DbArticle, _>(data.hostname_beta, "article", Some(get_article.clone())).await?;
|
|
||||||
assert_eq!(edit_res.title, get_res.title);
|
assert_eq!(edit_res.title, get_res.title);
|
||||||
assert_eq!(edit_res.edits.len(), 1);
|
assert_eq!(edit_res.edits.len(), 1);
|
||||||
assert_eq!(edit_res.text, get_res.text);
|
assert_eq!(edit_res.text, get_res.text);
|
||||||
|
|
||||||
let get_res =
|
let get_res = get_article(data.hostname_gamma, &title).await?;
|
||||||
get_query::<DbArticle, _>(data.hostname_gamma, "article", Some(get_article.clone()))
|
|
||||||
.await?;
|
|
||||||
assert_eq!(edit_res.title, get_res.title);
|
assert_eq!(edit_res.title, get_res.title);
|
||||||
assert_eq!(edit_res.edits.len(), 1);
|
assert_eq!(edit_res.edits.len(), 1);
|
||||||
assert_eq!(edit_res.text, get_res.text);
|
assert_eq!(edit_res.text, get_res.text);
|
||||||
|
@ -259,11 +204,9 @@ async fn test_edit_conflict() -> MyResult<()> {
|
||||||
follow_instance(data.hostname_alpha, data.hostname_beta).await?;
|
follow_instance(data.hostname_alpha, data.hostname_beta).await?;
|
||||||
|
|
||||||
// create new article
|
// create new article
|
||||||
let create_form = CreateArticleData {
|
let title = "Manu_Chao".to_string();
|
||||||
title: "Manu_Chao".to_string(),
|
let create_res = create_article(data.hostname_beta, title.clone()).await?;
|
||||||
};
|
assert_eq!(title, create_res.title);
|
||||||
let create_res: DbArticle = post(data.hostname_beta, "article", &create_form).await?;
|
|
||||||
assert_eq!(create_res.title, create_form.title);
|
|
||||||
assert!(create_res.local);
|
assert!(create_res.local);
|
||||||
|
|
||||||
// fetch article to gamma
|
// fetch article to gamma
|
||||||
|
|
Loading…
Reference in a new issue