Something went wrong. Try again.
A simple to-do app focused on tasks that can be completed within a specific time span. taskline.tobinio.dev
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270use serde_json::json;use types::organization::Organization;use uuid::Uuid;
use crate::common::{Client, get_server};
mod common;
#[tokio::test]async fn add_organization() { let server = get_server().await; let client = Client::new(&server);
let organization_uuid = Uuid::new_v4(); let organization = Organization { uuid: organization_uuid, name: "Test Organization".to_string(), };
let response = client .add_organization(json!( { "uuid": organization_uuid, "name": "Test Organization", } )) .await;
response.assert_status_success(); response.assert_json(&organization);
let response = client.get_organizations().await; response.assert_status_success(); let organizations: Vec<Organization> = response.json(); assert_eq!(organizations.len(), 1); assert_eq!(organizations.first().unwrap(), &organization);}
#[tokio::test]async fn add_organization_known_uuid() { let server = get_server().await; let client = Client::new(&server);
let organization_uuid = Uuid::new_v4();
client .add_organization_json(json!( { "uuid": organization_uuid, "name": "Test Organization", } )) .await;
let response = client .add_organization(json!( { "uuid": organization_uuid, "name": "Test Organization", } )) .await;
response.assert_status_bad_request();}
#[tokio::test]async fn add_invalid_organization() { let server = get_server().await; let client = Client::new(&server);
let organization_uuid = Uuid::new_v4();
let response = client .add_organization(json!( { "uuid": organization_uuid, } )) .await;
response.assert_status_unprocessable_entity();}
#[tokio::test]async fn leave_organization() { let server = get_server().await; let client = Client::new(&server);
let organization_uuid = Uuid::new_v4();
client .add_organization_json(json!( { "uuid": organization_uuid, "name": "Test Organization", } )) .await;
let response = client .leave_organization(json!( { "uuid": organization_uuid, } )) .await;
response.assert_status_success();
let organizations = client.get_organizations_json().await; assert_eq!(organizations.len(), 0);}
#[tokio::test]async fn leave_unknown_organization() { let server = get_server().await; let client = Client::new(&server);
let organization_uuid = Uuid::new_v4();
let response = client .leave_organization(json!( { "uuid": organization_uuid, } )) .await;
response.assert_status_bad_request();}
#[tokio::test]async fn join_organization() { let server = get_server().await; let client = Client::new(&server);
let organization_uuid = Uuid::new_v4();
client .add_organization_json(json!( { "uuid": organization_uuid, "name": "Test Organization", } )) .await;
client .leave_organization(json!( { "uuid": organization_uuid, } )) .await .assert_status_success();
let response = client .join_organization(json!( { "uuid": organization_uuid, } )) .await;
response.assert_status_success();
let organizations = client.get_organizations_json().await; assert_eq!(organizations.len(), 1);}
#[tokio::test]async fn join_unknown_organization() { let server = get_server().await; let client = Client::new(&server);
let organization_uuid = Uuid::new_v4();
let response = client .join_organization(json!( { "uuid": organization_uuid, } )) .await;
response.assert_status_bad_request();}
#[tokio::test]async fn join_already_joined_organization() { let server = get_server().await; let client = Client::new(&server);
let organization_uuid = Uuid::new_v4();
client .add_organization_json(json!( { "uuid": organization_uuid, "name": "Test Organization", } )) .await;
client .leave_organization(json!( { "uuid": organization_uuid, } )) .await .assert_status_success();
client .join_organization(json!( { "uuid": organization_uuid, } )) .await .assert_status_success();
let response = client .join_organization(json!( { "uuid": organization_uuid, } )) .await;
response.assert_status_bad_request();}
#[tokio::test]async fn leave_already_leaved_organization() { let server = get_server().await; let client = Client::new(&server);
let organization_uuid = Uuid::new_v4();
client .add_organization_json(json!( { "uuid": organization_uuid, "name": "Test Organization", } )) .await;
client .leave_organization(json!( { "uuid": organization_uuid, } )) .await .assert_status_success();
let response = client .leave_organization(json!( { "uuid": organization_uuid, } )) .await;
response.assert_status_bad_request();}