Skip to content

Commit

Permalink
chore(tests): fix transformations build parse
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Jan 11, 2025
1 parent 8e9812f commit ff770ce
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
15 changes: 15 additions & 0 deletions spider/src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,21 @@ fn get_error_status(
get_error_status_base(should_retry, error_for_status).map(std::sync::Arc::new)
}


/// Instantiate a new page without scraping it and with the base URL parsed (used for testing purposes).
#[cfg(not(feature = "decentralized"))]
pub fn build_with_parse(url: &str, res: PageResponse) -> Page {
let mut page = build(url, res);
page.set_url_parsed_direct_empty();
page
}

/// Instantiate a new page without scraping it and with the base URL parsed (used for testing purposes).
#[cfg(feature = "decentralized")]
pub fn build_with_parse(url: &str, res: PageResponse) -> Page {
build(url, res)
}

/// Instantiate a new page without scraping it (used for testing purposes).
#[cfg(not(feature = "decentralized"))]
pub fn build(url: &str, res: PageResponse) -> Page {
Expand Down
16 changes: 8 additions & 8 deletions spider_transformations/src/transformation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod tests {
use maud::PreEscaped;
use spider::{
bytes::Bytes,
page::build,
page::build_with_parse,
tokio::{self, fs::File},
utils::PageResponse,
};
Expand Down Expand Up @@ -51,7 +51,7 @@ mod tests {
let mut page_response = PageResponse::default();

page_response.content = Some(Bytes::from(markup).into());
let page = build(url, page_response);
let page = build_with_parse(url, page_response);

conf.return_format = ReturnFormat::Markdown;

Expand Down Expand Up @@ -111,7 +111,7 @@ mod tests {
let mut page_response = PageResponse::default();
conf.return_format = ReturnFormat::XML;
page_response.content = Some(Bytes::from(markup).into());
let page = build(url, page_response);
let page = build_with_parse(url, page_response);
let content = content::transform_content(&page, &conf, &None, &None, &None);
assert!(
content
Expand All @@ -129,7 +129,7 @@ mod tests {
let mut page_response = PageResponse::default();

page_response.content = Some(Bytes::from(markup).into());
let page = build(url, page_response);
let page = build_with_parse(url, page_response);

conf.return_format = ReturnFormat::Markdown;

Expand All @@ -154,7 +154,7 @@ mod tests {
let mut page_response = PageResponse::default();

page_response.content = Some(Bytes::from(markup).into());
let page = build(url, page_response);
let page = build_with_parse(url, page_response);

conf.return_format = ReturnFormat::Markdown;

Expand All @@ -179,7 +179,7 @@ mod tests {
let mut page_response = PageResponse::default();

page_response.content = Some(Bytes::from(markup).into());
let page = build(url, page_response);
let page = build_with_parse(url, page_response);

conf.return_format = ReturnFormat::Text;

Expand All @@ -204,7 +204,7 @@ mod tests {
let mut page_response = PageResponse::default();

page_response.content = Some(Bytes::from(markup).into());
let page = build(url, page_response);
let page = build_with_parse(url, page_response);

conf.return_format = ReturnFormat::Text;

Expand Down Expand Up @@ -236,7 +236,7 @@ mod tests {

page_response.content = Some(b.into());

let page = build("https://example.com/example.pdf", page_response);
let page = build_with_parse("https://example.com/example.pdf", page_response);

let content = content::transform_content(&page, &conf, &None, &None, &None);

Expand Down

0 comments on commit ff770ce

Please sign in to comment.