Skip to content

Commit f11af63

Browse files
committed
og_image: Add JPEG/WebP avatars to increase test coverage
1 parent c99c21e commit f11af63

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

crates/crates_io_og_image/src/lib.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -602,14 +602,30 @@ mod tests {
602602
async fn create_mock_avatar_server() -> ServerGuard {
603603
let mut server = Server::new_async().await;
604604

605-
// Mock for successful avatar download
605+
// Mock for successful PNG avatar download
606606
server
607607
.mock("GET", "/test-avatar.png")
608608
.with_status(200)
609609
.with_header("content-type", "image/png")
610610
.with_body(include_bytes!("../template/assets/test-avatar.png"))
611611
.create();
612612

613+
// Mock for JPEG avatar download
614+
server
615+
.mock("GET", "/test-avatar.jpg")
616+
.with_status(200)
617+
.with_header("content-type", "image/jpeg")
618+
.with_body(include_bytes!("../template/assets/test-avatar.jpg"))
619+
.create();
620+
621+
// Mock for unsupported file type (WebP)
622+
server
623+
.mock("GET", "/test-avatar.webp")
624+
.with_status(200)
625+
.with_header("content-type", "image/webp")
626+
.with_body(include_bytes!("../template/assets/test-avatar.webp"))
627+
.create();
628+
613629
// Mock for 404 avatar download
614630
server
615631
.mock("GET", "/missing-avatar.png")
@@ -677,16 +693,21 @@ mod tests {
677693
}
678694

679695
fn create_overflow_authors(server_url: &str) -> Vec<OgImageAuthorData<'_>> {
680-
let avatar_url = format!("{server_url}/test-avatar.png");
681696
vec![
682-
author_with_avatar("alice-wonderland", avatar_url.clone()),
697+
author_with_avatar("alice-wonderland", format!("{server_url}/test-avatar.png")),
683698
author("bob-the-builder"),
684-
author_with_avatar("charlie-brown", avatar_url.clone()),
699+
author_with_avatar("charlie-brown", format!("{server_url}/test-avatar.jpg")),
685700
author("diana-prince"),
686-
author_with_avatar("edward-scissorhands", avatar_url.clone()),
701+
author_with_avatar(
702+
"edward-scissorhands",
703+
format!("{server_url}/test-avatar.png"),
704+
),
687705
author("fiona-apple"),
688-
author("george-washington"),
689-
author_with_avatar("helen-keller", avatar_url.clone()),
706+
author_with_avatar(
707+
"george-washington",
708+
format!("{server_url}/test-avatar.webp"),
709+
),
710+
author_with_avatar("helen-keller", format!("{server_url}/test-avatar.jpg")),
690711
author("isaac-newton"),
691712
author("jane-doe"),
692713
]
Loading
Binary file not shown.

0 commit comments

Comments
 (0)