Skip to content

Commit

Permalink
refactor: moved test to authorization mod
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-nt committed Sep 27, 2024
1 parent e3baeda commit 17de729
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions tests/e2e/web/api/v1/contexts/torrent/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,6 @@ mod for_guests {
use crate::e2e::web::api::v1::contexts::torrent::steps::{upload_random_torrent_to_index, upload_test_torrent};
use crate::e2e::web::api::v1::contexts::user::steps::new_logged_in_user;

#[tokio::test]
async fn it_should_allow_guests_to_get_torrents() {
let mut env = TestEnv::new();
env.start(api::Version::V1).await;

if !env.provides_a_tracker() {
println!("test skipped. It requires a tracker to be running.");
return;
}

let client = Client::unauthenticated(&env.server_socket_addr().unwrap());

let uploader = new_logged_in_user(&env).await;
let (_test_torrent, _indexed_torrent) = upload_random_torrent_to_index(&uploader, &env).await;

let response = client.get_torrents(Query::empty()).await;

let torrent_list_response: TorrentListResponse = serde_json::from_str(&response.body).unwrap();

assert!(torrent_list_response.data.total > 0);
assert!(response.is_json_and_ok());
}

#[tokio::test]
async fn it_should_allow_to_get_torrents_with_pagination() {
let mut env = TestEnv::new();
Expand Down Expand Up @@ -434,6 +411,8 @@ mod for_guests {
use crate::common::client::Client;
use crate::common::contexts::torrent::fixtures::random_torrent;
use crate::common::contexts::torrent::forms::UploadTorrentMultipartForm;
use crate::common::contexts::torrent::responses::TorrentListResponse;
use crate::common::http::Query;
use crate::e2e::environment::TestEnv;
use crate::e2e::web::api::v1::contexts::torrent::steps::upload_random_torrent_to_index;
use crate::e2e::web::api::v1::contexts::user::steps::new_logged_in_user;
Expand Down Expand Up @@ -495,6 +474,29 @@ mod for_guests {

assert_eq!(response.status, 200);
}

#[tokio::test]
async fn it_should_allow_guests_to_get_torrents() {
let mut env = TestEnv::new();
env.start(api::Version::V1).await;

if !env.provides_a_tracker() {
println!("test skipped. It requires a tracker to be running.");
return;
}

let client = Client::unauthenticated(&env.server_socket_addr().unwrap());

let uploader = new_logged_in_user(&env).await;
let (_test_torrent, _indexed_torrent) = upload_random_torrent_to_index(&uploader, &env).await;

let response = client.get_torrents(Query::empty()).await;

let torrent_list_response: TorrentListResponse = serde_json::from_str(&response.body).unwrap();

assert!(torrent_list_response.data.total > 0);
assert!(response.is_json_and_ok());
}
}
}

Expand Down

0 comments on commit 17de729

Please sign in to comment.