Skip to content

Commit e8bf537

Browse files
committed
refactor: [#115] extractfunction expected_torrent
1 parent 4782f67 commit e8bf537

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use torrust_index_backend::models::torrent_file::Torrent;
2+
3+
/// The backend does not generate exactly the same torrent that was uploaded.
4+
/// So we need to update the expected torrent to match the one generated by
5+
/// the backend.
6+
pub fn expected_torrent(mut uploaded_torrent: Torrent) -> Torrent {
7+
// code-review: The backend does not generate exactly the same torrent
8+
// that was uploaded and created by the `imdl` command-line tool.
9+
// So we need to update the expected torrent to match the one generated
10+
// by the backend. For some of them it makes sense (`announce` and `announce_list`),
11+
// for others it does not.
12+
uploaded_torrent.info.private = Some(0);
13+
uploaded_torrent.announce = Some("udp://tracker:6969".to_string());
14+
uploaded_torrent.encoding = None;
15+
uploaded_torrent.announce_list = Some(vec![vec!["udp://tracker:6969".to_string()]]);
16+
uploaded_torrent.creation_date = None;
17+
uploaded_torrent.created_by = None;
18+
19+
uploaded_torrent
20+
}

tests/e2e/contexts/torrent/contract.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ mod for_guests {
3030
use crate::common::contexts::torrent::responses::{
3131
Category, File, TorrentDetails, TorrentDetailsResponse, TorrentListResponse,
3232
};
33+
use crate::e2e::contexts::torrent::asserts::expected_torrent;
3334
use crate::e2e::contexts::torrent::steps::upload_random_torrent_to_index;
3435
use crate::e2e::contexts::user::steps::new_logged_in_user;
3536
use crate::e2e::environment::TestEnv;
@@ -125,25 +126,13 @@ mod for_guests {
125126
let client = Client::unauthenticated(&env.server_socket_addr().unwrap());
126127

127128
let uploader = new_logged_in_user(&env).await;
128-
let (test_torrent, uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await;
129+
let (test_torrent, torrent_listed_in_index) = upload_random_torrent_to_index(&uploader, &env).await;
129130

130-
let response = client.download_torrent(uploaded_torrent.torrent_id).await;
131+
let response = client.download_torrent(torrent_listed_in_index.torrent_id).await;
131132

132133
let torrent = decode_torrent(&response.bytes).unwrap();
133-
let mut expected_torrent = decode_torrent(&test_torrent.index_info.torrent_file.contents).unwrap();
134-
135-
// code-review: The backend does not generate exactly the same torrent
136-
// that was uploaded and created by the `imdl` command-line tool.
137-
// So we need to update the expected torrent to match the one generated
138-
// by the backend. For some of them it makes sense (`announce` and `announce_list`),
139-
// for others it does not.
140-
expected_torrent.info.private = Some(0);
141-
expected_torrent.announce = Some("udp://tracker:6969".to_string());
142-
expected_torrent.encoding = None;
143-
expected_torrent.announce_list = Some(vec![vec!["udp://tracker:6969".to_string()]]);
144-
expected_torrent.creation_date = None;
145-
expected_torrent.created_by = None;
146-
134+
let uploaded_torrent = decode_torrent(&test_torrent.index_info.torrent_file.contents).unwrap();
135+
let expected_torrent = expected_torrent(uploaded_torrent);
147136
assert_eq!(torrent, expected_torrent);
148137
assert!(response.is_bittorrent_and_ok());
149138
}

tests/e2e/contexts/torrent/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
pub mod asserts;
12
pub mod contract;
23
pub mod steps;

0 commit comments

Comments
 (0)