Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
merge conflicts, fixes deleted data
Browse files Browse the repository at this point in the history
  • Loading branch information
thesuzerain committed Nov 18, 2023
1 parent 315a81a commit 5ffa116
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 20 deletions.
5 changes: 4 additions & 1 deletion tests/common/api_v2/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use std::collections::HashMap;

use crate::common::{asserts::assert_status, database::MOD_USER_PAT};

use super::{request_data::get_public_project_creation_data, ImageData, ApiV2};
use super::{
request_data::{get_public_project_creation_data, ImageData},
ApiV2,
};

impl ApiV2 {
pub async fn add_default_org_project(&self, org_id: &str, pat: &str) -> LegacyProject {
Expand Down
2 changes: 1 addition & 1 deletion tests/common/api_v3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pub mod project;
pub mod request_data;
pub mod tags;
pub mod team;
pub mod version;
pub mod user;
pub mod version;

#[derive(Clone)]
pub struct ApiV3 {
Expand Down
22 changes: 15 additions & 7 deletions tests/common/api_v3/organization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use actix_web::{
};
use bytes::Bytes;
use labrinth::models::{organizations::Organization, v3::projects::Project};
use serde_json::json;
use labrinth::util::actix::TestRequestExtensions;
use serde_json::json; // TODO: extend other tests to do this

use super::{request_data::ImageData, ApiV3};

Expand All @@ -26,6 +27,19 @@ impl ApiV3 {
self.call(req).await
}

pub async fn create_organization_deserialized(
&self,
organization_title: &str,
description: &str,
pat: &str,
) -> Organization {
let resp = self
.create_organization(organization_title, description, pat)
.await;
assert_eq!(resp.status(), 200);
test::read_body_json(resp).await
}

pub async fn get_organization(&self, id_or_title: &str, pat: &str) -> ServiceResponse {
let req = TestRequest::get()
.uri(&format!("/v3/organization/{id_or_title}"))
Expand Down Expand Up @@ -147,13 +161,7 @@ impl ApiV3 {

self.call(req).await
}
}
use actix_web::{dev::ServiceResponse, test::TestRequest};
use labrinth::util::actix::TestRequestExtensions; // TODO: extend other tests to do this

use super::ApiV3;

impl ApiV3 {
pub async fn follow_organization(&self, organization_id: &str, pat: &str) -> ServiceResponse {
let req = TestRequest::post()
.uri(&format!("/v3/organization/{}/follow", organization_id))
Expand Down
9 changes: 8 additions & 1 deletion tests/common/api_v3/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ use serde_json::json;
use crate::common::{asserts::assert_status, database::MOD_USER_PAT};

use super::{
request_data::{ImageData, ProjectCreationRequestData},
request_data::{get_public_project_creation_data, ImageData, ProjectCreationRequestData},
ApiV3,
};

impl ApiV3 {
pub async fn add_default_org_project(&self, org_id: &str, pat: &str) -> Project {
let project_create_data =
get_public_project_creation_data("thisisaslug", None, Some(org_id));
let (project, _) = self.add_public_project(project_create_data, pat).await;
project
}

pub async fn add_public_project(
&self,
creation_data: ProjectCreationRequestData,
Expand Down
13 changes: 10 additions & 3 deletions tests/common/api_v3/request_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ pub struct ImageData {
pub fn get_public_project_creation_data(
slug: &str,
version_jar: Option<TestFile>,
organization_id: Option<&str>,
) -> ProjectCreationRequestData {
let json_data = get_public_project_creation_data_json(slug, version_jar.as_ref());
let json_data =
get_public_project_creation_data_json(slug, version_jar.as_ref(), organization_id);
let multipart_data = get_public_creation_data_multipart(&json_data, version_jar.as_ref());
ProjectCreationRequestData {
slug: slug.to_string(),
Expand Down Expand Up @@ -88,6 +90,7 @@ pub fn get_public_version_creation_data_json(
pub fn get_public_project_creation_data_json(
slug: &str,
version_jar: Option<&TestFile>,
organization_id: Option<&str>,
) -> serde_json::Value {
let initial_versions = if let Some(jar) = version_jar {
json!([get_public_version_creation_data_json("1.2.3", jar)])
Expand All @@ -96,7 +99,7 @@ pub fn get_public_project_creation_data_json(
};

let is_draft = version_jar.is_none();
json!(
let mut j = json!(
{
"title": format!("Test Project {slug}"),
"slug": slug,
Expand All @@ -107,7 +110,11 @@ pub fn get_public_project_creation_data_json(
"categories": [],
"license_id": "MIT",
}
)
);
if let Some(organization_id) = organization_id {
j["organization_id"] = json!(organization_id);
}
j
}

pub fn get_public_creation_data_multipart(
Expand Down
15 changes: 10 additions & 5 deletions tests/feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async fn get_feed_after_following_user_shows_previously_created_public_versions(

// Add version
let v = env
.v2
.v3
.create_default_version(&alpha_project_id, None, USER_USER_PAT)
.await;

Expand All @@ -74,8 +74,8 @@ async fn get_feed_after_following_user_shows_previously_created_public_versions(
async fn get_feed_when_following_user_that_creates_project_as_org_only_shows_event_when_following_org(
) {
with_test_environment(|env| async move {
let org_id = env.v2.create_default_organization(USER_USER_PAT).await;
let project = env.v2.add_default_org_project(&org_id, USER_USER_PAT).await;
let org_id = env.v3.create_organization_deserialized("test", "desc", USER_USER_PAT).await.id.to_string();
let project = env.v3.add_default_org_project(&org_id, USER_USER_PAT).await;

env.v3.follow_user(USER_USER_ID, FRIEND_USER_PAT).await;
let feed = env.v3.get_feed(FRIEND_USER_PAT).await;
Expand Down Expand Up @@ -107,8 +107,13 @@ async fn get_feed_after_unfollowing_user_no_longer_shows_feed_items() {
#[actix_rt::test]
async fn get_feed_after_unfollowing_organization_no_longer_shows_feed_items() {
with_test_environment(|env| async move {
let org_id = env.v2.create_default_organization(USER_USER_PAT).await;
env.v2.add_default_org_project(&org_id, USER_USER_PAT).await;
let org_id = env
.v3
.create_organization_deserialized("test", "desc", USER_USER_PAT)
.await
.id
.to_string();
env.v3.add_default_org_project(&org_id, USER_USER_PAT).await;
env.v3.follow_organization(&org_id, FRIEND_USER_PAT).await;

env.v3.unfollow_organization(&org_id, FRIEND_USER_PAT).await;
Expand Down
2 changes: 1 addition & 1 deletion tests/organizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use crate::common::{
use actix_web::test;
use bytes::Bytes;
use common::{
api_v3::request_data::get_public_project_creation_data,
database::{FRIEND_USER_ID, FRIEND_USER_PAT, USER_USER_PAT},
permissions::{PermissionsTest, PermissionsTestContext},
request_data::get_public_project_creation_data,
};
use labrinth::{
models::teams::{OrganizationPermissions, ProjectPermissions},
Expand Down
2 changes: 2 additions & 0 deletions tests/v2/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ async fn test_project_type_sanity() {
let test_creation_mod = request_data::get_public_project_creation_data(
"test-mod",
Some(TestFile::build_random_jar()),
None,
);
let test_creation_modpack = request_data::get_public_project_creation_data(
"test-modpack",
Some(TestFile::build_random_mrpack()),
None,
);
for (mod_or_modpack, test_creation_data) in [
("mod", test_creation_mod),
Expand Down
2 changes: 1 addition & 1 deletion tests/v2/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn search_projects() {
TestFile::build_random_jar()
};
let mut basic_project_json =
request_data::get_public_project_creation_data_json(&slug, Some(&jar));
request_data::get_public_project_creation_data_json(&slug, Some(&jar), None);
modify_json(&mut basic_project_json);

let basic_project_multipart =
Expand Down

0 comments on commit 5ffa116

Please sign in to comment.