This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
183 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,3 +109,4 @@ derive-new = "0.5.9" | |
|
||
[dev-dependencies] | ||
actix-http = "3.4.0" | ||
assert_matches = "1.5.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use actix_web::{dev::ServiceResponse, test::TestRequest}; | ||
|
||
use crate::common::actix::TestRequestExtensions; | ||
|
||
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)) | ||
.append_auth(pat) | ||
.to_request(); | ||
|
||
self.call(req).await | ||
} | ||
|
||
pub async fn unfollow_organization(&self, organization_id: &str, pat: &str) -> ServiceResponse { | ||
let req = TestRequest::delete() | ||
.uri(&format!("/v3/organization/{}/follow", organization_id)) | ||
.append_auth(pat) | ||
.to_request(); | ||
|
||
self.call(req).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use actix_http::StatusCode; | ||
use actix_web::{ | ||
dev::ServiceResponse, | ||
test::{self, TestRequest}, | ||
}; | ||
use labrinth::models::feed_item::FeedItem; | ||
|
||
use crate::common::{actix::TestRequestExtensions, asserts::assert_status}; | ||
|
||
use super::ApiV3; | ||
|
||
impl ApiV3 { | ||
pub async fn follow_user(&self, user_id: &str, pat: &str) -> ServiceResponse { | ||
let req = TestRequest::post() | ||
.uri(&format!("/v3/user/{}/follow", user_id)) | ||
.append_auth(pat) | ||
.to_request(); | ||
|
||
self.call(req).await | ||
} | ||
|
||
pub async fn unfollow_user(&self, user_id: &str, pat: &str) -> ServiceResponse { | ||
let req = TestRequest::delete() | ||
.uri(&format!("/v3/user/{}/follow", user_id)) | ||
.append_auth(pat) | ||
.to_request(); | ||
|
||
self.call(req).await | ||
} | ||
|
||
pub async fn get_feed(&self, pat: &str) -> Vec<FeedItem> { | ||
let req = TestRequest::get() | ||
.uri("/v3/user/feed") | ||
.append_auth(pat) | ||
.to_request(); | ||
let resp = self.call(req).await; | ||
assert_status(&resp, StatusCode::OK); | ||
|
||
test::read_body_json(resp).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use assert_matches::assert_matches; | ||
use common::{ | ||
api_v2::organization::deser_organization, | ||
database::{FRIEND_USER_PAT, USER_USER_ID, USER_USER_PAT}, | ||
environment::with_test_environment, | ||
request_data::get_public_project_creation_data, | ||
}; | ||
use labrinth::models::feed_item::FeedItemBody; | ||
|
||
use crate::common::dummy_data::DummyProjectAlpha; | ||
|
||
mod common; | ||
|
||
#[actix_rt::test] | ||
async fn user_feed_before_following_user_shows_no_projects() { | ||
with_test_environment(|env| async move { | ||
let feed = env.v3.get_feed(FRIEND_USER_PAT).await; | ||
|
||
assert_eq!(feed.len(), 0); | ||
}) | ||
.await | ||
} | ||
|
||
#[actix_rt::test] | ||
async fn user_feed_after_following_user_shows_previously_created_public_projects() { | ||
with_test_environment(|env| async move { | ||
let DummyProjectAlpha { | ||
project_id: alpha_project_id, | ||
.. | ||
} = env.dummy.as_ref().unwrap().project_alpha.clone(); | ||
env.v3.follow_user(USER_USER_ID, FRIEND_USER_PAT).await; | ||
|
||
let feed = env.v3.get_feed(FRIEND_USER_PAT).await; | ||
|
||
assert_eq!(feed.len(), 1); | ||
assert_matches!( | ||
feed[0].body, | ||
FeedItemBody::ProjectCreated { project_id, .. } if project_id.to_string() == alpha_project_id | ||
) | ||
}) | ||
.await | ||
} | ||
|
||
#[actix_rt::test] | ||
async fn user_feed_when_following_user_that_creates_project_as_org_only_shows_event_when_following_org( | ||
) { | ||
with_test_environment(|env| async move { | ||
let resp = env | ||
.v2 | ||
.create_organization("test", "desc", USER_USER_ID) | ||
.await; | ||
let organization = deser_organization(resp).await; | ||
let org_id = organization.id.to_string(); | ||
let project_create_data = get_public_project_creation_data("a", None, Some(&org_id)); | ||
let (project, _) = env | ||
.v2 | ||
.add_public_project(project_create_data, 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; | ||
assert_eq!(feed.len(), 1); | ||
assert_matches!(feed[0].body, FeedItemBody::ProjectCreated { project_id, .. } if project_id != project.id); | ||
|
||
env.v3.follow_organization(&org_id, FRIEND_USER_PAT).await; | ||
let feed = env.v3.get_feed(FRIEND_USER_PAT).await; | ||
assert_eq!(feed.len(), 1); | ||
assert_matches!(feed[0].body, FeedItemBody::ProjectCreated { project_id, .. } if project_id == project.id); | ||
}) | ||
.await; | ||
} |