changes tests to a macro (#822)

This commit is contained in:
Wyatt Verchere
2024-01-06 11:08:03 -08:00
committed by GitHub
parent 10eed05d87
commit 87862f3e23
32 changed files with 423 additions and 391 deletions

View File

@@ -1,15 +1,17 @@
use std::sync::Arc;
use crate::common::{
api_common::{ApiProject, ApiVersion, AppendsOptionalPat},
api_v2::{request_data::get_public_project_creation_data_json, ApiV2},
asserts::assert_status,
database::{
generate_random_name, ADMIN_USER_PAT, FRIEND_USER_ID, FRIEND_USER_PAT, USER_USER_PAT,
use crate::{
assert_status,
common::{
api_common::{ApiProject, ApiVersion, AppendsOptionalPat},
api_v2::{request_data::get_public_project_creation_data_json, ApiV2},
database::{
generate_random_name, ADMIN_USER_PAT, FRIEND_USER_ID, FRIEND_USER_PAT, USER_USER_PAT,
},
dummy_data::TestFile,
environment::{with_test_environment, TestEnvironment},
permissions::{PermissionsTest, PermissionsTestContext},
},
dummy_data::TestFile,
environment::{with_test_environment, TestEnvironment},
permissions::{PermissionsTest, PermissionsTestContext},
};
use actix_http::StatusCode;
use actix_web::test;
@@ -134,7 +136,7 @@ async fn test_add_remove_project() {
.set_multipart(vec![json_segment.clone(), file_segment.clone()])
.to_request();
let resp: actix_web::dev::ServiceResponse = test_env.call(req).await;
assert_status(&resp, StatusCode::OK);
assert_status!(&resp, StatusCode::OK);
// Get the project we just made, and confirm that it's correct
let project = api.get_project_deserialized("demo", USER_USER_PAT).await;
@@ -162,7 +164,7 @@ async fn test_add_remove_project() {
.to_request();
let resp = test_env.call(req).await;
assert_status(&resp, StatusCode::BAD_REQUEST);
assert_status!(&resp, StatusCode::BAD_REQUEST);
// Reusing with the same slug and a different file should fail
let req = test::TestRequest::post()
@@ -175,7 +177,7 @@ async fn test_add_remove_project() {
.to_request();
let resp = test_env.call(req).await;
assert_status(&resp, StatusCode::BAD_REQUEST);
assert_status!(&resp, StatusCode::BAD_REQUEST);
// Different slug, different file should succeed
let req = test::TestRequest::post()
@@ -188,7 +190,7 @@ async fn test_add_remove_project() {
.to_request();
let resp = test_env.call(req).await;
assert_status(&resp, StatusCode::OK);
assert_status!(&resp, StatusCode::OK);
// Get
let project = api.get_project_deserialized("demo", USER_USER_PAT).await;
@@ -196,7 +198,7 @@ async fn test_add_remove_project() {
// Remove the project
let resp = test_env.api.remove_project("demo", USER_USER_PAT).await;
assert_status(&resp, StatusCode::NO_CONTENT);
assert_status!(&resp, StatusCode::NO_CONTENT);
// Confirm that the project is gone from the cache
let mut redis_conn = test_env.db.redis_pool.connect().await.unwrap();
@@ -219,7 +221,7 @@ async fn test_add_remove_project() {
// Old slug no longer works
let resp = api.get_project("demo", USER_USER_PAT).await;
assert_status(&resp, StatusCode::NOT_FOUND);
assert_status!(&resp, StatusCode::NOT_FOUND);
})
.await;
}
@@ -343,7 +345,7 @@ pub async fn test_patch_v2() {
USER_USER_PAT,
)
.await;
assert_status(&resp, StatusCode::NO_CONTENT);
assert_status!(&resp, StatusCode::NO_CONTENT);
let project = api
.get_project_deserialized(alpha_project_slug, USER_USER_PAT)
@@ -455,7 +457,7 @@ pub async fn test_bulk_edit_links() {
ADMIN_USER_PAT,
)
.await;
assert_status(&resp, StatusCode::NO_CONTENT);
assert_status!(&resp, StatusCode::NO_CONTENT);
let alpha_body = api
.get_project_deserialized(alpha_project_id, ADMIN_USER_PAT)
@@ -495,7 +497,7 @@ pub async fn test_bulk_edit_links() {
ADMIN_USER_PAT,
)
.await;
assert_status(&resp, StatusCode::NO_CONTENT);
assert_status!(&resp, StatusCode::NO_CONTENT);
let alpha_body = api
.get_project_deserialized(alpha_project_id, ADMIN_USER_PAT)
@@ -567,7 +569,7 @@ pub async fn test_bulk_edit_links() {
ADMIN_USER_PAT,
)
.await;
assert_status(&resp, StatusCode::NO_CONTENT);
assert_status!(&resp, StatusCode::NO_CONTENT);
let alpha_body = api
.get_project_deserialized(alpha_project_id, ADMIN_USER_PAT)