use crate::tests::test_client::testwp_client;
use crate::{Error, Result};
#[tokio::test]
async fn test_get() -> Result<()> {
let client = testwp_client();
let html = client.get_raw("Main Page").await?;
assert!(html.contains("wmf-config/InitialiseSettings.php"));
match client.get("ThisPageDoesNotExist").await {
Err(Error::PageDoesNotExist(title)) => {
assert_eq!("ThisPageDoesNotExist".to_string(), title);
}
_ => {
panic!("Test did not fail with Error::PageDoesNotExist()");
}
}
Ok(())
}
#[tokio::test]
async fn test_get_revision() -> Result<()> {
let client = testwp_client();
let code = client.get_revision("Main Page", 1).await?.into_mutable();
assert!(code.text_contents().contains(
"This subdomain is reserved for the creation of a Wikipedia"
));
assert_eq!(code.revision_id(), Some(1));
Ok(())
}
#[tokio::test]
async fn test_get_redirect() -> Result<()> {
let client = testwp_client();
let code = client.get("Mwbot-rs/Redirect").await?.into_mutable();
let redirect = code.redirect();
assert!(redirect.is_some());
assert_eq!(&redirect.unwrap().target(), "Main Page");
Ok(())
}
#[tokio::test]
async fn test_transform_to_html() -> Result<()> {
let client = testwp_client();
let html = client
.transform_to_html_raw("{{1x|This is HTML now}}")
.await?;
assert!(html.contains("This is HTML now"));
Ok(())
}
#[tokio::test]
async fn test_transform_to_wikitext() -> Result<()> {
let client = testwp_client();
let wikitext = client
.transform_to_wikitext_raw(
"<a rel=\"mw:WikiLink\" href=\"./Foo\">Foo bar</a>",
None,
None,
None,
)
.await?;
assert_eq!(wikitext, "[[Foo|Foo bar]]".to_string());
Ok(())
}
#[tokio::test]
async fn test_immutable() -> Result<()> {
let client = testwp_client();
let code = client.get("Main Page").await?;
let wikitext = client.transform_to_wikitext(&code).await?;
assert!(wikitext.contains("Wikipedia"));
Ok(())
}