57 lines
2.1 KiB
Rust
57 lines
2.1 KiB
Rust
use pokedex_api::{
|
|
clients::{funtranslations::TranslationClient, pokeapi::PokeApiClient},
|
|
domain::TranslationKind,
|
|
};
|
|
use std::time::Duration;
|
|
|
|
const POKEAPI_BASE_URL: &str = "https://pokeapi.co/api/v2";
|
|
const FUN_TRANSLATIONS_BASE_URL: &str = "https://api.funtranslations.mercxry.me/v1";
|
|
const CONTRACT_TIMEOUT: Duration = Duration::from_secs(10);
|
|
|
|
#[tokio::test]
|
|
#[ignore = "nightly external contract test: calls the real PokéAPI"]
|
|
async fn pokeapi_species_contract_still_matches_what_we_parse() {
|
|
let client =
|
|
PokeApiClient::new(POKEAPI_BASE_URL, CONTRACT_TIMEOUT).expect("client should build");
|
|
|
|
let pokemon = client
|
|
.get_pokemon_info("mewtwo")
|
|
.await
|
|
.expect("PokéAPI species contract should still parse");
|
|
|
|
assert_eq!(pokemon.name, "mewtwo");
|
|
assert_eq!(pokemon.habitat, "rare");
|
|
assert!(pokemon.is_legendary);
|
|
assert!(!pokemon.description.trim().is_empty());
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[ignore = "nightly external contract test: calls the real FunTranslations API"]
|
|
async fn funtranslations_yoda_contract_still_matches_what_we_parse() {
|
|
let client = TranslationClient::new(FUN_TRANSLATIONS_BASE_URL, CONTRACT_TIMEOUT)
|
|
.expect("client should build");
|
|
|
|
let translated = client
|
|
.translate(TranslationKind::Yoda, "It was created by science.")
|
|
.await
|
|
.expect("FunTranslations Yoda contract should still parse");
|
|
|
|
assert!(!translated.trim().is_empty());
|
|
assert_ne!(translated, "It was created by science.");
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[ignore = "nightly external contract test: calls the real FunTranslations API"]
|
|
async fn funtranslations_shakespeare_contract_still_matches_what_we_parse() {
|
|
let client = TranslationClient::new(FUN_TRANSLATIONS_BASE_URL, CONTRACT_TIMEOUT)
|
|
.expect("client should build");
|
|
|
|
let translated = client
|
|
.translate(TranslationKind::Shakespeare, "You have a great friend.")
|
|
.await
|
|
.expect("FunTranslations Shakespeare contract should still parse");
|
|
|
|
assert!(!translated.trim().is_empty());
|
|
assert_ne!(translated, "You have a great friend.");
|
|
}
|