diff --git a/src/upgrades/from_v1_0_0_to_v2_0_0/databases/sqlite_v1_0_0.rs b/src/upgrades/from_v1_0_0_to_v2_0_0/databases/sqlite_v1_0_0.rs index 3d42a4b3..a5743000 100644 --- a/src/upgrades/from_v1_0_0_to_v2_0_0/databases/sqlite_v1_0_0.rs +++ b/src/upgrades/from_v1_0_0_to_v2_0_0/databases/sqlite_v1_0_0.rs @@ -35,7 +35,7 @@ pub struct TorrentRecordV1 { pub info_hash: String, pub title: String, pub category_id: i64, - pub description: String, + pub description: Option, pub upload_date: i64, pub file_size: i64, pub seeders: i64, diff --git a/tests/upgrades/from_v1_0_0_to_v2_0_0/sqlite_v2_0_0.rs b/tests/upgrades/from_v1_0_0_to_v2_0_0/sqlite_v2_0_0.rs index 17331572..2f0ba395 100644 --- a/tests/upgrades/from_v1_0_0_to_v2_0_0/sqlite_v2_0_0.rs +++ b/tests/upgrades/from_v1_0_0_to_v2_0_0/sqlite_v2_0_0.rs @@ -35,6 +35,20 @@ pub struct TrackerKeyRecordV2 { pub date_expiry: i64, } +#[derive(Debug, Serialize, Deserialize, sqlx::FromRow)] +pub struct TorrentInfoRecordV2 { + pub torrent_id: i64, + pub title: String, + pub description: Option, +} + +#[derive(Debug, Serialize, Deserialize, sqlx::FromRow, PartialEq)] +pub struct TorrentAnnounceUrlV2 { + pub announce_url_id: i64, + pub torrent_id: i64, + pub tracker_url: String, +} + pub struct SqliteDatabaseV2_0_0 { pub pool: SqlitePool, } @@ -95,4 +109,28 @@ impl SqliteDatabaseV2_0_0 { .fetch_one(&self.pool) .await } + + pub async fn get_torrent_info( + &self, + torrent_id: i64, + ) -> Result { + query_as::<_, TorrentInfoRecordV2>( + "SELECT * FROM torrust_torrent_info WHERE torrent_id = ?", + ) + .bind(torrent_id) + .fetch_one(&self.pool) + .await + } + + pub async fn get_torrent_announce_urls( + &self, + torrent_id: i64, + ) -> Result, sqlx::Error> { + query_as::<_, TorrentAnnounceUrlV2>( + "SELECT * FROM torrust_torrent_announce_urls WHERE torrent_id = ?", + ) + .bind(torrent_id) + .fetch_all(&self.pool) + .await + } } diff --git a/tests/upgrades/from_v1_0_0_to_v2_0_0/testers/torrent_tester.rs b/tests/upgrades/from_v1_0_0_to_v2_0_0/testers/torrent_tester.rs index d6c14045..33ea8b1a 100644 --- a/tests/upgrades/from_v1_0_0_to_v2_0_0/testers/torrent_tester.rs +++ b/tests/upgrades/from_v1_0_0_to_v2_0_0/testers/torrent_tester.rs @@ -31,7 +31,7 @@ impl TorrentTester { info_hash: "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_string(), title: "title".to_string(), category_id: 1, - description: "description".to_string(), + description: Some("description".to_string()), upload_date: 1667546358, // 2022-11-04 07:19:18 file_size: 9219566, seeders: 0, @@ -60,10 +60,10 @@ impl TorrentTester { let torrent_file = read_torrent_from_file(&filepath).unwrap(); self.assert_torrent(&torrent_file).await; + self.assert_torrent_info().await; + self.assert_torrent_announce_urls(&torrent_file).await; // TODO // `torrust_torrent_files`, - // `torrust_torrent_info` - // `torrust_torrent_announce_urls` } pub fn torrent_file_path(&self, upload_path: &str, torrent_id: i64) -> String { @@ -112,4 +112,41 @@ impl TorrentTester { convert_timestamp_to_datetime(self.test_data.torrent.upload_date) ); } + + /// Table `torrust_torrent_info` + async fn assert_torrent_info(&self) { + let torrent_info = self + .destiny_database + .get_torrent_info(self.test_data.torrent.torrent_id) + .await + .unwrap(); + + assert_eq!(torrent_info.torrent_id, self.test_data.torrent.torrent_id); + assert_eq!(torrent_info.title, self.test_data.torrent.title); + assert_eq!(torrent_info.description, self.test_data.torrent.description); + } + + /// Table `torrust_torrent_announce_urls` + async fn assert_torrent_announce_urls(&self, torrent_file: &Torrent) { + let torrent_announce_urls = self + .destiny_database + .get_torrent_announce_urls(self.test_data.torrent.torrent_id) + .await + .unwrap(); + + let urls: Vec = torrent_announce_urls + .iter() + .map(|torrent_announce_url| torrent_announce_url.tracker_url.to_string()) + .collect(); + + let expected_urls = torrent_file + .announce_list + .clone() + .unwrap() + .into_iter() + .flatten() + .collect::>(); + + assert_eq!(urls, expected_urls); + } }