Skip to content

Commit ccf0365

Browse files
committed
test(fetcher/deal/free_games): cover Platform's config_value tokens and url_slug codes for all nine storefronts, feed_url slug embedding for every non-aggregate platform, and parse_platform/parse_kind case-insensitive matching of every known storefront and the explicit game keyword
1 parent 9b98aa6 commit ccf0365

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

‎src/fetcher/deal/free_games.rs‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,4 +598,66 @@ mod tests {
598598
assert!(row.store.is_none());
599599
assert_eq!(row.title, "just a title");
600600
}
601+
602+
const ALL_PLATFORMS: [Platform; 9] = [
603+
Platform::All,
604+
Platform::Epic,
605+
Platform::Steam,
606+
Platform::Amazon,
607+
Platform::Gog,
608+
Platform::Humble,
609+
Platform::Itch,
610+
Platform::Apple,
611+
Platform::Google,
612+
];
613+
614+
#[test]
615+
fn config_value_is_a_distinct_lowercase_token_for_every_platform() {
616+
let tokens: Vec<&str> = ALL_PLATFORMS.iter().map(|p| p.config_value()).collect();
617+
assert_eq!(
618+
tokens,
619+
[
620+
"all", "epic", "steam", "amazon", "gog", "humble", "itch", "apple", "google"
621+
]
622+
);
623+
}
624+
625+
#[test]
626+
fn url_slug_blanks_the_aggregate_feed_and_codes_every_storefront() {
627+
assert_eq!(Platform::All.url_slug(), "");
628+
let coded: Vec<&str> = ALL_PLATFORMS.iter().skip(1).map(|p| p.url_slug()).collect();
629+
assert_eq!(
630+
coded,
631+
[
632+
"epic", "steam", "amazon", "gog", "humble", "itch", "apple", "google"
633+
]
634+
);
635+
}
636+
637+
#[test]
638+
fn feed_url_for_every_non_aggregate_platform_embeds_its_slug() {
639+
for platform in ALL_PLATFORMS.iter().skip(1).copied() {
640+
let url = platform.feed_url(Kind::Game);
641+
assert_eq!(
642+
url,
643+
format!("{FEED_BASE}/lootscraper_{}_game.xml", platform.url_slug())
644+
);
645+
}
646+
}
647+
648+
#[test]
649+
fn parse_platform_accepts_every_known_storefront() {
650+
for platform in ALL_PLATFORMS {
651+
let parsed = parse_platform(Some(platform.config_value())).unwrap();
652+
assert_eq!(parsed, platform);
653+
}
654+
// The matcher lowercases first, so a mixed-case storefront still resolves.
655+
assert_eq!(parse_platform(Some("GoG")).unwrap(), Platform::Gog);
656+
}
657+
658+
#[test]
659+
fn parse_kind_accepts_the_explicit_game_keyword() {
660+
assert_eq!(parse_kind(Some("game")).unwrap(), Kind::Game);
661+
assert_eq!(parse_kind(Some(" GAME ")).unwrap(), Kind::Game);
662+
}
601663
}

0 commit comments

Comments
 (0)