use super::*;
use dotenv::dotenv;
use serde_json::json;
async fn project_update(bot: Rujira, key: &str) {
let update = serde_json::from_str(r#"{"name":"Updated name"}"#).unwrap();
let _ = crate::api::project::update(bot, key, update, None)
.apply()
.await;
}
#[tokio::test]
async fn try_to_create_and_delete_issue() {
dotenv().ok();
let bot = Rujira::new().from_env_handler();
let me = crate::api::myself::get(bot.clone()).apply().await;
assert!(me.is_ok());
let binding = me.unwrap();
let name = binding.data["displayName"].as_str();
let _ = crate::api::project::create(
bot.clone(),
"ITMG",
"iTmage",
"software",
name.expect("No name"),
)
.add_payload("description", json!("Custom field added by bot"))
.apply()
.await;
let project = crate::api::project::get(bot.clone(), "ITMG", None)
.add_payload("description", json!("Custom field added by bot"))
.apply()
.await;
assert!(project.is_ok());
assert!(!project.unwrap().data.is_null());
project_update(bot.clone(), "ITMG").await;
let project = crate::api::project::get(bot.clone(), "ITMG", None)
.apply()
.await;
let name = &project.unwrap().data["name"];
assert_eq!(name, "Updated name");
let fields = json!({
"project": { "key": "ITMG" },
"summary": "BOT: added a new feature.",
"description": "This task was generated by the bot when creating changes in the repository.",
"issuetype": { "name": "Task" },
});
let issue = crate::api::issue::create(bot.clone(), fields, true)
.apply()
.await;
assert!(issue.is_ok());
let project = crate::api::project::delete(bot.clone(), "ITMG")
.apply()
.await;
assert!(project.is_ok());
}