Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename test modules #19

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ entity = { path = "entity" }
migration = { path = "migration" }

[dev-dependencies]
mockall = "0.11.3"
rstest = "0.16.0"
20 changes: 10 additions & 10 deletions src/controllers/api/animes/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter};
use serde::{Deserialize, Serialize};

use crate::app_state::AppState;
use crate::types::animes::{StrictAnime, StrictAnimes};
use crate::types::animes::{Anime, Animes};
use entity::anime::{Column as AnimeColumn, Entity as AnimeEntity};

#[derive(Debug, Deserialize, Serialize)]
pub struct ResponseBody {
pub animes: StrictAnimes,
pub animes: Animes,
}

#[derive(Debug, Deserialize, Serialize)]
struct ErrorResponseBody {
reason: String,
successful_animes: StrictAnimes,
failed_anime: StrictAnime,
successful_animes: Animes,
failed_anime: Anime,
}

#[derive(Debug, Deserialize, Serialize)]
Expand All @@ -27,7 +27,7 @@ pub struct PathParams {

#[derive(Debug, Deserialize, Serialize)]
pub struct BodyParams {
animes: StrictAnimes,
animes: Animes,
}

type AppData = web::Data<AppState>;
Expand All @@ -40,7 +40,7 @@ pub async fn get(data: AppData) -> impl Responder {
return HttpResponse::InternalServerError().finish();
}

let mut animes = StrictAnime::new_by_models(found_animes.unwrap());
let mut animes = Anime::new_by_models(found_animes.unwrap());
animes.sort();
return HttpResponse::Ok().json(ResponseBody { animes });
}
Expand All @@ -56,7 +56,7 @@ pub async fn get_by_year(data: AppData, path_params: web::Path<PathParams>) -> i
return HttpResponse::InternalServerError().finish();
}

let mut animes = StrictAnime::new_by_models(found_animes.unwrap());
let mut animes = Anime::new_by_models(found_animes.unwrap());
animes.sort();
return HttpResponse::Ok().json(ResponseBody { animes });
}
Expand All @@ -73,7 +73,7 @@ pub async fn get_by_season(data: AppData, path_params: web::Path<PathParams>) ->
return HttpResponse::InternalServerError().finish();
}

let mut animes = StrictAnime::new_by_models(found_animes.unwrap());
let mut animes = Anime::new_by_models(found_animes.unwrap());
animes.sort();
return HttpResponse::Ok().json(ResponseBody { animes });
}
Expand All @@ -82,7 +82,7 @@ pub async fn post(data: AppData, body_params: web::Json<BodyParams>) -> impl Res
let new_animes = &body_params.animes;
info!("Try to insert animes: {:?}", new_animes);

let target_option_animes = StrictAnime::to_active_models(new_animes.clone());
let target_option_animes = Anime::to_active_models(new_animes.clone());
let include_none = target_option_animes
.clone()
.into_iter()
Expand Down Expand Up @@ -140,7 +140,7 @@ pub async fn put(data: AppData, body_params: web::Json<BodyParams>) -> impl Resp
}

info!("Succeeded to update an anime: {:?}", anime);
updated_animes.push(StrictAnime::new_by_model(updated_anime.unwrap()));
updated_animes.push(Anime::new_by_model(updated_anime.unwrap()));
}

return HttpResponse::Ok().json(ResponseBody {
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/api/animes/scrape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use log::debug;
use serde::{Deserialize, Serialize};

use crate::service::anime_scraper::fetch;
use crate::types::animes::StrictAnimes;
use crate::types::animes::Animes;
use crate::types::season::Season;

#[derive(Debug, Deserialize, Serialize)]
Expand All @@ -13,7 +13,7 @@ pub struct PathParams {

#[derive(Debug, Deserialize, Serialize)]
pub struct ResponseBody {
animes: StrictAnimes,
animes: Animes,
}

pub async fn get(path_params: web::Path<PathParams>) -> impl Responder {
Expand Down
8 changes: 4 additions & 4 deletions src/service/anime_scraper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use log::{debug, info};
use scraper::element_ref::ElementRef;
use scraper::{Html, Selector};

use crate::types::animes::{Detail, StrictAnime, StrictAnimes};
use crate::types::animes::{Anime, Animes, Detail};
use crate::types::season::Season;
use crate::types::wday::WDay;

const BASE_URL: &str = "https://akiba-souken.com/anime/";

pub async fn fetch(season: Season) -> StrictAnimes {
pub async fn fetch(season: Season) -> Animes {
let url = mk_url(&season);
if url.is_none() {
return vec![];
Expand All @@ -34,8 +34,8 @@ pub async fn fetch(season: Season) -> StrictAnimes {

let animes = anime_items
.into_iter()
.map(|i| StrictAnime::new(parse_title(&i), year, season.clone(), parse_detail(&i)))
.collect::<StrictAnimes>();
.map(|i| Anime::new(parse_title(&i), year, season.clone(), parse_detail(&i)))
.collect::<Animes>();
info!("fetch animes = {:?}", animes);

return animes;
Expand Down
14 changes: 7 additions & 7 deletions src/types/animes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::types::wday::WDay;
use entity::anime::{ActiveModel as AnimeActiveModel, Model as AnimeModel};

#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
pub struct StrictAnime {
pub struct Anime {
pub id: Option<i32>,
pub year: Option<i32>,
pub season: Option<Season>,
Expand All @@ -20,9 +20,9 @@ pub struct StrictAnime {
pub recommend: Option<bool>,
}

pub type StrictAnimes = Vec<StrictAnime>;
pub type Animes = Vec<Anime>;

impl StrictAnime {
impl Anime {
pub fn new(title: String, year: i32, season: Season, detail: Detail) -> Self {
return Self {
id: None,
Expand All @@ -49,8 +49,8 @@ impl StrictAnime {
};
}

pub fn new_by_models(animes: Vec<AnimeModel>) -> StrictAnimes {
return animes.into_iter().map(StrictAnime::new_by_model).collect();
pub fn new_by_models(animes: Vec<AnimeModel>) -> Animes {
return animes.into_iter().map(Anime::new_by_model).collect();
}

pub fn to_active_model(self) -> Option<AnimeActiveModel> {
Expand Down Expand Up @@ -83,13 +83,13 @@ impl StrictAnime {
}
}

impl PartialOrd for StrictAnime {
impl PartialOrd for Anime {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
return Some(self.cmp(other));
}
}

impl Ord for StrictAnime {
impl Ord for Anime {
fn cmp(&self, other: &Self) -> Ordering {
if self.year != other.year {
return self.year.cmp(&other.year);
Expand Down
2 changes: 1 addition & 1 deletion tests/controllers/api/animes/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod index;
pub mod index_test;
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/controllers/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod animes;
pub mod echo;
pub mod index;
pub mod echo_test;
pub mod index_test;
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/controllers/auth/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod logout;
pub mod logout_test;
2 changes: 1 addition & 1 deletion tests/controllers/health_check/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod index;
pub mod index_test;