fix: fix tests for temp
This commit is contained in:
@@ -14,32 +14,30 @@ path = "src/bin/main.rs"
|
||||
required-features = []
|
||||
|
||||
[dependencies]
|
||||
loco-rs = { version = "0.13.2" }
|
||||
loco-rs = { version = "0.13" }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
eyre = "0.6"
|
||||
tokio = { version = "1.42", default-features = false }
|
||||
async-trait = "0.1.83"
|
||||
tracing = "0.1.41"
|
||||
tracing = "0.1"
|
||||
chrono = "0.4"
|
||||
validator = { version = "0.19" }
|
||||
sea-orm = { version = "1.1.3", features = [
|
||||
sea-orm = { version = "1", features = [
|
||||
"sqlx-sqlite",
|
||||
"sqlx-postgres",
|
||||
"runtime-tokio-rustls",
|
||||
"macros",
|
||||
"debug-print"
|
||||
] }
|
||||
|
||||
axum = "0.7.9"
|
||||
include_dir = "0.7"
|
||||
uuid = { version = "1.6.0", features = ["v4"] }
|
||||
tracing-subscriber = { version = "0.3.19", features = ["env-filter", "json"] }
|
||||
sea-orm-migration = { version = "1.1.3", features = ["runtime-tokio-rustls"] }
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
|
||||
sea-orm-migration = { version = "1", features = ["runtime-tokio-rustls"] }
|
||||
reqwest = "0.12.9"
|
||||
thiserror = "2"
|
||||
rss = "2"
|
||||
bytes = "1.9"
|
||||
futures = "0.3.31"
|
||||
itertools = "0.13.0"
|
||||
url = "2.5"
|
||||
fancy-regex = "0.14"
|
||||
@@ -62,8 +60,5 @@ serde_with = "3"
|
||||
|
||||
[dev-dependencies]
|
||||
serial_test = "3"
|
||||
rstest = "0.23.0"
|
||||
loco-rs = { version = "0.13.2", features = ["testing"] }
|
||||
loco-rs = { version = "0.13", features = ["testing"] }
|
||||
insta = { version = "1", features = ["redactions", "yaml", "filters"] }
|
||||
testcontainers = { version = "0.23.1" }
|
||||
testcontainers-modules = { version = "0.11.4" }
|
||||
|
||||
@@ -19,7 +19,10 @@ use recorder::{
|
||||
use sea_orm_migration::MigratorTrait;
|
||||
|
||||
async fn pull_mikan_bangumi_rss(ctx: &AppContext) -> eyre::Result<()> {
|
||||
let rss_link = "https://mikanani.me/RSS/Bangumi?bangumiId=3416&subgroupid=370";
|
||||
// let rss_link = "https://mikanani.me/RSS/Bangumi?bangumiId=3416&subgroupid=370";
|
||||
|
||||
let rss_link =
|
||||
"https://mikanani.me/RSS/MyBangumi?token=FE9tccsML2nBPUUqpCuJW2uJZydAXCntHJ7RpD9LDP8%3d";
|
||||
let subscription = if let Some(subscription) = subscriptions::Entity::find()
|
||||
.filter(subscriptions::Column::SourceUrl.eq(String::from(rss_link)))
|
||||
.one(&ctx.db)
|
||||
@@ -45,6 +48,10 @@ async fn pull_mikan_bangumi_rss(ctx: &AppContext) -> eyre::Result<()> {
|
||||
}
|
||||
|
||||
async fn init() -> eyre::Result<AppContext> {
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(tracing::Level::DEBUG)
|
||||
.with_test_writer()
|
||||
.init();
|
||||
let ctx = loco_rs::cli::playground::<App>().await?;
|
||||
let BootResult {
|
||||
app_context: ctx, ..
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#![feature(duration_constructors, assert_matches)]
|
||||
#![feature(duration_constructors, assert_matches, unboxed_closures)]
|
||||
|
||||
pub mod app;
|
||||
pub mod config;
|
||||
|
||||
@@ -39,6 +39,7 @@ pub enum Bangumi {
|
||||
MikanBangumiId,
|
||||
DisplayName,
|
||||
SubscriptionId,
|
||||
SubscriberId,
|
||||
RawName,
|
||||
Season,
|
||||
SeasonRaw,
|
||||
@@ -62,6 +63,7 @@ pub enum Episodes {
|
||||
DisplayName,
|
||||
BangumiId,
|
||||
SubscriptionId,
|
||||
SubscriberId,
|
||||
DownloadId,
|
||||
SavePath,
|
||||
Resolution,
|
||||
|
||||
@@ -90,6 +90,7 @@ impl MigrationTrait for Migration {
|
||||
.col(pk_auto(Bangumi::Id))
|
||||
.col(text_null(Bangumi::MikanBangumiId))
|
||||
.col(integer(Bangumi::SubscriptionId))
|
||||
.col(integer(Bangumi::SubscriberId))
|
||||
.col(text(Bangumi::DisplayName))
|
||||
.col(text(Bangumi::RawName))
|
||||
.col(integer(Bangumi::Season))
|
||||
@@ -111,6 +112,14 @@ impl MigrationTrait for Migration {
|
||||
.on_update(ForeignKeyAction::Restrict)
|
||||
.on_delete(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_bangumi_subscriber_id")
|
||||
.from(Bangumi::Table, Bangumi::SubscriberId)
|
||||
.to(Subscribers::Table, Subscribers::Id)
|
||||
.on_update(ForeignKeyAction::Restrict)
|
||||
.on_delete(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
@@ -150,6 +159,7 @@ impl MigrationTrait for Migration {
|
||||
.col(text(Episodes::DisplayName))
|
||||
.col(integer(Episodes::BangumiId))
|
||||
.col(integer(Episodes::SubscriptionId))
|
||||
.col(integer(Episodes::SubscriberId))
|
||||
.col(text_null(Episodes::SavePath))
|
||||
.col(text_null(Episodes::Resolution))
|
||||
.col(integer(Episodes::Season))
|
||||
@@ -178,6 +188,14 @@ impl MigrationTrait for Migration {
|
||||
.on_update(ForeignKeyAction::Restrict)
|
||||
.on_delete(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_episodes_subscriber_id")
|
||||
.from(Episodes::Table, Episodes::SubscriberId)
|
||||
.to(Subscribers::Table, Subscribers::Id)
|
||||
.on_update(ForeignKeyAction::Restrict)
|
||||
.on_delete(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -6,6 +6,7 @@ pub use super::entities::bangumi::*;
|
||||
impl Model {
|
||||
pub async fn get_or_insert_from_mikan<F>(
|
||||
ctx: &AppContext,
|
||||
subscriber_id: i32,
|
||||
subscription_id: i32,
|
||||
mikan_bangumi_id: String,
|
||||
mikan_fansub_id: String,
|
||||
@@ -30,6 +31,7 @@ impl Model {
|
||||
mikan_bangumi_id: ActiveValue::Set(Some(mikan_bangumi_id)),
|
||||
mikan_fansub_id: ActiveValue::Set(Some(mikan_fansub_id)),
|
||||
subscription_id: ActiveValue::Set(subscription_id),
|
||||
subscriber_id: ActiveValue::Set(subscriber_id),
|
||||
..Default::default()
|
||||
};
|
||||
f(&mut bgm).await?;
|
||||
|
||||
@@ -26,6 +26,7 @@ pub struct Model {
|
||||
pub id: i32,
|
||||
pub mikan_bangumi_id: Option<String>,
|
||||
pub subscription_id: i32,
|
||||
pub subscriber_id: i32,
|
||||
pub display_name: String,
|
||||
pub raw_name: String,
|
||||
pub season: i32,
|
||||
@@ -50,6 +51,12 @@ pub enum Relation {
|
||||
to = "super::subscriptions::Column::Id"
|
||||
)]
|
||||
Subscription,
|
||||
#[sea_orm(
|
||||
belongs_to = "super::subscribers::Entity",
|
||||
from = "Column::SubscriberId",
|
||||
to = "super::subscribers::Column::Id"
|
||||
)]
|
||||
Subscriber,
|
||||
#[sea_orm(has_many = "super::episodes::Entity")]
|
||||
Episode,
|
||||
}
|
||||
@@ -65,3 +72,9 @@ impl Related<super::subscriptions::Entity> for Entity {
|
||||
Relation::Subscription.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::subscribers::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Subscriber.def()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ pub struct Model {
|
||||
pub display_name: String,
|
||||
pub bangumi_id: i32,
|
||||
pub subscription_id: i32,
|
||||
pub subscriber_id: i32,
|
||||
pub download_id: Option<i32>,
|
||||
pub save_path: Option<String>,
|
||||
pub resolution: Option<String>,
|
||||
@@ -61,6 +62,12 @@ pub enum Relation {
|
||||
to = "super::subscriptions::Column::Id"
|
||||
)]
|
||||
Subscriptions,
|
||||
#[sea_orm(
|
||||
belongs_to = "super::subscribers::Entity",
|
||||
from = "Column::SubscriberId",
|
||||
to = "super::subscribers::Column::Id"
|
||||
)]
|
||||
Subscriber,
|
||||
}
|
||||
|
||||
impl Related<super::bangumi::Entity> for Entity {
|
||||
@@ -80,3 +87,9 @@ impl Related<super::subscriptions::Entity> for Entity {
|
||||
Relation::Subscriptions.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::subscribers::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Subscriber.def()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,10 @@ pub enum Relation {
|
||||
to = "super::downloaders::Column::Id"
|
||||
)]
|
||||
Downloader,
|
||||
#[sea_orm(has_many = "super::bangumi::Entity")]
|
||||
Bangumi,
|
||||
#[sea_orm(has_many = "super::episodes::Entity")]
|
||||
Episode,
|
||||
}
|
||||
|
||||
impl Related<super::subscriptions::Entity> for Entity {
|
||||
@@ -45,3 +49,15 @@ impl Related<super::downloaders::Entity> for Entity {
|
||||
Relation::Downloader.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::bangumi::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Bangumi.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::episodes::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Episode.def()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ impl Model {
|
||||
.do_nothing()
|
||||
.to_owned(),
|
||||
)
|
||||
.on_empty_do_nothing()
|
||||
.exec(db)
|
||||
.await?;
|
||||
|
||||
@@ -61,6 +62,7 @@ impl ActiveModel {
|
||||
display_name: ActiveValue::Set(item.episode_title.clone()),
|
||||
bangumi_id: ActiveValue::Set(bgm.id),
|
||||
subscription_id: ActiveValue::Set(bgm.subscription_id),
|
||||
subscriber_id: ActiveValue::Set(bgm.subscriber_id),
|
||||
resolution: ActiveValue::Set(raw_meta.resolution),
|
||||
season: ActiveValue::Set(if raw_meta.season > 0 {
|
||||
raw_meta.season
|
||||
|
||||
@@ -123,8 +123,7 @@ impl Model {
|
||||
.iter()
|
||||
.map(|s| Value::from(s.mikan_episode_id.clone())),
|
||||
);
|
||||
stmt.expr(Expr::col(episodes::Column::SubscriptionId))
|
||||
.and_where(Expr::col(episodes::Column::SubscriptionId).eq(self.id));
|
||||
stmt.and_where(Expr::col(episodes::Column::SubscriberId).eq(self.subscriber_id));
|
||||
|
||||
let builder = &db.get_database_backend();
|
||||
|
||||
@@ -132,7 +131,7 @@ impl Model {
|
||||
.query_all(builder.build(&stmt))
|
||||
.await?
|
||||
.into_iter()
|
||||
.flat_map(|qs| qs.try_get_by_index::<String>(0))
|
||||
.flat_map(|qs| qs.try_get_by_index(0))
|
||||
.collect::<HashSet<String>>();
|
||||
|
||||
let new_rss_items = items
|
||||
@@ -173,6 +172,7 @@ impl Model {
|
||||
let bgm = Arc::new(
|
||||
bangumi::Model::get_or_insert_from_mikan(
|
||||
ctx,
|
||||
self.subscriber_id,
|
||||
self.id,
|
||||
mikan_bangumi_id.to_string(),
|
||||
mikan_fansub_id.to_string(),
|
||||
|
||||
Reference in New Issue
Block a user