You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

use crate::helpers::ENV;
use u_lib::{api::ClientHandler, messaging::Reportable, models::*};
use uuid::Uuid;
pub struct RegisteredAgent {
pub uid: Uuid,
}
impl RegisteredAgent {
pub async fn unregister(self) {
let cli = ClientHandler::new(&ENV.u_server, None);
cli.del(self.uid).await.unwrap();
}
}
#[fixture]
pub async fn register_agent() -> RegisteredAgent {
let cli = ClientHandler::new(&ENV.u_server, None);
let agent_uid = Uuid::new_v4();
println!("registering agent {agent_uid}");
let resp = cli
.get_personal_jobs(agent_uid)
.await
.unwrap()
.pop()
.unwrap();
let job_id = resp.job_id;
let job = cli.get_jobs(Some(job_id)).await.unwrap().pop().unwrap();
assert_eq!(job.alias, Some("agent_hello".to_string()));
let mut agent_data = AssignedJob::from(&job);
agent_data.agent_id = agent_uid;
agent_data.set_result(&Agent::with_id(agent_uid));
cli.report(Reportable::Assigned(agent_data)).await.unwrap();
RegisteredAgent { uid: agent_uid }
}