You've already forked AstralRinth
forked from didirus/AstralRinth
Fixes failing tests (#813)
* fixes failing tests * fmt clippy * updated dockerfile * fixes failing tests; adds important fix from extracts_versions PR * assert_eq -> assert_status, giving better error messages * fixed random failure bug * fmt, clippy, etc
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
use crate::common::{
|
||||
api_common::{ApiProject, ApiTeams},
|
||||
asserts::assert_status,
|
||||
database::{
|
||||
generate_random_name, ADMIN_USER_PAT, ENEMY_USER_ID_PARSED, ENEMY_USER_PAT,
|
||||
FRIEND_USER_ID_PARSED, MOD_USER_ID, MOD_USER_PAT, USER_USER_ID, USER_USER_ID_PARSED,
|
||||
},
|
||||
dummy_data::{DummyImage, DummyOrganizationZeta, DummyProjectAlpha, DummyProjectBeta},
|
||||
};
|
||||
use actix_http::StatusCode;
|
||||
use common::{
|
||||
api_v3::ApiV3,
|
||||
database::{FRIEND_USER_ID, FRIEND_USER_PAT, USER_USER_PAT},
|
||||
@@ -27,45 +29,61 @@ async fn create_organization() {
|
||||
let zeta_organization_slug = &test_env.dummy.organization_zeta.organization_id;
|
||||
|
||||
// Failed creations title:
|
||||
// - too short title
|
||||
// - too long title
|
||||
for title in ["a", &"a".repeat(100)] {
|
||||
let resp = api
|
||||
.create_organization(title, "theta", "theta_description", USER_USER_PAT)
|
||||
.await;
|
||||
assert_status(&resp, StatusCode::BAD_REQUEST);
|
||||
}
|
||||
|
||||
// Failed creations slug:
|
||||
// - slug collision with zeta
|
||||
// - too short slug
|
||||
// - too long slug
|
||||
// - not url safe slug
|
||||
for title in [
|
||||
for slug in [
|
||||
zeta_organization_slug,
|
||||
"a",
|
||||
&"a".repeat(100),
|
||||
"not url safe%&^!#$##!@#$%^&*()",
|
||||
] {
|
||||
let resp = api
|
||||
.create_organization(title, "theta_description", USER_USER_PAT)
|
||||
.create_organization("Theta Org", slug, "theta_description", USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 400);
|
||||
assert_status(&resp, StatusCode::BAD_REQUEST);
|
||||
}
|
||||
|
||||
// Failed creations description:
|
||||
// - too short slug
|
||||
// - too long slug
|
||||
// - too short desc
|
||||
// - too long desc
|
||||
for description in ["a", &"a".repeat(300)] {
|
||||
let resp = api
|
||||
.create_organization("theta", description, USER_USER_PAT)
|
||||
.create_organization("Theta Org", "theta", description, USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 400);
|
||||
assert_status(&resp, StatusCode::BAD_REQUEST);
|
||||
}
|
||||
|
||||
// Create 'theta' organization
|
||||
let resp = api
|
||||
.create_organization("theta", "not url safe%&^!#$##!@#$%^&", USER_USER_PAT)
|
||||
.create_organization(
|
||||
"Theta Org",
|
||||
"theta",
|
||||
"not url safe%&^!#$##!@#$%^&",
|
||||
USER_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 200);
|
||||
assert_status(&resp, StatusCode::OK);
|
||||
|
||||
// Get organization using slug
|
||||
let theta = api
|
||||
.get_organization_deserialized("theta", USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(theta.name, "theta");
|
||||
assert_eq!(theta.name, "Theta Org");
|
||||
assert_eq!(theta.slug, "theta");
|
||||
assert_eq!(theta.description, "not url safe%&^!#$##!@#$%^&");
|
||||
assert_eq!(resp.status(), 200);
|
||||
assert_status(&resp, StatusCode::OK);
|
||||
|
||||
// Get created team
|
||||
let members = api
|
||||
@@ -95,7 +113,7 @@ async fn get_project_organization() {
|
||||
let resp = api
|
||||
.organization_add_project(zeta_organization_id, alpha_project_id, USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 200);
|
||||
assert_status(&resp, StatusCode::OK);
|
||||
|
||||
// Get project organization
|
||||
let zeta = api
|
||||
@@ -115,9 +133,25 @@ async fn patch_organization() {
|
||||
|
||||
// Create 'theta' organization
|
||||
let resp = api
|
||||
.create_organization("theta", "theta_description", USER_USER_PAT)
|
||||
.create_organization("Theta Org", "theta", "theta_description", USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 200);
|
||||
assert_status(&resp, StatusCode::OK);
|
||||
|
||||
// Failed patch to theta title:
|
||||
// - too short title
|
||||
// - too long title
|
||||
for title in ["a", &"a".repeat(100)] {
|
||||
let resp = api
|
||||
.edit_organization(
|
||||
"theta",
|
||||
json!({
|
||||
"name": title,
|
||||
}),
|
||||
USER_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
assert_status(&resp, StatusCode::BAD_REQUEST);
|
||||
}
|
||||
|
||||
// Failed patch to zeta slug:
|
||||
// - slug collision with theta
|
||||
@@ -134,13 +168,13 @@ async fn patch_organization() {
|
||||
.edit_organization(
|
||||
zeta_organization_id,
|
||||
json!({
|
||||
"name": title,
|
||||
"slug": title,
|
||||
"description": "theta_description"
|
||||
}),
|
||||
USER_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 400);
|
||||
assert_status(&resp, StatusCode::BAD_REQUEST);
|
||||
}
|
||||
|
||||
// Failed patch to zeta description:
|
||||
@@ -156,7 +190,7 @@ async fn patch_organization() {
|
||||
USER_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 400);
|
||||
assert_status(&resp, StatusCode::BAD_REQUEST);
|
||||
}
|
||||
|
||||
// Successful patch to many fields
|
||||
@@ -165,18 +199,20 @@ async fn patch_organization() {
|
||||
zeta_organization_id,
|
||||
json!({
|
||||
"name": "new_title",
|
||||
"slug": "new_slug",
|
||||
"description": "not url safe%&^!#$##!@#$%^&" // not-URL-safe description should still work
|
||||
}),
|
||||
USER_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
|
||||
// Get project using new slug
|
||||
let new_title = api
|
||||
.get_organization_deserialized("new_title", USER_USER_PAT)
|
||||
.get_organization_deserialized("new_slug", USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(new_title.name, "new_title");
|
||||
assert_eq!(new_title.slug, "new_slug");
|
||||
assert_eq!(new_title.description, "not url safe%&^!#$##!@#$%^&");
|
||||
})
|
||||
.await;
|
||||
@@ -185,7 +221,7 @@ async fn patch_organization() {
|
||||
// add/remove icon
|
||||
#[actix_rt::test]
|
||||
async fn add_remove_icon() {
|
||||
with_test_environment(None, |test_env: TestEnvironment<ApiV3>| async move {
|
||||
with_test_environment(Some(10), |test_env: TestEnvironment<ApiV3>| async move {
|
||||
let api = &test_env.api;
|
||||
let zeta_organization_id = &test_env.dummy.organization_zeta.organization_id;
|
||||
|
||||
@@ -205,7 +241,7 @@ async fn add_remove_icon() {
|
||||
USER_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
|
||||
// Get project
|
||||
let zeta_org = api
|
||||
@@ -218,7 +254,7 @@ async fn add_remove_icon() {
|
||||
let resp = api
|
||||
.edit_organization_icon(zeta_organization_id, None, USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
|
||||
// Get project
|
||||
let zeta_org = api
|
||||
@@ -239,13 +275,13 @@ async fn delete_org() {
|
||||
let resp = api
|
||||
.delete_organization(zeta_organization_id, USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
|
||||
// Get organization, which should no longer exist
|
||||
let resp = api
|
||||
.get_organization(zeta_organization_id, USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 404);
|
||||
assert_status(&resp, StatusCode::NOT_FOUND);
|
||||
})
|
||||
.await;
|
||||
}
|
||||
@@ -264,7 +300,7 @@ async fn add_remove_organization_projects() {
|
||||
.api
|
||||
.organization_add_project(zeta_organization_id, alpha, USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 200);
|
||||
assert_status(&resp, StatusCode::OK);
|
||||
|
||||
// Get organization projects
|
||||
let projects = test_env
|
||||
@@ -284,7 +320,7 @@ async fn add_remove_organization_projects() {
|
||||
USER_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 200);
|
||||
assert_status(&resp, StatusCode::OK);
|
||||
|
||||
// Get organization projects
|
||||
let projects = test_env
|
||||
@@ -338,11 +374,11 @@ async fn add_remove_organization_project_ownership_to_user() {
|
||||
USER_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
|
||||
// Accept invites
|
||||
let resp = test_env.api.join_team(team, FRIEND_USER_PAT).await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
}
|
||||
|
||||
// For each team, confirm there are two members, but only one owner of the project, and it is USER_USER_ID
|
||||
@@ -362,7 +398,7 @@ async fn add_remove_organization_project_ownership_to_user() {
|
||||
.api
|
||||
.transfer_team_ownership(beta_team_id, FRIEND_USER_ID, USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
|
||||
// Confirm there are still two users, but now FRIEND_USER_ID is the owner
|
||||
let members = test_env
|
||||
@@ -383,7 +419,7 @@ async fn add_remove_organization_project_ownership_to_user() {
|
||||
.api
|
||||
.organization_add_project(zeta_organization_id, project_id, pat)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 200);
|
||||
assert_status(&resp, StatusCode::OK);
|
||||
|
||||
// Get and confirm it has been added
|
||||
let project = test_env.api.get_project_deserialized(project_id, pat).await;
|
||||
@@ -416,7 +452,7 @@ async fn add_remove_organization_project_ownership_to_user() {
|
||||
.api
|
||||
.transfer_team_ownership(zeta_team_id, FRIEND_USER_ID, USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
|
||||
// Confirm there are no members of the alpha project OR the beta project
|
||||
// - Friend was removed as a member of these projects when ownership was transferred to them
|
||||
@@ -433,14 +469,14 @@ async fn add_remove_organization_project_ownership_to_user() {
|
||||
.api
|
||||
.add_user_to_team(alpha_team_id, FRIEND_USER_ID, None, None, USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 400);
|
||||
assert_status(&resp, StatusCode::BAD_REQUEST);
|
||||
|
||||
// As friend, can add user to alpha project, as they are not the org owner
|
||||
let resp = test_env
|
||||
.api
|
||||
.add_user_to_team(alpha_team_id, USER_USER_ID, None, None, FRIEND_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
|
||||
// At this point, friend owns the org
|
||||
// Alpha member has user as a member, but not as an owner
|
||||
@@ -457,7 +493,7 @@ async fn add_remove_organization_project_ownership_to_user() {
|
||||
USER_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 400);
|
||||
assert_status(&resp, StatusCode::BAD_REQUEST);
|
||||
|
||||
// Set user's permissions within the project that it is a member of to none (for a later test)
|
||||
let resp = test_env
|
||||
@@ -471,7 +507,7 @@ async fn add_remove_organization_project_ownership_to_user() {
|
||||
FRIEND_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
|
||||
// Remove project from organization with a user that is an organization member, and a project member
|
||||
// This should succeed
|
||||
@@ -484,7 +520,7 @@ async fn add_remove_organization_project_ownership_to_user() {
|
||||
USER_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 200);
|
||||
assert_status(&resp, StatusCode::OK);
|
||||
|
||||
// Remove project from organization with a user that is an organization member, but not a project member
|
||||
// This should succeed
|
||||
@@ -497,7 +533,7 @@ async fn add_remove_organization_project_ownership_to_user() {
|
||||
USER_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 200);
|
||||
assert_status(&resp, StatusCode::OK);
|
||||
|
||||
// For each of alpha and beta, confirm:
|
||||
// - There is one member of each project, the owner, USER_USER_ID
|
||||
@@ -559,11 +595,11 @@ async fn delete_organization_means_all_projects_to_org_owner() {
|
||||
.api
|
||||
.add_user_to_team(zeta_team_id, FRIEND_USER_ID, None, None, USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
|
||||
// Accept invite
|
||||
let resp = test_env.api.join_team(zeta_team_id, FRIEND_USER_PAT).await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
|
||||
// Confirm there is only one owner of the project, and it is USER_USER_ID
|
||||
let members = test_env
|
||||
@@ -579,7 +615,7 @@ async fn delete_organization_means_all_projects_to_org_owner() {
|
||||
.api
|
||||
.organization_add_project(zeta_organization_id, alpha_project_id, USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 200);
|
||||
assert_status(&resp, StatusCode::OK);
|
||||
|
||||
// Add beta to zeta organization
|
||||
test_env
|
||||
@@ -592,13 +628,13 @@ async fn delete_organization_means_all_projects_to_org_owner() {
|
||||
.api
|
||||
.add_user_to_team(beta_team_id, FRIEND_USER_ID, None, None, USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
|
||||
// Try to accept invite
|
||||
// This returns a failure, because since beta and FRIEND are in the organizations,
|
||||
// they can be added to the project without an invite
|
||||
let resp = test_env.api.join_team(beta_team_id, FRIEND_USER_PAT).await;
|
||||
assert_eq!(resp.status(), 400);
|
||||
assert_status(&resp, StatusCode::BAD_REQUEST);
|
||||
|
||||
// Confirm there is NO owner of the project, as it is owned by the organization
|
||||
let members = test_env
|
||||
@@ -613,7 +649,7 @@ async fn delete_organization_means_all_projects_to_org_owner() {
|
||||
.api
|
||||
.transfer_team_ownership(zeta_team_id, FRIEND_USER_ID, USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
|
||||
// Confirm there is NO owner of the project, as it is owned by the organization
|
||||
let members = test_env
|
||||
@@ -628,7 +664,7 @@ async fn delete_organization_means_all_projects_to_org_owner() {
|
||||
.api
|
||||
.delete_organization(zeta_organization_id, FRIEND_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
|
||||
// Confirm there is only one owner of the alpha project, and it is now FRIEND_USER_ID
|
||||
let members = test_env
|
||||
@@ -708,7 +744,7 @@ async fn permissions_patch_organization() {
|
||||
// Not covered by PATCH /organization
|
||||
#[actix_rt::test]
|
||||
async fn permissions_edit_details() {
|
||||
with_test_environment(None, |test_env: TestEnvironment<ApiV3>| async move {
|
||||
with_test_environment(Some(12), |test_env: TestEnvironment<ApiV3>| async move {
|
||||
let zeta_organization_id = &test_env.dummy.organization_zeta.organization_id;
|
||||
let zeta_team_id = &test_env.dummy.organization_zeta.team_id;
|
||||
|
||||
@@ -814,9 +850,9 @@ async fn permissions_manage_invites() {
|
||||
let resp = api
|
||||
.add_user_to_team(zeta_team_id, MOD_USER_ID, None, None, ADMIN_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
let resp = api.join_team(zeta_team_id, MOD_USER_PAT).await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
|
||||
// remove existing member (requires remove_member)
|
||||
let remove_member = OrganizationPermissions::REMOVE_MEMBER;
|
||||
@@ -852,13 +888,13 @@ async fn permissions_add_remove_project() {
|
||||
let resp = api
|
||||
.add_user_to_team(alpha_team_id, FRIEND_USER_ID, None, None, USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
let resp = api.join_team(alpha_team_id, FRIEND_USER_PAT).await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
let resp = api
|
||||
.transfer_team_ownership(alpha_team_id, FRIEND_USER_ID, USER_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(resp.status(), 204);
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
|
||||
// Now, FRIEND_USER_ID owns the alpha project
|
||||
// Add alpha project to zeta organization
|
||||
|
||||
Reference in New Issue
Block a user