From a1bb7c0acc98f35a36b3b3d2dcfbc250b0b7dd24 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Mon, 16 Sep 2024 16:33:15 +0300 Subject: [PATCH] sdk: add account deactivation tests --- .../matrix-sdk/tests/integration/account.rs | 62 +++++++++++++++++++ crates/matrix-sdk/tests/integration/main.rs | 1 + 2 files changed, 63 insertions(+) create mode 100644 crates/matrix-sdk/tests/integration/account.rs diff --git a/crates/matrix-sdk/tests/integration/account.rs b/crates/matrix-sdk/tests/integration/account.rs new file mode 100644 index 000000000..d87074e28 --- /dev/null +++ b/crates/matrix-sdk/tests/integration/account.rs @@ -0,0 +1,62 @@ +use assert_matches::assert_matches; +use matrix_sdk_test::async_test; +use serde_json::json; +use wiremock::{ + matchers::{method, path}, + Mock, Request, ResponseTemplate, +}; + +use crate::logged_in_client_with_server; + +#[async_test] +async fn test_account_deactivation() { + #[derive(serde::Deserialize)] + struct Parameters { + pub id_server: Option, + pub erase: Option, + } + + let (client, server) = logged_in_client_with_server().await; + + { + let _scope = Mock::given(method("POST")) + .and(path("/_matrix/client/r0/account/deactivate")) + .respond_with(|req: &Request| { + let params: Parameters = req.body_json().unwrap(); + assert_eq!(params.id_server, Some("FirstIdentityServer".to_owned())); + assert_eq!(params.erase, None); + + ResponseTemplate::new(200).set_body_json(json!({ + "id_server_unbind_result": "success" + })) + }) + .expect(1) + .mount_as_scoped(&server) + .await; + + assert!(client + .account() + .deactivate(Some("FirstIdentityServer"), None, false) + .await + .is_ok()); + } + + { + let _scope = Mock::given(method("POST")) + .and(path("/_matrix/client/r0/account/deactivate")) + .respond_with(|req: &Request| { + let params: Parameters = req.body_json().unwrap(); + assert_eq!(params.id_server, None); + assert_eq!(params.erase, Some(true)); + + ResponseTemplate::new(200).set_body_json(json!({ + "id_server_unbind_result": "success" + })) + }) + .expect(1) + .mount_as_scoped(&server) + .await; + + assert!(client.account().deactivate(None, None, true).await.is_ok()); + } +} diff --git a/crates/matrix-sdk/tests/integration/main.rs b/crates/matrix-sdk/tests/integration/main.rs index 69b79b05f..9192d0233 100644 --- a/crates/matrix-sdk/tests/integration/main.rs +++ b/crates/matrix-sdk/tests/integration/main.rs @@ -10,6 +10,7 @@ use wiremock::{ Mock, MockGuard, MockServer, ResponseTemplate, }; +mod account; mod client; #[cfg(feature = "e2e-encryption")] mod encryption;