feat: Added interaction with accounts in CLI

- Account creation
- Account deletion
- Account balance management
- Account quest completion
- Added account CRUD test in tests/io.rs
This commit is contained in:
Alexey 2025-12-02 16:12:42 +03:00
commit dc94f2060c
3 changed files with 215 additions and 18 deletions

View file

@ -1,5 +1,4 @@
use squad_quest::{SquadObject, config::Config, error::Error, quest::Quest};
use std::path::PathBuf;
use squad_quest::{SquadObject, account::Account, config::Config, quest::Quest};
const CONFIG_PATH: &str = "tests/io/config.toml";
@ -7,23 +6,35 @@ const CONFIG_PATH: &str = "tests/io/config.toml";
// and Quest::save can override files,
// so this test covers full quest CRUD
#[test]
fn quest_crud() -> Result<(), Error> {
fn quest_crud() {
let config = Config::load(CONFIG_PATH.into());
let mut quests_path = PathBuf::from(CONFIG_PATH).parent().unwrap().to_owned();
quests_path.push(config.quests_path);
let mut quests_path = config.full_quests_path();
let quest = Quest::default();
println!("{:?}", quests_path.clone());
quest.save(quests_path.clone())?;
quest.save(quests_path.clone()).unwrap();
let filename = format!("{}.toml", quest.id);
quests_path.push(filename);
Quest::delete(quests_path)?;
Ok(())
Quest::delete(quests_path).unwrap();
}
#[test]
fn account_crud() {
let config = Config::load(CONFIG_PATH.into());
let mut accounts_path = config.full_accounts_path();
let account = Account::default();
account.save(accounts_path.clone()).unwrap();
let filename = format!("{}.toml", account.id);
accounts_path.push(filename);
Account::delete(accounts_path).unwrap();
}