-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: [#273] add tags to torrent details in test responses
- Loading branch information
1 parent
f904f14
commit 022692e
Showing
5 changed files
with
74 additions
and
62 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,37 +1,42 @@ | ||
use super::responses::TorrentDetails; | ||
|
||
type Check = (&'static str, bool); | ||
|
||
/// Assert that the torrent details match the expected ones. | ||
/// | ||
/// It ignores some fields that are not relevant for the E2E tests | ||
/// or hard to assert due to the concurrent nature of the tests. | ||
pub fn assert_expected_torrent_details(torrent: &TorrentDetails, expected_torrent: &TorrentDetails) { | ||
assert_eq!( | ||
torrent.torrent_id, expected_torrent.torrent_id, | ||
"torrent `file_size` mismatch" | ||
); | ||
assert_eq!(torrent.uploader, expected_torrent.uploader, "torrent `uploader` mismatch"); | ||
assert_eq!(torrent.info_hash, expected_torrent.info_hash, "torrent `info_hash` mismatch"); | ||
assert_eq!(torrent.title, expected_torrent.title, "torrent `title` mismatch"); | ||
assert_eq!( | ||
torrent.description, expected_torrent.description, | ||
"torrent `description` mismatch" | ||
); | ||
assert_eq!( | ||
torrent.category.category_id, expected_torrent.category.category_id, | ||
"torrent `category.category_id` mismatch" | ||
); | ||
assert_eq!( | ||
torrent.category.name, expected_torrent.category.name, | ||
"torrent `category.name` mismatch" | ||
); | ||
// assert_eq!(torrent.category.num_torrents, expected_torrent.category.num_torrents, "torrent `category.num_torrents` mismatch"); // Ignored | ||
// assert_eq!(torrent.upload_date, expected_torrent.upload_date, "torrent `upload_date` mismatch"); // Ignored, can't mock time easily for now. | ||
assert_eq!(torrent.file_size, expected_torrent.file_size, "torrent `file_size` mismatch"); | ||
assert_eq!(torrent.seeders, expected_torrent.seeders, "torrent `seeders` mismatch"); | ||
assert_eq!(torrent.leechers, expected_torrent.leechers, "torrent `leechers` mismatch"); | ||
assert_eq!(torrent.files, expected_torrent.files, "torrent `files` mismatch"); | ||
assert_eq!(torrent.trackers, expected_torrent.trackers, "torrent `trackers` mismatch"); | ||
assert_eq!( | ||
torrent.magnet_link, expected_torrent.magnet_link, | ||
"torrent `magnet_link` mismatch" | ||
); | ||
let mut discrepancies = Vec::new(); | ||
|
||
let checks: Vec<Check> = vec![ | ||
("torrent_id", torrent.torrent_id == expected_torrent.torrent_id), | ||
("uploader", torrent.uploader == expected_torrent.uploader), | ||
("info_hash", torrent.info_hash == expected_torrent.info_hash), | ||
("title", torrent.title == expected_torrent.title), | ||
("description", torrent.description == expected_torrent.description), | ||
( | ||
"category.category_id", | ||
torrent.category.category_id == expected_torrent.category.category_id, | ||
), | ||
("category.name", torrent.category.name == expected_torrent.category.name), | ||
("file_size", torrent.file_size == expected_torrent.file_size), | ||
("seeders", torrent.seeders == expected_torrent.seeders), | ||
("leechers", torrent.leechers == expected_torrent.leechers), | ||
("files", torrent.files == expected_torrent.files), | ||
("trackers", torrent.trackers == expected_torrent.trackers), | ||
("magnet_link", torrent.magnet_link == expected_torrent.magnet_link), | ||
("tags", torrent.tags == expected_torrent.tags), | ||
("name", torrent.name == expected_torrent.name), | ||
]; | ||
|
||
for (field_name, equals) in &checks { | ||
if !equals { | ||
discrepancies.push((*field_name).to_string()); | ||
} | ||
} | ||
|
||
let error_message = format!("left:\n{torrent:#?}\nright:\n{expected_torrent:#?}\ndiscrepancies: {discrepancies:#?}"); | ||
|
||
assert!(discrepancies.is_empty(), "{}", error_message); | ||
} |
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