From a51028c4c8f534f54289b3e0a8a7e1ad78b2f4a6 Mon Sep 17 00:00:00 2001 From: Konrad Kohbrok Date: Thu, 3 Aug 2023 15:06:36 +0200 Subject: [PATCH] file renaming --- .../test_scenarios/basic_group_operations.rs | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 test_harness/src/test_scenarios/basic_group_operations.rs diff --git a/test_harness/src/test_scenarios/basic_group_operations.rs b/test_harness/src/test_scenarios/basic_group_operations.rs new file mode 100644 index 00000000..9e7a2862 --- /dev/null +++ b/test_harness/src/test_scenarios/basic_group_operations.rs @@ -0,0 +1,68 @@ +// SPDX-FileCopyrightText: 2023 Phoenix R&D GmbH +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +use phnxbackend::qs::Fqdn; + +use crate::utils::setup::TestBed; + +pub(super) const NUMBER_OF_SERVERS: usize = 2; + +impl TestBed { + async fn create_alice_and_bob(&mut self, domains: &[Fqdn]) -> (String, String) { + let alice_name = format!("alice@{}", domains[0]); + self.add_user(alice_name.clone()).await; + let bob_name = format!("bob@{}", domains[1]); + self.add_user(bob_name.clone()).await; + (alice_name, bob_name) + } + + pub(crate) async fn create_and_connect_alice_and_bob( + &mut self, + domains: &[Fqdn], + ) -> (String, String) { + let (alice_name, bob_name) = self.create_alice_and_bob(domains).await; + self.connect_users(&alice_name, &bob_name).await; + (alice_name, bob_name) + } +} + +/// This function is meant to be called from the test container. It registers +/// two clients, one on each test server and makes them perform the requests +/// required to connect the two. Before running the test, it waits for the +/// health check to succeed on both servers. +pub async fn connect_users_runner(domains: &[Fqdn]) { + let mut test_bed = TestBed::new().await; + test_bed.create_and_connect_alice_and_bob(domains).await; +} + +pub async fn invite_to_group_runner(domains: &[Fqdn]) { + let mut test_bed = TestBed::new().await; + let (alice_name, bob_name) = test_bed.create_and_connect_alice_and_bob(domains).await; + let conversation_id = test_bed.create_group(&alice_name).await; + test_bed + .invite_to_group(conversation_id, &alice_name, vec![&bob_name]) + .await; +} + +pub async fn remove_from_group_runner(domains: &[Fqdn]) { + let mut test_bed = TestBed::new().await; + let (alice_name, bob_name) = test_bed.create_and_connect_alice_and_bob(domains).await; + let conversation_id = test_bed.create_group(&alice_name).await; + test_bed + .invite_to_group(conversation_id, &alice_name, vec![&bob_name]) + .await; + test_bed + .remove_from_group(conversation_id, &alice_name, vec![&bob_name]) + .await; +} + +pub async fn leave_group_runner(domains: &[Fqdn]) { + let mut test_bed = TestBed::new().await; + let (alice_name, bob_name) = test_bed.create_and_connect_alice_and_bob(domains).await; + let conversation_id = test_bed.create_group(&alice_name).await; + test_bed + .invite_to_group(conversation_id, &alice_name, vec![&bob_name]) + .await; + test_bed.leave_group(conversation_id, &bob_name).await +}