From 8b36ceb3c92fdf98e080ecfb66fdf4301de61f93 Mon Sep 17 00:00:00 2001
From: Timofey Myagkikh <rdcm@protonmail.ch>
Date: Mon, 13 Nov 2023 03:14:53 +0300
Subject: [PATCH] cleanup

---
 Cargo.toml                                    |  2 +-
 .../Cargo.toml                                |  0
 .../tests/gen.rs                              |  0
 .../tests/sut.rs                              | 26 +++++++------------
 .../tests/user_tests.rs                       |  0
 run_tests.sh                                  |  2 +-
 6 files changed, 12 insertions(+), 18 deletions(-)
 rename {integrtion-tests => integration-tests}/Cargo.toml (100%)
 rename {integrtion-tests => integration-tests}/tests/gen.rs (100%)
 rename {integrtion-tests => integration-tests}/tests/sut.rs (80%)
 rename {integrtion-tests => integration-tests}/tests/user_tests.rs (100%)

diff --git a/Cargo.toml b/Cargo.toml
index 70ebe64..f62f385 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,7 +6,7 @@ members = [
     "domain_impl",
     "host",
     "infra",
-    "integrtion-tests",
+    "integration-tests",
     "acl"
 ]
 
diff --git a/integrtion-tests/Cargo.toml b/integration-tests/Cargo.toml
similarity index 100%
rename from integrtion-tests/Cargo.toml
rename to integration-tests/Cargo.toml
diff --git a/integrtion-tests/tests/gen.rs b/integration-tests/tests/gen.rs
similarity index 100%
rename from integrtion-tests/tests/gen.rs
rename to integration-tests/tests/gen.rs
diff --git a/integrtion-tests/tests/sut.rs b/integration-tests/tests/sut.rs
similarity index 80%
rename from integrtion-tests/tests/sut.rs
rename to integration-tests/tests/sut.rs
index feb1047..5db436e 100644
--- a/integrtion-tests/tests/sut.rs
+++ b/integration-tests/tests/sut.rs
@@ -44,12 +44,10 @@ impl Sut {
 
         let response = client.get(uri).send().await.unwrap();
 
-        if response.status() == StatusCode::OK {
-            let user: UserResponse = response.json().await.unwrap();
-
-            Ok(user)
-        } else {
-            Err(response.text().await.unwrap())
+        match response.status() {
+            StatusCode::OK => Ok(response.json().await.unwrap()),
+            StatusCode::BAD_REQUEST => Err(response.text().await.unwrap()),
+            code => Err(format!("unexpected status code {}", code))
         }
     }
 
@@ -68,12 +66,9 @@ impl Sut {
             .await
             .unwrap();
 
-        if response.status() == StatusCode::CREATED {
-            let user: CreatedUserIdResponse = response.json().await.unwrap();
-
-            Ok(user)
-        } else {
-            Err(response.text().await.unwrap())
+        match response.status() {
+            StatusCode::CREATED => Ok(response.json().await.unwrap()),
+            code => Err(format!("unexpected status code {}", code))
         }
     }
 
@@ -83,10 +78,9 @@ impl Sut {
 
         let response = client.post(uri).json(&activity).send().await.unwrap();
 
-        if response.status() == StatusCode::OK {
-            Ok(())
-        } else {
-            Err(response.text().await.unwrap())
+        match response.status() {
+            StatusCode::OK => Ok(()),
+            code => Err(format!("unexpected status code {}", code))
         }
     }
 
diff --git a/integrtion-tests/tests/user_tests.rs b/integration-tests/tests/user_tests.rs
similarity index 100%
rename from integrtion-tests/tests/user_tests.rs
rename to integration-tests/tests/user_tests.rs
diff --git a/run_tests.sh b/run_tests.sh
index c140727..4d24163 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -20,7 +20,7 @@ cargo test --workspace
 find . -path "*/${timestamp}/*" -name '*.profraw' -exec mv {} "./${directory_path}" \;
 
 # generate report
-grcov "${directory_path}" --binary-path target/debug -s . -o "${directory_path}" --ignore "target/debug/*" --ignore "integrtion-tests/*" --output-types html
+grcov "${directory_path}" --binary-path target/debug -s . -o "${directory_path}" --ignore "target/debug/*" --ignore "integration-tests/*" --output-types html
 
 # open report
 open "./${directory_path}/html/index.html"
\ No newline at end of file