Return new task after adding a new one

This commit is contained in:
2022-01-27 14:07:15 +01:00
parent 0cb22f7dcd
commit d9cee2be40
4 changed files with 79 additions and 31 deletions

View File

@@ -1,21 +1,20 @@
pub mod test_helper;
use contextswitch_api::contextswitch::taskwarrior;
use contextswitch_types::Task;
use contextswitch_types::TaskDefinition;
use contextswitch_api::contextswitch;
use contextswitch_types::{ContextSwitchMetadata, NewTask, Task, TaskId};
use rstest::*;
use test_helper::app_address;
use uuid::Uuid;
#[rstest]
#[tokio::test]
async fn list_tasks(app_address: &str) {
let task_id =
taskwarrior::add_task(vec!["test", "list_tasks", "contextswitch:'{\"test\": 1}'"])
.await
.unwrap();
let task = contextswitch::add_task(vec!["test", "list_tasks", "contextswitch:'{\"test\": 1}'"])
.await
.unwrap();
let tasks: Vec<Task> = reqwest::Client::new()
.get(&format!("{}/tasks?filter={}", &app_address, task_id))
.get(&format!("{}/tasks?filter={}", &app_address, task.id))
.send()
.await
.expect("Failed to execute request")
@@ -34,7 +33,7 @@ async fn list_tasks(app_address: &str) {
async fn add_task(app_address: &str) {
let response: serde_json::Value = reqwest::Client::new()
.post(&format!("{}/tasks", &app_address))
.json(&TaskDefinition {
.json(&NewTask {
definition: "test add_task contextswitch:{\"test\":1}".to_string(),
})
.send()
@@ -43,14 +42,14 @@ async fn add_task(app_address: &str) {
.json()
.await
.expect("Cannot parse JSON result");
let new_task_id = response["id"].as_u64().unwrap();
let tasks = taskwarrior::list_tasks(vec![&new_task_id.to_string()]).unwrap();
let new_task_id = TaskId(Uuid::parse_str(response["id"].as_str().unwrap()).unwrap());
let tasks = contextswitch::list_tasks(vec![&new_task_id.to_string()]).unwrap();
assert_eq!(tasks.len(), 1);
assert_eq!(tasks[0].id, new_task_id);
assert_eq!(tasks[0].description, "test add_task");
assert_eq!(
tasks[0].contextswitch.as_ref().unwrap(),
&"{\"test\":1}".to_string()
&ContextSwitchMetadata { test: 1 }
);
}