From 95d23fceacbf59fedacbcb249b9d4f701992e5d6 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 12 Nov 2023 16:33:27 -0700 Subject: [PATCH] clean up tests a bit by using itembuilder rather than using structs directly --- tests/common.rs | 265 ++++++++++++++- tests/test_bank.rs | 410 ++++++----------------- tests/test_item_actions.rs | 106 ++---- tests/test_item_id.rs | 74 ++-- tests/test_item_pickup.rs | 150 +++------ tests/test_item_use.rs | 128 ++----- tests/test_mags.rs | 54 +-- tests/test_shops.rs | 214 ++++-------- tests/test_trade.rs | 667 +++++++++---------------------------- 9 files changed, 744 insertions(+), 1324 deletions(-) diff --git a/tests/common.rs b/tests/common.rs index e2a3555..eb21187 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -161,9 +161,23 @@ pub async fn join_room(ship: &mut ShipServerState pub struct WeaponBuilder { weapon: item::weapon::WeaponType, grind: u8, + special: Option, + attributes: [Option; 3], + tekked: bool, } + impl WeaponBuilder { + fn new(weapon: item::weapon::WeaponType) -> WeaponBuilder { + WeaponBuilder { + weapon, + grind: 0, + special: None, + attributes: [None; 3], + tekked: true, + } + } + pub fn grind(self, grind: u8) -> WeaponBuilder { WeaponBuilder { grind, @@ -171,28 +185,267 @@ impl WeaponBuilder { } } + pub fn special(self, special: item::weapon::WeaponSpecial) -> WeaponBuilder { + WeaponBuilder { + special: Some(special), + ..self + } + } + + pub fn attr(mut self, attr: item::weapon::Attribute, value: i8) -> WeaponBuilder { + self.attributes + .iter_mut() + .find(|k| k.is_none()) + .map(|empty_attr| { + *empty_attr = Some(item::weapon::WeaponAttribute { + attr, + value, + }) + }); + + self + } + + pub fn untekked(self) -> WeaponBuilder { + WeaponBuilder { + tekked: false, + ..self + } + } + pub fn as_new(self) -> item::NewItemEntity { item::NewItemEntity { item: item::ItemDetail::Weapon( item::weapon::Weapon { weapon: self.weapon, grind: self.grind, - special: None, - attrs: [None, None, None], - tekked: true, + special: self.special, + attrs: self.attributes, + tekked: self.tekked, + } + ) + } + } +} + +pub struct ArmorBuilder { + armor: item::armor::ArmorType, + dfp: u8, + evp: u8, + slots: u8, +} + +impl ArmorBuilder { + pub fn new(armor: item::armor::ArmorType) -> ArmorBuilder { + ArmorBuilder { + armor: armor, + dfp: 0, + evp: 0, + slots: 0, + } + } + + pub fn slots(self, slots: u8) -> ArmorBuilder { + ArmorBuilder { + slots, + ..self + } + } + + pub fn dfp(self, dfp: u8) -> ArmorBuilder { + ArmorBuilder { + dfp, + ..self + } + } + + pub fn evp(self, evp: u8) -> ArmorBuilder { + ArmorBuilder { + evp, + ..self + } + } + + pub fn as_new(self) -> item::NewItemEntity { + item::NewItemEntity { + item: item::ItemDetail::Armor( + item::armor::Armor { + armor: self.armor, + dfp: self.dfp, + evp: self.evp, + slots: self.slots, + } + ) + } + } +} + +pub struct ShieldBuilder { + shield: item::shield::ShieldType, + dfp: u8, + evp: u8, +} + +impl ShieldBuilder { + pub fn new(shield: item::shield::ShieldType) -> ShieldBuilder { + ShieldBuilder { + shield: shield, + dfp: 0, + evp: 0, + } + } + + pub fn dfp(self, dfp: u8) -> ShieldBuilder { + ShieldBuilder { + dfp, + ..self + } + } + + pub fn evp(self, evp: u8) -> ShieldBuilder { + ShieldBuilder { + evp, + ..self + } + } + + pub fn as_new(self) -> item::NewItemEntity { + item::NewItemEntity { + item: item::ItemDetail::Shield( + item::shield::Shield { + shield: self.shield, + dfp: self.dfp, + evp: self.evp, + } + ) + } + } +} + + +pub struct UnitBuilder { + unit: item::unit::UnitType, + modifier: Option, +} + +impl UnitBuilder { + pub fn modifier(self, modifier: item::unit::UnitModifier) -> UnitBuilder { + UnitBuilder { + modifier: Some(modifier), + ..self + } + } + + pub fn as_new(self) -> item::NewItemEntity { + item::NewItemEntity { + item: item::ItemDetail::Unit( + item::unit::Unit { + unit: self.unit, + modifier: self.modifier, } ) } } } + +pub struct MagBuilder { +} + +impl MagBuilder { + pub fn as_new(self) -> item::NewItemEntity { + item::NewItemEntity { + item: item::ItemDetail::Mag( + item::mag::Mag::baby_mag(0) + ) + } + } +} + + + +pub struct ToolBuilder { + tool: item::tool::ToolType, +} + +impl ToolBuilder { + pub fn as_new(self) -> item::NewItemEntity { + item::NewItemEntity { + item: item::ItemDetail::Tool ( + item::tool::Tool { + tool: self.tool, + } + ), + } + } +} + +pub struct TechBuilder { + tech: item::tech::Technique, + level: u32, +} + + +impl TechBuilder { + pub fn level(self, level: u32) -> TechBuilder { + TechBuilder { + level, + ..self + } + } + + pub fn as_new(self) -> item::NewItemEntity { + item::NewItemEntity { + item: item::ItemDetail::TechniqueDisk ( + item::tech::TechniqueDisk { + tech: self.tech, + level: self.level, + } + ) + } + } +} + + pub struct ItemBuilder; impl ItemBuilder { pub fn weapon(weapon: item::weapon::WeaponType) -> WeaponBuilder { - WeaponBuilder { - weapon, - grind: 0, + WeaponBuilder::new(weapon) + } + + pub fn armor(armor: item::armor::ArmorType) -> ArmorBuilder { + ArmorBuilder::new(armor) + } + + pub fn shield(shield: item::shield::ShieldType) -> ShieldBuilder { + ShieldBuilder::new(shield) + } + + pub fn unit(unit: item::unit::UnitType) -> UnitBuilder { + UnitBuilder { + unit: unit, + modifier: None, + } + } + + pub fn baby_mag() -> MagBuilder { + MagBuilder { } } + + pub fn tool(tool: item::tool::ToolType) -> ToolBuilder { + ToolBuilder { + tool: tool, + } + } + + pub fn tech(tech: item::tech::Technique) -> TechBuilder { + TechBuilder { + tech: tech, + level: 0, + } + } + + } diff --git a/tests/test_bank.rs b/tests/test_bank.rs index a3ad3e8..9211f97 100644 --- a/tests/test_bank.rs +++ b/tests/test_bank.rs @@ -20,17 +20,9 @@ async fn test_bank_items_sent_in_character_login() { let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let item = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap(); entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![item]), &item::BankIdentifier::Character).await.unwrap(); @@ -55,17 +47,9 @@ async fn test_request_bank_items() { let mut bank = Vec::new(); for _ in 0..3 { bank.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), &item::BankIdentifier::Character).await.unwrap(); @@ -101,13 +85,9 @@ async fn test_request_stacked_bank_items() { let mut monomates = Vec::new(); for _ in 0..3usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool ( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), &item::BankIdentifier::Character).await.unwrap(); @@ -140,37 +120,17 @@ async fn test_request_bank_items_sorted() { let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let item1 = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap(); let monomate = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool ( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap(); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap(); let item2 = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Calibur, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(); + ItemBuilder::weapon(item::weapon::WeaponType::Calibur) + .as_new() + ).await.unwrap(); let bank = vec![item::BankItemEntity::Individual(item1), vec![monomate].into(), item2.into()]; entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), &item::BankIdentifier::Character).await.unwrap(); @@ -204,29 +164,13 @@ async fn test_deposit_individual_item() { let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let item0 = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(); + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap(); let item1 = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap(); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![item0, item1])).await.unwrap(); @@ -283,13 +227,9 @@ async fn test_deposit_stacked_item() { let mut monomates = Vec::new(); for _ in 0..3usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![monomates])).await.unwrap(); @@ -342,13 +282,9 @@ async fn test_deposit_partial_stacked_item() { let mut monomates = Vec::new(); for _ in 0..3usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![monomates])).await.unwrap(); @@ -411,22 +347,14 @@ async fn test_deposit_stacked_item_with_stack_already_in_bank() { let mut inventory_monomates = Vec::new(); for _ in 0..2usize { inventory_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); bank_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![inventory_monomates])).await.unwrap(); @@ -479,25 +407,17 @@ async fn test_deposit_stacked_item_with_full_stack_in_bank() { let mut inventory_monomates = Vec::new(); for _ in 0..2usize { inventory_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } let mut bank_monomates = Vec::new(); for _ in 0..10 { bank_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![inventory_monomates])).await.unwrap(); @@ -548,32 +468,16 @@ async fn test_deposit_individual_item_in_full_bank() { let mut inventory = Vec::new(); inventory.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap()); let mut bank = Vec::new(); for _ in 0..200usize { bank.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap(); @@ -621,29 +525,17 @@ async fn test_deposit_stacked_item_in_full_bank() { let mut monomates = Vec::new(); for _ in 0..2usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } let mut full_bank = Vec::new(); for _ in 0..200usize { full_bank.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![monomates])).await.unwrap(); @@ -692,41 +584,25 @@ async fn test_deposit_stacked_item_in_full_bank_with_partial_stack() { let mut monomates = Vec::new(); for _ in 0..2usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } let mut bank_monomates = Vec::new(); for _ in 0..2usize { bank_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } let mut almost_full_bank: Vec = Vec::new(); for _ in 0..199usize { almost_full_bank.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap().into()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap().into()); } almost_full_bank.push(bank_monomates.into()); @@ -882,17 +758,9 @@ async fn test_withdraw_individual_item() { let mut bank = Vec::new(); bank.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap()); entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(bank), &item::BankIdentifier::Character).await.unwrap(); @@ -943,13 +811,9 @@ async fn test_withdraw_stacked_item() { let mut monomates = Vec::new(); for _ in 0..3usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), &item::BankIdentifier::Character).await.unwrap(); @@ -1001,13 +865,9 @@ async fn test_withdraw_partial_stacked_item() { let mut monomates = Vec::new(); for _ in 0..3usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), &item::BankIdentifier::Character).await.unwrap(); @@ -1066,22 +926,14 @@ async fn test_withdraw_stacked_item_with_stack_already_in_inventory() { let mut bank_monomates = Vec::new(); for _ in 0..2usize { inventory_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); bank_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![inventory_monomates])).await.unwrap(); @@ -1136,25 +988,17 @@ async fn test_withdraw_stacked_item_with_full_stack_in_inventory() { let mut bank_monomates = Vec::new(); for _ in 0..2usize { bank_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } let mut inventory_monomates = Vec::new(); for _ in 0..10usize { inventory_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![inventory_monomates])).await.unwrap(); @@ -1205,32 +1049,16 @@ async fn test_withdraw_individual_item_in_full_inventory() { let mut bank = Vec::new(); bank.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap()); let mut inventory = Vec::new(); for _ in 0..30usize { inventory.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap(); @@ -1274,29 +1102,17 @@ async fn test_withdraw_stacked_item_in_full_inventory() { let mut monomates = Vec::new(); for _ in 0..2usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } let mut inventory = Vec::new(); for _ in 0..30usize { inventory.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(inventory)).await.unwrap(); @@ -1346,42 +1162,26 @@ async fn test_withdraw_stacked_item_in_full_inventory_with_partial_stack() { let mut bank_item = Vec::new(); for _ in 0..2usize { bank_item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![bank_item]), &item::BankIdentifier::Character).await.unwrap(); let mut items = Vec::new(); for _i in 0..29usize { items.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap().into()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .as_new() + ).await.unwrap().into()); } let mut item29 = Vec::new(); for _ in 0..2usize { item29.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } items.push(item::InventoryItemEntity::Stacked(item29)); diff --git a/tests/test_item_actions.rs b/tests/test_item_actions.rs index 2072403..beef459 100644 --- a/tests/test_item_actions.rs +++ b/tests/test_item_actions.rs @@ -18,33 +18,21 @@ async fn test_equip_unit_from_equip_menu() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Armor( - item::armor::Armor{ - armor: item::armor::ArmorType::Frame, - dfp: 0, - evp: 0, - slots: 4, - }), - }).await.unwrap()); + ItemBuilder::armor(item::armor::ArmorType::Frame) + .slots(4) + .as_new() + ).await.unwrap()); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit{ - unit: item::unit::UnitType::KnightPower, - modifier: None, - }), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::KnightPower) + .as_new() + ).await.unwrap()); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit{ - unit: item::unit::UnitType::KnightPower, - modifier: Some(item::unit::UnitModifier::Plus), - }), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::KnightPower) + .modifier(item::unit::UnitModifier::Plus) + .as_new() + ).await.unwrap()); let equipped = item::EquippedEntity { weapon: None, @@ -93,33 +81,21 @@ async fn test_unequip_armor_with_units() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Armor( - item::armor::Armor{ - armor: item::armor::ArmorType::Frame, - dfp: 0, - evp: 0, - slots: 4, - }), - }).await.unwrap()); + ItemBuilder::armor(item::armor::ArmorType::Frame) + .slots(4) + .as_new() + ).await.unwrap()); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit{ - unit: item::unit::UnitType::KnightPower, - modifier: None, - }), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::KnightPower) + .as_new() + ).await.unwrap()); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit{ - unit: item::unit::UnitType::KnightPower, - modifier: Some(item::unit::UnitModifier::Plus), - }), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::KnightPower) + .modifier(item::unit::UnitModifier::Plus) + .as_new() + ).await.unwrap()); let equipped = item::EquippedEntity { weapon: None, @@ -159,33 +135,21 @@ async fn test_sort_items() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Armor( - item::armor::Armor{ - armor: item::armor::ArmorType::Frame, - dfp: 0, - evp: 0, - slots: 4, - }), - }).await.unwrap()); + ItemBuilder::armor(item::armor::ArmorType::Frame) + .slots(4) + .as_new() + ).await.unwrap()); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit{ - unit: item::unit::UnitType::KnightPower, - modifier: None, - }), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::KnightPower) + .as_new() + ).await.unwrap()); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit{ - unit: item::unit::UnitType::KnightPower, - modifier: Some(item::unit::UnitModifier::Plus), - }), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::KnightPower) + .modifier(item::unit::UnitModifier::Plus) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -210,8 +174,8 @@ async fn test_sort_items() { ship.handle(ClientId(1), RecvShipPacket::Message(Message::new(GameMessage::SortItems(SortItems { client: 255, target: 255, - item_ids: [0x10001u32, 0x10002, 0x10000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + item_ids: [0x10001u32, 0x10002, 0x10000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, + 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF], })))).await.unwrap(); diff --git a/tests/test_item_id.rs b/tests/test_item_id.rs index d887af4..01ec5d2 100644 --- a/tests/test_item_id.rs +++ b/tests/test_item_id.rs @@ -22,13 +22,9 @@ async fn test_use_monomate_after_leaving_and_rejoining_room() { let mut item = Vec::new(); for _ in 0..2usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p1_items.push(item::InventoryItemEntity::Stacked(item)); } @@ -40,13 +36,9 @@ async fn test_use_monomate_after_leaving_and_rejoining_room() { let mut item = Vec::new(); for _ in 0..2usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p2_items.push(item::InventoryItemEntity::Stacked(item)); } @@ -116,13 +108,9 @@ async fn test_using_some_monomates_after_a_convoluted_series_of_leaves_and_joins let mut item = Vec::new(); for _ in 0..2usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p1_items.push(item::InventoryItemEntity::Stacked(item)); } @@ -133,13 +121,9 @@ async fn test_using_some_monomates_after_a_convoluted_series_of_leaves_and_joins let mut item = Vec::new(); for _ in 0..6usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p2_items.push(item::InventoryItemEntity::Stacked(item)); } @@ -150,17 +134,9 @@ async fn test_using_some_monomates_after_a_convoluted_series_of_leaves_and_joins p3_items.push( item::InventoryItemEntity::Individual( entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap() + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap() )); } entity_gateway.set_character_inventory(&char3.id, &item::InventoryEntity::new(p3_items)).await.unwrap(); @@ -301,13 +277,9 @@ async fn test_depositing_a_full_stack_then_withdrawing_part() { let mut item = Vec::new(); for _ in 0..5usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p1_items.push(item::InventoryItemEntity::Stacked(item)); } @@ -316,13 +288,9 @@ async fn test_depositing_a_full_stack_then_withdrawing_part() { let mut monomates = Vec::new(); for _ in 0..3usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_bank(&char1.id, &item::BankEntity::new(vec![monomates]), &item::BankIdentifier::Character).await.unwrap(); diff --git a/tests/test_item_pickup.rs b/tests/test_item_pickup.rs index 7788ffb..82dd777 100644 --- a/tests/test_item_pickup.rs +++ b/tests/test_item_pickup.rs @@ -19,17 +19,9 @@ async fn test_pick_up_individual_item() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(Vec::::new())).await.unwrap(); @@ -88,26 +80,18 @@ async fn test_pick_up_item_stack_of_items_already_in_inventory() { let mut p1_monomate = Vec::new(); p1_monomate.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); let mut p2_items = Vec::new(); for (_slot, tool) in vec![item::tool::ToolType::Monomate, item::tool::ToolType::Monofluid].into_iter().enumerate() { let mut item = Vec::new(); for _ in 0..5usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p2_items.push(item); } @@ -162,13 +146,9 @@ async fn test_pick_up_item_stack_of_items_not_already_held() { let mut p2_monomate = Vec::new(); p2_monomate.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(vec![p2_monomate])).await.unwrap(); @@ -220,17 +200,9 @@ async fn test_pick_up_meseta_when_inventory_full() { let mut p1_items = Vec::new(); for _ in 0..30usize { p1_items.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_items)).await.unwrap(); @@ -291,37 +263,21 @@ async fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() { let mut p1_inv = Vec::new(); for _slot in 0..29usize { p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap().into()); + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap().into()); } p1_inv.push(item::InventoryItemEntity::Stacked(vec![entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()])); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()])); let mut p2_monomates = Vec::new(); p2_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(vec![p2_monomates])).await.unwrap(); @@ -372,32 +328,16 @@ async fn test_can_not_pick_up_item_when_inventory_full() { let mut p1_inv = Vec::new(); for _slot in 0..30usize { p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap()); } let mut p2_inv = Vec::new(); p2_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(p2_inv)).await.unwrap(); @@ -498,25 +438,17 @@ async fn test_pick_up_stack_that_would_exceed_stack_limit() { let mut p1_monomates = Vec::new(); for _ in 0..6usize { p1_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } let mut p2_monomates = Vec::new(); for _ in 0..6usize { p2_monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![p1_monomates])).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(vec![p2_monomates])).await.unwrap(); @@ -675,13 +607,9 @@ async fn test_player_drops_partial_stack_and_other_player_picks_it_up() { let mut monomates = Vec::new(); for _ in 0..5usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![monomates])).await.unwrap(); diff --git a/tests/test_item_use.rs b/tests/test_item_use.rs index a117da7..d4117f7 100644 --- a/tests/test_item_use.rs +++ b/tests/test_item_use.rs @@ -23,13 +23,9 @@ async fn test_use_monomate() { let mut item = Vec::new(); for _ in 0..2usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p1_items.push(item::InventoryItemEntity::Stacked(item)); } @@ -68,13 +64,9 @@ async fn test_use_monomate_twice() { let mut item = Vec::new(); for _ in 0..3usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p1_items.push(item::InventoryItemEntity::Stacked(item)); } @@ -116,13 +108,9 @@ async fn test_use_last_monomate() { let mut p1_inv = Vec::new(); for tool in vec![item::tool::ToolType::Monomate, item::tool::ToolType::Monofluid].into_iter() { p1_inv.push(item::InventoryItemEntity::Stacked(vec![entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()])); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()])); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -155,13 +143,9 @@ async fn test_use_nonstackable_tool() { let mut p1_items = Vec::new(); p1_items.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::HuntersReport, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::HuntersReport) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_items)).await.unwrap(); @@ -191,13 +175,9 @@ async fn test_use_materials() { let mut item = Vec::new(); for _ in 0..5usize { item.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: tool - } - ), - }).await.unwrap()); + ItemBuilder::tool(tool) + .as_new() + ).await.unwrap()); } p1_inv.push(item::InventoryItemEntity::Stacked(item)); } @@ -250,20 +230,13 @@ async fn test_jackolantern() { item::InventoryItemEntity::Stacked( vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::JackOLantern, - } - ), - }).await.unwrap(), - entity_gateway.create_item(item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::JackOLantern, - } - ), - }).await.unwrap(), + ItemBuilder::tool(item::tool::ToolType::JackOLantern) + .as_new() + ).await.unwrap(), + entity_gateway.create_item( + ItemBuilder::tool(item::tool::ToolType::JackOLantern) + .as_new() + ).await.unwrap(), ])]; entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -301,34 +274,19 @@ async fn test_use_barta_1() { let inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::TechniqueDisk( - item::tech::TechniqueDisk { - tech: item::tech::Technique::Foie, - level: 3, - } - ) - } + ItemBuilder::tech(item::tech::Technique::Foie) + .level(3) + .as_new() ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::TechniqueDisk( - item::tech::TechniqueDisk { - tech: item::tech::Technique::Barta, - level: 4, - } - ) - } + ItemBuilder::tech(item::tech::Technique::Barta) + .level(4) + .as_new() ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::TechniqueDisk( - item::tech::TechniqueDisk { - tech: item::tech::Technique::Zonde, - level: 5, - } - ) - } + ItemBuilder::tech(item::tech::Technique::Zonde) + .level(5) + .as_new() ).await.unwrap() ]; @@ -368,28 +326,16 @@ async fn test_use_monogrinder() { let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let saber = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(); + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap(); let mut grinders = Vec::new(); for _ in 0..3usize { grinders.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monogrinder, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monogrinder) + .as_new() + ).await.unwrap()); } let equipped = item::EquippedEntity { diff --git a/tests/test_mags.rs b/tests/test_mags.rs index a4ee763..d55a269 100644 --- a/tests/test_mags.rs +++ b/tests/test_mags.rs @@ -18,22 +18,16 @@ async fn test_mag_feed() { let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mag = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Mag( - item::mag::Mag::baby_mag(0) - ), - }).await.unwrap(); + ItemBuilder::baby_mag() + .as_new() + ).await.unwrap(); let mut monomates = Vec::new(); for _ in 0..7usize { monomates.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap()); } let equipped = item::EquippedEntity { @@ -95,11 +89,9 @@ async fn test_mag_change_owner() { entity_gateway.save_character(&char2).await.unwrap(); let mag = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Mag( - item::mag::Mag::baby_mag(0) - ), - }).await.unwrap(); + ItemBuilder::baby_mag() + .as_new() + ).await.unwrap(); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(vec![mag])).await.unwrap(); @@ -151,31 +143,21 @@ async fn test_mag_cell() { let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let mag = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Mag( - item::mag::Mag::baby_mag(0) - ), - }).await.unwrap(); + ItemBuilder::baby_mag() + .as_new() + ).await.unwrap(); for _ in 0..1000usize { let fed_tool = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool ( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ), - }).await.unwrap(); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap(); entity_gateway.feed_mag(&mag.id, &fed_tool.id).await.unwrap(); } let mag_cell = entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::CellOfMag502, - } - ), - }).await.unwrap(); + ItemBuilder::tool(item::tool::ToolType::CellOfMag502) + .as_new() + ).await.unwrap(); let equipped = item::EquippedEntity { weapon: None, diff --git a/tests/test_shops.rs b/tests/test_shops.rs index 4855db4..3e2dc02 100644 --- a/tests/test_shops.rs +++ b/tests/test_shops.rs @@ -265,19 +265,14 @@ async fn test_player_sells_3_attr_weapon_to_shop() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 5, - special: Some(item::weapon::WeaponSpecial::Charge), - attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}), - Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}), - Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .grind(5) + .special(item::weapon::WeaponSpecial::Charge) + .attr(item::weapon::Attribute::Hit, 100) + .attr(item::weapon::Attribute::Dark, 100) + .attr(item::weapon::Attribute::Native, 100) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -351,13 +346,9 @@ async fn test_other_clients_see_stacked_purchase() { entity_gateway.save_character(&char1).await.unwrap(); entity_gateway.set_character_meseta(&char1.id, item::Meseta(999999)).await.unwrap(); entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate - } - ), - }).await.unwrap(); + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await.unwrap(); let mut ship = standard_ship_buildable(entity_gateway.clone()) .item_shops(StandardItemShops::default()) @@ -622,19 +613,15 @@ async fn test_player_sells_untekked_weapon() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Vulcan, - grind: 5, - special: Some(item::weapon::WeaponSpecial::Charge), - attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}), - Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}), - Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),], - tekked: false, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Vulcan) + .untekked() + .grind(5) + .special(item::weapon::WeaponSpecial::Charge) + .attr(item::weapon::Attribute::Hit, 100) + .attr(item::weapon::Attribute::Dark, 100) + .attr(item::weapon::Attribute::Native, 100) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -664,19 +651,13 @@ async fn test_player_sells_rare_item() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::DarkFlow, - grind: 5, - special: None, - attrs: [Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Hit, value: 100}), - Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 100}), - Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Native, value: 100}),], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::DarkFlow) + .grind(5) + .attr(item::weapon::Attribute::Hit, 100) + .attr(item::weapon::Attribute::Dark, 100) + .attr(item::weapon::Attribute::Native, 100) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -708,13 +689,9 @@ async fn test_player_sells_partial_photon_drop_stack() { let mut photon_drops = Vec::new(); for _ in 0..7usize { photon_drops.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::PhotonDrop, - } - ), - }).await.unwrap()); + ItemBuilder::tool(item::tool::ToolType::PhotonDrop) + .as_new() + ).await.unwrap()); } p1_inv.push(item::InventoryItemEntity::Stacked(photon_drops)); @@ -747,16 +724,9 @@ async fn test_player_sells_basic_frame() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Armor( - item::armor::Armor { - armor: item::armor::ArmorType::Frame, - dfp: 0, - evp: 0, - slots: 0, - } - ), - }).await.unwrap()); + ItemBuilder::armor(item::armor::ArmorType::Frame) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -786,16 +756,12 @@ async fn test_player_sells_max_frame() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Armor( - item::armor::Armor { - armor: item::armor::ArmorType::Frame, - dfp: 2, - evp: 2, - slots: 4, - } - ), - }).await.unwrap()); + ItemBuilder::armor(item::armor::ArmorType::Frame) + .dfp(2) + .evp(2) + .slots(4) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -825,15 +791,9 @@ async fn test_player_sells_basic_barrier() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Shield( - item::shield::Shield { - shield: item::shield::ShieldType::Barrier, - dfp: 0, - evp: 0, - } - ), - }).await.unwrap()); + ItemBuilder::shield(item::shield::ShieldType::Barrier) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -863,15 +823,11 @@ async fn test_player_sells_max_barrier() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Shield( - item::shield::Shield { - shield: item::shield::ShieldType::Barrier, - dfp: 5, - evp: 5, - } - ), - }).await.unwrap()); + ItemBuilder::shield(item::shield::ShieldType::Barrier) + .dfp(5) + .evp(5) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -901,14 +857,10 @@ async fn test_player_sells_1_star_minusminus_unit() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit { - unit: item::unit::UnitType::PriestMind, - modifier: Some(item::unit::UnitModifier::MinusMinus), - } - ), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::PriestMind) + .modifier(item::unit::UnitModifier::MinusMinus) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -938,14 +890,10 @@ async fn test_player_sells_5_star_plusplus_unit() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit { - unit: item::unit::UnitType::GeneralHp, - modifier: Some(item::unit::UnitModifier::PlusPlus), - } - ), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::GeneralHp) + .modifier(item::unit::UnitModifier::PlusPlus) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -975,16 +923,12 @@ async fn test_player_sells_rare_frame() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Armor( - item::armor::Armor { - armor: item::armor::ArmorType::StinkFrame, - dfp: 10, - evp: 20, - slots: 3, - } - ), - }).await.unwrap()); + ItemBuilder::armor(item::armor::ArmorType::StinkFrame) + .dfp(10) + .evp(20) + .slots(3) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -1014,15 +958,11 @@ async fn test_player_sells_rare_barrier() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Shield( - item::shield::Shield { - shield: item::shield::ShieldType::RedRing, - dfp: 10, - evp: 20, - } - ), - }).await.unwrap()); + ItemBuilder::shield(item::shield::ShieldType::RedRing) + .dfp(10) + .evp(20) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -1052,14 +992,9 @@ async fn test_player_sells_rare_unit() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit { - unit: item::unit::UnitType::V101, - modifier: None, - } - ), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::V101) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -1090,14 +1025,9 @@ async fn test_player_cant_sell_if_meseta_would_go_over_max() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Unit( - item::unit::Unit { - unit: item::unit::UnitType::V101, - modifier: None, - } - ), - }).await.unwrap()); + ItemBuilder::unit(item::unit::UnitType::V101) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); diff --git a/tests/test_trade.rs b/tests/test_trade.rs index d35d31b..93f1463 100644 --- a/tests/test_trade.rs +++ b/tests/test_trade.rs @@ -118,17 +118,9 @@ async fn test_trade_one_individual_item() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(Vec::::new())).await.unwrap(); @@ -217,17 +209,9 @@ async fn test_trade_player2_to_player1() { let mut p2_inv = Vec::new(); p2_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(Vec::::new())).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(p2_inv)).await.unwrap(); @@ -316,17 +300,9 @@ async fn test_reverse_trade_ack_order() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(Vec::::new())).await.unwrap(); @@ -417,13 +393,9 @@ async fn test_trade_one_stacked_item() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -519,13 +491,9 @@ async fn test_trade_partial_stacked_item() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -622,30 +590,14 @@ async fn test_trade_individual_both() { let p1_inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()]; + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap()]; let p2_inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()]; + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()]; entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(p2_inv)).await.unwrap(); @@ -787,13 +739,9 @@ async fn test_trade_stacked_both() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -804,13 +752,9 @@ async fn test_trade_stacked_both() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monofluid, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monofluid) + .as_new() + ).await }})) .await .into_iter() @@ -955,13 +899,9 @@ async fn test_trade_partial_stack_both() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -972,13 +912,9 @@ async fn test_trade_partial_stack_both() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monofluid, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monofluid) + .as_new() + ).await }})) .await .into_iter() @@ -1129,13 +1065,9 @@ async fn test_trade_same_stacked_item_to_eachother() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -1146,13 +1078,9 @@ async fn test_trade_same_stacked_item_to_eachother() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -1299,13 +1227,9 @@ async fn test_trade_stacked_when_already_have_partial_stack() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -1316,13 +1240,9 @@ async fn test_trade_stacked_when_already_have_partial_stack() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -1435,29 +1355,17 @@ async fn test_trade_individual_for_stacked() { let p1_inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()]; + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap()]; let p2_stack = futures::future::join_all((0..2).map(|_| { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -1603,55 +1511,23 @@ async fn test_trade_multiple_individual() { let p1_inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Buster, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Buster) + .as_new() + ).await.unwrap(), ]; let p2_inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Autogun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Autogun) + .as_new() + ).await.unwrap(), ]; entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -1861,13 +1737,9 @@ async fn test_trade_multiple_stacked() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -1877,13 +1749,9 @@ async fn test_trade_multiple_stacked() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Dimate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Dimate) + .as_new() + ).await }})) .await .into_iter() @@ -1894,13 +1762,9 @@ async fn test_trade_multiple_stacked() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monofluid, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monofluid) + .as_new() + ).await }})) .await .into_iter() @@ -1910,13 +1774,9 @@ async fn test_trade_multiple_stacked() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Difluid, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Difluid) + .as_new() + ).await }})) .await .into_iter() @@ -2126,17 +1986,8 @@ async fn test_trade_not_enough_inventory_space_individual() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - } + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() ).await }})) .await @@ -2148,17 +1999,8 @@ async fn test_trade_not_enough_inventory_space_individual() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - } + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() ).await }})) .await @@ -2247,13 +2089,9 @@ async fn test_trade_not_enough_inventory_space_stacked() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -2264,17 +2102,8 @@ async fn test_trade_not_enough_inventory_space_stacked() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - } + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() ).await }})) .await @@ -2362,13 +2191,9 @@ async fn test_trade_stack_too_big() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -2379,13 +2204,9 @@ async fn test_trade_stack_too_big() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -2732,17 +2553,9 @@ async fn test_back_out_of_trade_last_minute() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(Vec::::new())).await.unwrap(); @@ -2798,17 +2611,8 @@ async fn test_valid_trade_when_both_inventories_are_full() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - } + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() ).await }})) .await @@ -2820,17 +2624,8 @@ async fn test_valid_trade_when_both_inventories_are_full() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - } + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() ).await }})) .await @@ -2938,17 +2733,8 @@ async fn test_invalid_trade_when_both_inventories_are_full() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - } + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() ).await }})) .await @@ -2960,17 +2746,8 @@ async fn test_invalid_trade_when_both_inventories_are_full() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - } + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() ).await }})) .await @@ -3155,17 +2932,9 @@ async fn test_add_then_remove_individual_item() { let mut p1_inv = Vec::new(); for _ in 0..2 { p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); } entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -3267,13 +3036,9 @@ async fn test_add_then_remove_stacked_item() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -3284,13 +3049,9 @@ async fn test_add_then_remove_stacked_item() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monofluid, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monofluid) + .as_new() + ).await }})) .await .into_iter() @@ -3400,13 +3161,9 @@ async fn test_add_then_remove_partial_stack() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -3417,13 +3174,9 @@ async fn test_add_then_remove_partial_stack() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monofluid, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monofluid) + .as_new() + ).await }})) .await .into_iter() @@ -3604,17 +3357,9 @@ async fn test_items_to_trade_data_does_not_match() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(Vec::::new())).await.unwrap(); @@ -3685,17 +3430,9 @@ async fn test_items_to_trade_id_does_not_match() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(Vec::::new())).await.unwrap(); @@ -3756,13 +3493,9 @@ async fn test_stack_is_same_amount_in_request_and_items_to_trade() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -3828,13 +3561,9 @@ async fn test_stack_is_same_amount_in_request_and_items_to_trade2() { let mut entity_gateway = entity_gateway.clone(); async move { entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Tool( - item::tool::Tool { - tool: item::tool::ToolType::Monomate, - } - ) - }).await + ItemBuilder::tool(item::tool::ToolType::Monomate) + .as_new() + ).await }})) .await .into_iter() @@ -3898,41 +3627,17 @@ async fn test_items_to_trade_count_less_than() { let p1_inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Brand, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Brand) + .as_new() + ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Buster, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Buster) + .as_new() + ).await.unwrap(), ]; entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -4000,41 +3705,17 @@ async fn test_items_to_trade_count_greater_than() { let p1_inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Brand, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Brand) + .as_new() + ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Buster, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Buster) + .as_new() + ).await.unwrap(), ]; entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -4106,41 +3787,17 @@ async fn test_items_to_trade_count_mismatch_with_meseta() { let p1_inv = vec![ entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Saber, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Saber) + .as_new() + ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Brand, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Brand) + .as_new() + ).await.unwrap(), entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Buster, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap(), + ItemBuilder::weapon(item::weapon::WeaponType::Buster) + .as_new() + ).await.unwrap(), ]; entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); @@ -4206,17 +3863,9 @@ async fn test_dropping_item_after_trade() { let mut p1_inv = Vec::new(); p1_inv.push(entity_gateway.create_item( - item::NewItemEntity { - item: item::ItemDetail::Weapon( - item::weapon::Weapon { - weapon: item::weapon::WeaponType::Handgun, - grind: 0, - special: None, - attrs: [None, None, None], - tekked: true, - } - ), - }).await.unwrap()); + ItemBuilder::weapon(item::weapon::WeaponType::Handgun) + .as_new() + ).await.unwrap()); entity_gateway.set_character_inventory(&char1.id, &item::InventoryEntity::new(p1_inv)).await.unwrap(); entity_gateway.set_character_inventory(&char2.id, &item::InventoryEntity::new(Vec::::new())).await.unwrap();