Add bookmarks to Contextswitch data
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
pub mod test_helper;
|
||||
|
||||
use contextswitch_api::contextswitch;
|
||||
use contextswitch_types::{ContextSwitchMetadata, NewTask, Task, TaskId};
|
||||
use contextswitch_types::{Bookmark, ContextswitchData, NewTask, Task, TaskId};
|
||||
use http::uri::Uri;
|
||||
use rstest::*;
|
||||
use test_helper::app_address;
|
||||
use uuid::Uuid;
|
||||
@@ -9,9 +10,13 @@ use uuid::Uuid;
|
||||
#[rstest]
|
||||
#[tokio::test]
|
||||
async fn list_tasks(app_address: &str) {
|
||||
let task = contextswitch::add_task(vec!["test", "list_tasks", "contextswitch:'{\"test\": 1}'"])
|
||||
.await
|
||||
.unwrap();
|
||||
let task = contextswitch::add_task(vec![
|
||||
"test",
|
||||
"list_tasks",
|
||||
"contextswitch:'{\"bookmarks\":[{\"uri\":\"https://example.com/path?filter=1\"}]}'",
|
||||
])
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let tasks: Vec<Task> = reqwest::Client::new()
|
||||
.get(&format!("{}/tasks?filter={}", &app_address, task.id))
|
||||
@@ -24,8 +29,69 @@ async fn list_tasks(app_address: &str) {
|
||||
|
||||
assert_eq!(tasks.len(), 1);
|
||||
assert_eq!(tasks[0].description, "test list_tasks");
|
||||
let cs_metadata = tasks[0].contextswitch.as_ref().unwrap();
|
||||
assert_eq!(cs_metadata.test, 1);
|
||||
let cs_data = tasks[0].contextswitch.as_ref().unwrap();
|
||||
assert_eq!(cs_data.bookmarks.len(), 1);
|
||||
assert_eq!(cs_data.bookmarks[0].content, None);
|
||||
assert_eq!(
|
||||
cs_data.bookmarks[0].uri,
|
||||
"https://example.com/path?filter=1".parse::<Uri>().unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[tokio::test]
|
||||
async fn list_tasks_with_unknown_contextswitch_data(app_address: &str) {
|
||||
let task = contextswitch::add_task(vec![
|
||||
"test",
|
||||
"list_tasks_with_unknown_contextswitch_data",
|
||||
"contextswitch:'{\"unknown\": 1}'",
|
||||
])
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let tasks: Vec<Task> = reqwest::Client::new()
|
||||
.get(&format!("{}/tasks?filter={}", &app_address, task.id))
|
||||
.send()
|
||||
.await
|
||||
.expect("Failed to execute request")
|
||||
.json()
|
||||
.await
|
||||
.expect("Cannot parse JSON result");
|
||||
|
||||
assert_eq!(tasks.len(), 1);
|
||||
assert_eq!(
|
||||
tasks[0].description,
|
||||
"test list_tasks_with_unknown_contextswitch_data"
|
||||
);
|
||||
assert!(tasks[0].contextswitch.is_none());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[tokio::test]
|
||||
async fn list_tasks_with_invalid_contextswitch_data(app_address: &str) {
|
||||
let task = contextswitch::add_task(vec![
|
||||
"test",
|
||||
"list_tasks_with_invalid_contextswitch_data",
|
||||
"contextswitch:'}'",
|
||||
])
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let tasks: Vec<Task> = reqwest::Client::new()
|
||||
.get(&format!("{}/tasks?filter={}", &app_address, task.id))
|
||||
.send()
|
||||
.await
|
||||
.expect("Failed to execute request")
|
||||
.json()
|
||||
.await
|
||||
.expect("Cannot parse JSON result");
|
||||
|
||||
assert_eq!(tasks.len(), 1);
|
||||
assert_eq!(
|
||||
tasks[0].description,
|
||||
"test list_tasks_with_invalid_contextswitch_data"
|
||||
);
|
||||
assert!(tasks[0].contextswitch.is_none());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
@@ -34,7 +100,9 @@ async fn add_task(app_address: &str) {
|
||||
let response: serde_json::Value = reqwest::Client::new()
|
||||
.post(&format!("{}/tasks", &app_address))
|
||||
.json(&NewTask {
|
||||
definition: "test add_task contextswitch:{\"test\":1}".to_string(),
|
||||
definition:
|
||||
"test add_task contextswitch:{\"bookmarks\":[{\"uri\":\"https://example.com/path?filter=1\"}]}"
|
||||
.to_string(),
|
||||
})
|
||||
.send()
|
||||
.await
|
||||
@@ -50,6 +118,11 @@ async fn add_task(app_address: &str) {
|
||||
assert_eq!(tasks[0].description, "test add_task");
|
||||
assert_eq!(
|
||||
tasks[0].contextswitch.as_ref().unwrap(),
|
||||
&ContextSwitchMetadata { test: 1 }
|
||||
&ContextswitchData {
|
||||
bookmarks: vec![Bookmark {
|
||||
uri: "https://example.com/path?filter=1".parse::<Uri>().unwrap(),
|
||||
content: None
|
||||
}]
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user