|
| 1 | +use crate::integration::{AssertCommand, MockEndpointBuilder, TestManager}; |
| 2 | + |
| 3 | +#[test] |
| 4 | +fn command_build_download_help() { |
| 5 | + TestManager::new().register_trycmd_test("build/build-download-help.trycmd"); |
| 6 | +} |
| 7 | + |
| 8 | +#[test] |
| 9 | +fn command_build_download_not_installable() { |
| 10 | + TestManager::new() |
| 11 | + .mock_endpoint( |
| 12 | + MockEndpointBuilder::new( |
| 13 | + "GET", |
| 14 | + "/api/0/organizations/wat-org/preprodartifacts/123/install-details/", |
| 15 | + ) |
| 16 | + .with_response_body(r#"{"isInstallable": false, "installUrl": null}"#), |
| 17 | + ) |
| 18 | + .assert_cmd(vec!["build", "download", "--build-id", "123"]) |
| 19 | + .with_default_token() |
| 20 | + .run_and_assert(AssertCommand::Failure); |
| 21 | +} |
| 22 | + |
| 23 | +#[test] |
| 24 | +fn command_build_download_apk() { |
| 25 | + let manager = TestManager::new(); |
| 26 | + let server_url = manager.server_url(); |
| 27 | + let download_path = format!("{server_url}/download/build.apk?response_format=apk"); |
| 28 | + let install_details_response = serde_json::json!({ |
| 29 | + "isInstallable": true, |
| 30 | + "installUrl": download_path, |
| 31 | + }) |
| 32 | + .to_string(); |
| 33 | + |
| 34 | + let output = tempfile::NamedTempFile::new().expect("Failed to create temp file"); |
| 35 | + let output_path = output.path().to_str().unwrap().to_owned(); |
| 36 | + |
| 37 | + manager |
| 38 | + .mock_endpoint( |
| 39 | + MockEndpointBuilder::new( |
| 40 | + "GET", |
| 41 | + "/api/0/organizations/wat-org/preprodartifacts/456/install-details/", |
| 42 | + ) |
| 43 | + .with_response_body(install_details_response), |
| 44 | + ) |
| 45 | + .mock_endpoint( |
| 46 | + MockEndpointBuilder::new("GET", "/download/build.apk?response_format=apk") |
| 47 | + .with_response_body("fake apk content"), |
| 48 | + ) |
| 49 | + .assert_cmd(vec![ |
| 50 | + "build", |
| 51 | + "download", |
| 52 | + "--build-id", |
| 53 | + "456", |
| 54 | + "--output", |
| 55 | + &output_path, |
| 56 | + ]) |
| 57 | + .with_default_token() |
| 58 | + .run_and_assert(AssertCommand::Success); |
| 59 | + |
| 60 | + let content = std::fs::read_to_string(&output_path).expect("Failed to read downloaded file"); |
| 61 | + assert_eq!(content, "fake apk content"); |
| 62 | +} |
| 63 | + |
| 64 | +#[test] |
| 65 | +fn command_build_download_ipa_converts_plist_format() { |
| 66 | + let manager = TestManager::new(); |
| 67 | + let server_url = manager.server_url(); |
| 68 | + // The install URL uses plist format, which should be converted to ipa |
| 69 | + let install_url = format!("{server_url}/download/build.ipa?response_format=plist"); |
| 70 | + let install_details_response = serde_json::json!({ |
| 71 | + "isInstallable": true, |
| 72 | + "installUrl": install_url, |
| 73 | + }) |
| 74 | + .to_string(); |
| 75 | + |
| 76 | + let output = tempfile::NamedTempFile::new().expect("Failed to create temp file"); |
| 77 | + let output_path = output.path().to_str().unwrap().to_owned(); |
| 78 | + |
| 79 | + manager |
| 80 | + .mock_endpoint( |
| 81 | + MockEndpointBuilder::new( |
| 82 | + "GET", |
| 83 | + "/api/0/organizations/wat-org/preprodartifacts/789/install-details/", |
| 84 | + ) |
| 85 | + .with_response_body(install_details_response), |
| 86 | + ) |
| 87 | + // The mock should receive the converted URL with response_format=ipa |
| 88 | + .mock_endpoint( |
| 89 | + MockEndpointBuilder::new("GET", "/download/build.ipa?response_format=ipa") |
| 90 | + .with_response_body("fake ipa content"), |
| 91 | + ) |
| 92 | + .assert_cmd(vec![ |
| 93 | + "build", |
| 94 | + "download", |
| 95 | + "--build-id", |
| 96 | + "789", |
| 97 | + "--output", |
| 98 | + &output_path, |
| 99 | + ]) |
| 100 | + .with_default_token() |
| 101 | + .run_and_assert(AssertCommand::Success); |
| 102 | + |
| 103 | + let content = std::fs::read_to_string(&output_path).expect("Failed to read downloaded file"); |
| 104 | + assert_eq!(content, "fake ipa content"); |
| 105 | +} |
| 106 | + |
| 107 | +#[test] |
| 108 | +fn command_build_download_unsupported_format() { |
| 109 | + let manager = TestManager::new(); |
| 110 | + let server_url = manager.server_url(); |
| 111 | + let download_path = format!("{server_url}/download/build.zip?response_format=zip"); |
| 112 | + let install_details_response = serde_json::json!({ |
| 113 | + "isInstallable": true, |
| 114 | + "installUrl": download_path, |
| 115 | + }) |
| 116 | + .to_string(); |
| 117 | + |
| 118 | + manager |
| 119 | + .mock_endpoint( |
| 120 | + MockEndpointBuilder::new( |
| 121 | + "GET", |
| 122 | + "/api/0/organizations/wat-org/preprodartifacts/999/install-details/", |
| 123 | + ) |
| 124 | + .with_response_body(install_details_response), |
| 125 | + ) |
| 126 | + .assert_cmd(vec!["build", "download", "--build-id", "999"]) |
| 127 | + .with_default_token() |
| 128 | + .run_and_assert(AssertCommand::Failure); |
| 129 | +} |
0 commit comments