Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijan committed Feb 7, 2025
1 parent 9af778a commit 347dc06
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 43 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

6 changes: 5 additions & 1 deletion entities/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ edition = "2021"
publish = false

[features]
test-utils = []
test-factories = [] # Define the feature



[dependencies]
test-utils = { path = "../test-utils" }
Expand All @@ -17,3 +19,5 @@ tracing.workspace = true
serde_json.workspace = true
chrono.workspace = true
serde.workspace = true

[build-dependencies]
7 changes: 7 additions & 0 deletions entities/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
// Check if we're running tests
let profile = std::env::var("PROFILE").unwrap_or_default();
if profile == "debug" {
println!("cargo:rustc-cfg=feature=\"test-factories\"");
}
}
70 changes: 35 additions & 35 deletions entities/src/dao/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,38 +115,38 @@ impl character::Model {
}
}

// #[cfg(test)]
// mod tests {
// use super::*;
// use crate::dao::char_info::Race;
// use sea_orm::TryIntoModel;
// use test_utils::utils::get_test_db;
// use test_utils::test_factories::factories::user_factory;
//
// #[tokio::test]
// async fn test_works() {
// let db_pool = get_test_db().await;
// let user = user_factory(&db_pool, |u|u).await;
// let char = character::ActiveModel {
// name: ActiveValue::Set("Admin".to_string()),
// level: ActiveValue::Set(1),
// face: ActiveValue::Set(2),
// hair_style: ActiveValue::Set(2),
// x: ActiveValue::Set(0),
// y: ActiveValue::Set(0),
// z: ActiveValue::Set(0),
// transform_id: ActiveValue::Set(2),
// class_id: ActiveValue::Set(1),
// race_id: ActiveValue::Set(Race::Human as i8),
// hair_color: ActiveValue::Set(0),
// is_female: ActiveValue::Set(false),
// user_id: ActiveValue::Set(user.id),
// ..Default::default()
// }
// .save(&db_pool)
// .await
// .unwrap()
// .try_into_model()
// .unwrap();
// }
// }
#[cfg(test)]
mod tests {
use super::*;
use crate::dao::char_info::PaperDoll;
use crate::test_factories::factories::{char_factory, item_factory, user_factory};
use test_utils::utils::get_test_db;

#[tokio::test]
async fn test_works() {
let db_pool = get_test_db().await;
let user = user_factory(&db_pool, |u| u).await;
let char = char_factory(&db_pool, |mut c| {
c.user_id = user.id;
c
})
.await;
let item = item_factory(&db_pool, |mut c| {
c.item_id = 10;
c.owner = char.id;
c.loc_data = PaperDoll::RHand as i32;
c
})
.await;

let chars =
character::Model::get_with_items_and_vars(&db_pool, "admin", LocType::Paperdoll)
.await
.unwrap();
assert_eq!(chars.len(), 1);
assert_eq!(chars[0].char_model.id, char.id);
assert_eq!(chars[0].items.len(), 1);
assert_eq!(chars[0].items[0].loc, LocType::Paperdoll);
assert_eq!(chars[0].items[0].item_id, item.item_id);
}
}
3 changes: 1 addition & 2 deletions entities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use sea_orm::DatabaseConnection;
pub mod entities;
pub mod dao;

#[cfg(feature = "test-utils")]
#[cfg(feature = "test-factories")]
pub mod test_factories;


pub type DBPool = DatabaseConnection;
2 changes: 1 addition & 1 deletion entities/src/test_factories.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(feature = "test-utils")]
#[cfg(feature = "test-factories")]
pub mod factories {
use crate::dao::char_info::{PaperDoll, Race};
use crate::dao::item::LocType;
Expand Down
2 changes: 1 addition & 1 deletion game/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ ntest.workspace = true

[dev-dependencies]
test-utils = { path = "../test-utils" }
entities = { path = "../entities", features = ["test-utils"] }
entities = { path = "../entities", features = ["test-factories"] }
3 changes: 1 addition & 2 deletions l2-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ pem.workspace = true
uuid.workspace = true
bytes.workspace = true

[dev-dependencies]
test-utils = {path = "../test-utils"}
[dev-dependencies]

0 comments on commit 347dc06

Please sign in to comment.