@@ -1073,6 +1073,15 @@ mod tests {
10731073
10741074 #[ test]
10751075 fn test_deploy_should_send_correct_requests ( ) {
1076+ run_deploy_should_send_correct_requests_test ( true ) ;
1077+ }
1078+
1079+ #[ test]
1080+ fn test_deploy_with_explicit_app_id_and_no_manifest_id_should_send_correct_requests ( ) {
1081+ run_deploy_should_send_correct_requests_test ( false ) ;
1082+ }
1083+
1084+ fn run_deploy_should_send_correct_requests_test ( id_in_manifest : bool ) {
10761085 let ( temp_dir, command, mock_server, _manifest, _instance_manifest) =
10771086 prepare_edge_apps_test ( false , false ) ;
10781087
@@ -1097,23 +1106,13 @@ mod tests {
10971106 } ,
10981107 ] ) ;
10991108
1109+ if !id_in_manifest {
1110+ manifest. id = None ;
1111+ }
11001112 manifest. user_version = None ;
11011113 manifest. author = None ;
11021114 manifest. entrypoint = None ;
11031115
1104- // let get_entrypoint_mock = mock_server.mock(|when, then| {
1105- // when.method(GET)
1106- // .path("/v4.1/edge-apps/installations")
1107- // .header("Authorization", "Token token")
1108- // .header(
1109- // "user-agent",
1110- // format!("screenly-cli {}", env!("CARGO_PKG_VERSION")),
1111- // )
1112- // .query_param("id", "eq.01H2QZ6Z8WXWNDC0KQ198XCZEB")
1113- // .query_param("select", "entrypoint");
1114- // then.status(200).json_body(json!([{"entrypoint": null}]));
1115- // });
1116- // "v4.1/edge-apps/versions?select=user_version,description,icon,author,entrypoint&app_id=eq.{}&order=revision.desc&limit=1",
11171116 let last_versions_mock = mock_server. mock ( |when, then| {
11181117 when. method ( GET )
11191118 . path ( "/v4.1/edge-apps/versions" )
@@ -1403,347 +1402,14 @@ mod tests {
14031402 let mut file = File :: create ( temp_dir. path ( ) . join ( "index.html" ) ) . unwrap ( ) ;
14041403 write ! ( file, "test" ) . unwrap ( ) ;
14051404
1406- let result = command. deploy (
1407- None ,
1408- Some ( temp_dir. path ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ) ,
1409- Some ( true ) ,
1410- ) ;
1411-
1412- // get_entrypoint_mock.assert();
1413- last_versions_mock. assert_calls ( 2 ) ;
1414- assets_mock. assert ( ) ;
1415- file_tree_from_version_mock. assert ( ) ;
1416- settings_mock. assert ( ) ;
1417- create_version_mock. assert ( ) ;
1418- settings_mock_create. assert ( ) ;
1419- settings_mock_patch. assert ( ) ;
1420- settings_mock_delete. assert ( ) ;
1421- upload_assets_mock. assert ( ) ;
1422- finished_processing_mock. assert ( ) ;
1423- publish_mock. assert ( ) ;
1424- copy_assets_mock. assert ( ) ;
1425- get_version_mock. assert ( ) ;
1426- promote_mock. assert ( ) ;
1427-
1428- assert ! ( result. is_ok( ) ) ;
1429- }
1430-
1431- #[ test]
1432- fn test_deploy_with_explicit_app_id_and_no_manifest_id_should_send_correct_requests ( ) {
1433- let ( temp_dir, command, mock_server, _manifest, _instance_manifest) =
1434- prepare_edge_apps_test ( false , false ) ;
1435-
1436- let mut manifest = create_edge_app_manifest_for_test ( vec ! [
1437- Setting {
1438- name: "asetting" . to_string( ) ,
1439- type_: SettingType :: String ,
1440- title: Some ( "atitle" . to_string( ) ) ,
1441- optional: false ,
1442- default_value: Some ( "" . to_string( ) ) ,
1443- is_global: false ,
1444- help_text: "help text" . to_string( ) ,
1445- } ,
1446- Setting {
1447- name: "nsetting" . to_string( ) ,
1448- type_: SettingType :: String ,
1449- title: Some ( "ntitle" . to_string( ) ) ,
1450- optional: false ,
1451- default_value: Some ( "" . to_string( ) ) ,
1452- is_global: false ,
1453- help_text: "help text" . to_string( ) ,
1454- } ,
1455- ] ) ;
1456-
1457- manifest. id = None ;
1458- manifest. user_version = None ;
1459- manifest. author = None ;
1460- manifest. entrypoint = None ;
1461-
1462- let last_versions_mock = mock_server. mock ( |when, then| {
1463- when. method ( GET )
1464- . path ( "/v4.1/edge-apps/versions" )
1465- . header ( "Authorization" , "Token token" )
1466- . header (
1467- "user-agent" ,
1468- format ! ( "screenly-cli {}" , env!( "CARGO_PKG_VERSION" ) ) ,
1469- )
1470- . query_param (
1471- "select" ,
1472- "user_version,description,icon,author,homepage_url,categories,revision,ready_signal" ,
1473- )
1474- . query_param ( "app_id" , "eq.01H2QZ6Z8WXWNDC0KQ198XCZEW" )
1475- . query_param ( "order" , "revision.desc" )
1476- . query_param ( "limit" , "1" ) ;
1477- then. status ( 200 ) . json_body ( json ! ( [
1478- {
1479- "user_version" : "1" ,
1480- "description" : "desc" ,
1481- "icon" : "icon" ,
1482- "author" : "author" ,
1483- "homepage_url" : "homepage_url" ,
1484- "categories" : [ ] ,
1485- "ready_signal" : false ,
1486- "revision" : 7 ,
1487- }
1488- ] ) ) ;
1489- } ) ;
1490-
1491- let assets_mock = mock_server. mock ( |when, then| {
1492- when. method ( GET )
1493- . path ( "/v4/assets" )
1494- . header ( "Authorization" , "Token token" )
1495- . header (
1496- "user-agent" ,
1497- format ! ( "screenly-cli {}" , env!( "CARGO_PKG_VERSION" ) ) ,
1498- )
1499- . query_param ( "select" , "signature" )
1500- . query_param ( "app_id" , "eq.01H2QZ6Z8WXWNDC0KQ198XCZEW" )
1501- . query_param ( "app_revision" , "eq.7" )
1502- . query_param ( "type" , "eq.edge-app-file" ) ;
1503- then. status ( 200 ) . json_body ( json ! ( [ { "signature" : "sig" } ] ) ) ;
1504- } ) ;
1505-
1506- let file_tree_from_version_mock = mock_server. mock ( |when, then| {
1507- when. method ( GET )
1508- . path ( "/v4/edge-apps/versions" )
1509- . header ( "Authorization" , "Token token" )
1510- . header (
1511- "user-agent" ,
1512- format ! ( "screenly-cli {}" , env!( "CARGO_PKG_VERSION" ) ) ,
1513- )
1514- . query_param ( "app_id" , "eq.01H2QZ6Z8WXWNDC0KQ198XCZEW" )
1515- . query_param ( "revision" , "eq.7" )
1516- . query_param ( "select" , "file_tree" ) ;
1517- then. status ( 200 ) . json_body ( json ! ( [ { "index.html" : "sig" } ] ) ) ;
1518- } ) ;
1519-
1520- let settings_mock = mock_server. mock ( |when, then| {
1521- when. method ( GET )
1522- . path ( "/v4.1/edge-apps/settings" )
1523- . header ( "Authorization" , "Token token" )
1524- . header (
1525- "user-agent" ,
1526- format ! ( "screenly-cli {}" , env!( "CARGO_PKG_VERSION" ) ) ,
1527- )
1528- . query_param ( "app_id" , "eq.01H2QZ6Z8WXWNDC0KQ198XCZEW" )
1529- . query_param ( "select" , "name,type,default_value,optional,title,help_text" )
1530- . query_param ( "order" , "name.asc" ) ;
1531- then. status ( 200 ) . json_body ( json ! ( [ {
1532- "name" : "nsetting" . to_string( ) ,
1533- "type" : SettingType :: String ,
1534- "default_value" : "5" . to_string( ) ,
1535- "title" : "ntitle" . to_string( ) ,
1536- "optional" : true ,
1537- "help_text" : "For how long to display the map overlay every time the rover has moved to a new position." . to_string( ) ,
1538- "is_global" : false ,
1539- } , {
1540- "name" : "isetting" . to_string( ) ,
1541- "type" : SettingType :: String ,
1542- "default_value" : "5" . to_string( ) ,
1543- "title" : null,
1544- "optional" : true ,
1545- "help_text" : "Some text" . to_string( ) ,
1546- "is_global" : false ,
1547- } ] ) ) ;
1548- } ) ;
1549-
1550- let create_version_mock = mock_server. mock ( |when, then| {
1551- when. method ( POST )
1552- . path ( "/v4/edge-apps/versions" )
1553- . header ( "Authorization" , "Token token" )
1554- . header (
1555- "user-agent" ,
1556- format ! ( "screenly-cli {}" , env!( "CARGO_PKG_VERSION" ) ) ,
1557- )
1558- . json_body ( json ! ( {
1559- "app_id" : "01H2QZ6Z8WXWNDC0KQ198XCZEW" ,
1560- "description" : "asdf" ,
1561- "icon" : "asdf" ,
1562- "homepage_url" : "asdfasdf" ,
1563- "categories" : [ "Utilities" , "Dashboards" ] ,
1564- "file_tree" : {
1565- "index.html" : "0a209f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08122086cebd0c365d241e32d5b0972c07aae3a8d6499c2a9471aa85943a35577200021a180a14a94a8fe5ccb19ba61c4c0873d391e987982fbbd31000"
1566- } ,
1567- "ready_signal" : false ,
1568- } ) ) ;
1569- then. status ( 201 ) . json_body ( json ! ( [ { "revision" : 8 } ] ) ) ;
1570- } ) ;
1571-
1572- let settings_mock_create = mock_server. mock ( |when, then| {
1573- when. method ( POST )
1574- . path ( "/v4.1/edge-apps/settings" )
1575- . header ( "Authorization" , "Token token" )
1576- . header (
1577- "user-agent" ,
1578- format ! ( "screenly-cli {}" , env!( "CARGO_PKG_VERSION" ) ) ,
1579- )
1580- . json_body ( json ! ( {
1581- "name" : "asetting" ,
1582- "app_id" : "01H2QZ6Z8WXWNDC0KQ198XCZEW" ,
1583- "type" : "string" ,
1584- "default_value" : "" ,
1585- "title" : "atitle" ,
1586- "optional" : false ,
1587- "help_text" : {
1588- "schema_version" : 1 ,
1589- "properties" : {
1590- "help_text" : "help text" ,
1591- "display_order" : 0 ,
1592- } ,
1593- } ,
1594- } ) ) ;
1595- then. status ( 201 ) . json_body ( json ! (
1596- [ {
1597- "name" : "asetting" ,
1598- "app_id" : "01H2QZ6Z8WXWNDC0KQ198XCZEW" ,
1599- "type" : "string" ,
1600- "default_value" : "" ,
1601- "title" : "atitle" ,
1602- "optional" : false ,
1603- "help_text" : "help text" ,
1604- } ] ) ) ;
1605- } ) ;
1606-
1607- let settings_mock_patch = mock_server. mock ( |when, then| {
1608- when. method ( PATCH )
1609- . path ( "/v4.1/edge-apps/settings" )
1610- . header ( "Authorization" , "Token token" )
1611- . header (
1612- "user-agent" ,
1613- format ! ( "screenly-cli {}" , env!( "CARGO_PKG_VERSION" ) ) ,
1614- )
1615- . query_param ( "app_id" , "eq.01H2QZ6Z8WXWNDC0KQ198XCZEW" )
1616- . query_param ( "name" , "eq.nsetting" )
1617- . json_body ( json ! ( {
1618- "name" : "nsetting" ,
1619- "type" : "string" ,
1620- "default_value" : "" ,
1621- "title" : "ntitle" ,
1622- "optional" : false ,
1623- "help_text" : {
1624- "schema_version" : 1 ,
1625- "properties" : {
1626- "help_text" : "help text" ,
1627- "display_order" : 1 ,
1628- } ,
1629- } ,
1630- } ) ) ;
1631- then. status ( 200 ) . json_body ( json ! (
1632- [ {
1633- "name" : "nsetting" ,
1634- "app_id" : "01H2QZ6Z8WXWNDC0KQ198XCZEW" ,
1635- "type" : "string" ,
1636- "default_value" : "" ,
1637- "title" : "ntitle" ,
1638- "optional" : false ,
1639- "help_text" : "help text" ,
1640- } ] ) ) ;
1641- } ) ;
1642-
1643- let settings_mock_delete = mock_server. mock ( |when, then| {
1644- when. method ( DELETE )
1645- . path ( "/v4.1/edge-apps/settings" )
1646- . header ( "Authorization" , "Token token" )
1647- . header (
1648- "user-agent" ,
1649- format ! ( "screenly-cli {}" , env!( "CARGO_PKG_VERSION" ) ) ,
1650- )
1651- . query_param ( "app_id" , "eq.01H2QZ6Z8WXWNDC0KQ198XCZEW" )
1652- . query_param ( "name" , "eq.isetting" ) ;
1653- then. status ( 204 ) . json_body ( json ! ( { } ) ) ;
1654- } ) ;
1655-
1656- let copy_assets_mock = mock_server. mock ( |when, then| {
1657- when. method ( POST )
1658- . path ( "/v4/edge-apps/copy-assets" )
1659- . header ( "Authorization" , "Token token" )
1660- . header (
1661- "user-agent" ,
1662- format ! ( "screenly-cli {}" , env!( "CARGO_PKG_VERSION" ) ) ,
1663- ) . json_body ( json ! ( {
1664- "app_id" : "01H2QZ6Z8WXWNDC0KQ198XCZEW" ,
1665- "revision" : 8 ,
1666- "signatures" : [ "0a209f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08122086cebd0c365d241e32d5b0972c07aae3a8d6499c2a9471aa85943a35577200021a180a14a94a8fe5ccb19ba61c4c0873d391e987982fbbd31000" ]
1667- } ) ) ;
1668- then. status ( 201 ) . json_body ( json ! ( [ ] ) ) ;
1669- } ) ;
1670-
1671- let upload_assets_mock = mock_server. mock ( |when, then| {
1672- when. method ( POST ) . path ( "/v4/assets" ) ;
1673- then. status ( 201 ) . body ( "" ) ;
1674- } ) ;
1675- let finished_processing_mock = mock_server. mock ( |when, then| {
1676- when. method ( GET )
1677- . path ( "/v4/assets" )
1678- . query_param ( "select" , "status,processing_error,title" )
1679- . query_param ( "app_id" , "eq.01H2QZ6Z8WXWNDC0KQ198XCZEW" )
1680- . query_param ( "app_revision" , "eq.8" )
1681- . query_param ( "status" , "neq.finished" ) ;
1682- then. status ( 200 ) . json_body ( json ! ( [ ] ) ) ;
1683- } ) ;
1684-
1685- let publish_mock = mock_server. mock ( |when, then| {
1686- when. method ( PATCH )
1687- . path ( "/v4/edge-apps/versions" )
1688- . header ( "Authorization" , "Token token" )
1689- . header (
1690- "user-agent" ,
1691- format ! ( "screenly-cli {}" , env!( "CARGO_PKG_VERSION" ) ) ,
1692- )
1693- . query_param ( "app_id" , "eq.01H2QZ6Z8WXWNDC0KQ198XCZEW" )
1694- . query_param ( "revision" , "eq.8" )
1695- . json_body ( json ! ( { "published" : true } ) ) ;
1696- then. status ( 200 ) ;
1697- } ) ;
1698-
1699- let get_version_mock = mock_server. mock ( |when, then| {
1700- when. method ( GET )
1701- . path ( "/v4/edge-apps/versions" )
1702- . header ( "Authorization" , "Token token" )
1703- . header (
1704- "user-agent" ,
1705- format ! ( "screenly-cli {}" , env!( "CARGO_PKG_VERSION" ) ) ,
1706- )
1707- . query_param ( "select" , "revision" )
1708- . query_param ( "app_id" , "eq.01H2QZ6Z8WXWNDC0KQ198XCZEW" )
1709- . query_param ( "revision" , "eq.8" ) ;
1710-
1711- then. status ( 200 ) . json_body ( json ! ( [
1712- {
1713- "revision" : 8 ,
1714- }
1715- ] ) ) ;
1716- } ) ;
1717-
1718- let promote_mock = mock_server. mock ( |when, then| {
1719- when. method ( PATCH )
1720- . path ( "/v4/edge-apps/channels" )
1721- . header ( "Authorization" , "Token token" )
1722- . header (
1723- "user-agent" ,
1724- format ! ( "screenly-cli {}" , env!( "CARGO_PKG_VERSION" ) ) ,
1725- )
1726- . query_param ( "app_id" , "eq.01H2QZ6Z8WXWNDC0KQ198XCZEW" )
1727- . query_param ( "channel" , "eq.stable" )
1728- . query_param ( "select" , "channel,app_revision" )
1729- . json_body ( json ! ( {
1730- "app_revision" : 8 ,
1731- } ) ) ;
1732- then. status ( 200 ) . json_body ( json ! ( [
1733- {
1734- "channel" : "stable" ,
1735- "app_revision" : 8
1736- }
1737- ] ) ) ;
1738- } ) ;
1739-
1740- EdgeAppManifest :: save_to_file ( & manifest, temp_dir. path ( ) . join ( "screenly.yml" ) . as_path ( ) )
1741- . unwrap ( ) ;
1742- let mut file = File :: create ( temp_dir. path ( ) . join ( "index.html" ) ) . unwrap ( ) ;
1743- write ! ( file, "test" ) . unwrap ( ) ;
1405+ let app_id = if id_in_manifest {
1406+ None
1407+ } else {
1408+ Some ( "01H2QZ6Z8WXWNDC0KQ198XCZEW" . to_string ( ) )
1409+ } ;
17441410
17451411 let result = command. deploy (
1746- Some ( "01H2QZ6Z8WXWNDC0KQ198XCZEW" . to_string ( ) ) ,
1412+ app_id ,
17471413 Some ( temp_dir. path ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ) ,
17481414 Some ( true ) ,
17491415 ) ;
0 commit comments