From e4d5a753bce9e35e74fcd1c7ee975a4ad3161748 Mon Sep 17 00:00:00 2001 From: tobinio Date: Fri, 1 May 2026 20:26:20 +0200 Subject: [PATCH] update & move tests --- api/tests/common/client.rs | 4 ++ api/tests/todos.rs | 2 + api/tests/todos/postion.rs | 144 +++++++++++++++++++++++++++++++++++++ api/tests/todos/update.rs | 91 +++++++++++++++++++++++ 4 files changed, 241 insertions(+) create mode 100644 api/tests/todos/postion.rs create mode 100644 api/tests/todos/update.rs diff --git a/api/tests/common/client.rs b/api/tests/common/client.rs index d0c3955..7e899df 100644 --- a/api/tests/common/client.rs +++ b/api/tests/common/client.rs @@ -127,6 +127,10 @@ impl Client { pub async fn delete_category_json(&self, category_uuid: Uuid) -> Category { Self::json(self.delete_category(category_uuid).await).await } + + pub async fn move_todo(&self, value: serde_json::Value) -> Response { + self.post_json("todos/move", value).await + } } pub fn get_client() -> Client { diff --git a/api/tests/todos.rs b/api/tests/todos.rs index 9b07618..64e5fe9 100644 --- a/api/tests/todos.rs +++ b/api/tests/todos.rs @@ -5,5 +5,7 @@ mod todos { mod check; mod delete; mod get; + mod postion; mod sse; + mod update; } diff --git a/api/tests/todos/postion.rs b/api/tests/todos/postion.rs new file mode 100644 index 0000000..164b3bf --- /dev/null +++ b/api/tests/todos/postion.rs @@ -0,0 +1,144 @@ +use crate::common::{client::get_client, db::clear_db}; +use serde_json::json; +use serial_test::serial; +use uuid::Uuid; + +#[tokio::test] +#[serial] +async fn move_todo() { + let client = get_client(); + clear_db().await; + + let todo1_uuid = Uuid::new_v4(); + let todo2_uuid = Uuid::new_v4(); + let todo3_uuid = Uuid::new_v4(); + + client + .add_todo_json(json!( + { + "data": { + "uuid": todo1_uuid, + "title": "Test Todo", + "note": "Test Note", + "tags": [], + "checks": [], + } + } + )) + .await; + client + .add_todo_json(json!( + { + "data": { + "uuid": todo2_uuid, + "title": "Test Todo", + "note": "Test Note", + "tags": [], + "checks": [], + }, + } + )) + .await; + client + .add_todo_json(json!( + { + "data": { + "uuid": todo3_uuid, + "title": "Test Todo", + "note": "Test Note", + "tags": [], + "checks": [], + }, + } + )) + .await; + + client + .move_todo(json!({ "toMove": todo1_uuid, "to": todo3_uuid })) + .await; + + let todos = client.get_todos_json().await; + assert_eq!(todos.len(), 3); + assert_eq!(todos[0].uuid, todo1_uuid); + assert_eq!(todos[1].uuid, todo3_uuid); + assert_eq!(todos[2].uuid, todo2_uuid); + + client + .move_todo(json!({ "toMove": todo2_uuid, "to": todo1_uuid })) + .await; + + let todos = client.get_todos_json().await; + assert_eq!(todos.len(), 3); + assert_eq!(todos[0].uuid, todo2_uuid); + assert_eq!(todos[1].uuid, todo1_uuid); + assert_eq!(todos[2].uuid, todo3_uuid); + + client + .move_todo(json!({ "toMove": todo1_uuid, "to": todo3_uuid })) + .await; + + let todos = client.get_todos_json().await; + assert_eq!(todos.len(), 3); + assert_eq!(todos[0].uuid, todo2_uuid); + assert_eq!(todos[1].uuid, todo3_uuid); + assert_eq!(todos[2].uuid, todo1_uuid); +} + +#[tokio::test] +#[serial] +async fn invalid_move_todo() { + let client = get_client(); + clear_db().await; + + let todo1_uuid = Uuid::new_v4(); + let todo2_uuid = Uuid::new_v4(); + let todo3_uuid = Uuid::new_v4(); + + client + .add_todo_json(json!( + { + "data": { + "uuid": todo1_uuid, + "title": "Test Todo", + "note": "Test Note", + "tags": [], + "checks": [], + } + } + )) + .await; + client + .add_todo_json(json!( + { + "data": { + "uuid": todo2_uuid, + "title": "Test Todo", + "note": "Test Note", + "tags": [], + "checks": [], + }, + } + )) + .await; + client + .add_todo_json(json!( + { + "data": { + "uuid": todo3_uuid, + "title": "Test Todo", + "note": "Test Note", + "tags": [], + "checks": [], + }, + } + )) + .await; + + let response = client + .move_todo(json!({ "toMove": "unknown", "to": todo3_uuid })) + .await; + assert_eq!(response.status().as_str(), "404"); + + let response = client.move_todo(json!({ "toMove": "unknown" })).await; + assert_eq!(response.status().as_str(), "400"); +} diff --git a/api/tests/todos/update.rs b/api/tests/todos/update.rs new file mode 100644 index 0000000..863610f --- /dev/null +++ b/api/tests/todos/update.rs @@ -0,0 +1,91 @@ +use crate::common::{client::get_client, db::clear_db}; +use serde_json::json; +use serial_test::serial; +use uuid::Uuid; + +#[tokio::test] +#[serial] +async fn update_todos() { + let client = get_client(); + clear_db().await; + + let todo_uuid = Uuid::new_v4(); + let tag_uuid = Uuid::new_v4(); + + client + .add_todo_json(json!( + { + "data": { + "uuid": todo_uuid, + "title": "Test Todo", + "note": "Test Note", + "tags": [], + "checks": [], + } + } + )) + .await; + + client + .add_todo_json(json!( + { + "data": { + "uuid": todo_uuid, + "title": "updated Todo", + "note": "Test Note", + "tags": [tag_uuid], + "checks": [], + } + } + )) + .await; + + let todos = client.get_todos_json().await; + + assert_eq!(todos.len(), 1); + assert_eq!(todos[0].uuid, todo_uuid); + assert_eq!(todos[0].title, "updated Todo"); + assert_eq!(todos[0].tags.len(), 1); + assert_eq!(todos[0].tags[0], tag_uuid); +} + +#[tokio::test] +#[serial] +async fn update_invalid_todos() { + let client = get_client(); + clear_db().await; + + let todo_uuid = Uuid::new_v4(); + + client + .add_todo_json(json!( + { + "data": { + "uuid": todo_uuid, + "title": "Test Todo", + "note": "Test Note", + "tags": [], + "checks": [], + } + } + )) + .await; + + let response = client + .add_todo(json!( + { + "data": { + "uuid": todo_uuid, + "title": "updated Todo", + } + } + )) + .await; + assert_eq!(response.status().as_str(), "400"); + + let todos = client.get_todos_json().await; + + assert_eq!(todos.len(), 1); + assert_eq!(todos[0].uuid, todo_uuid); + assert_eq!(todos[0].title, "Test Todo"); +} -- 2.51.2