An unofficial collection of APIs used in FreeJam games and mods
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
4.3KB

  1. #[cfg(feature = "robocraft")]
  2. use libfj::robocraft;
  3. #[cfg(feature = "robocraft")]
  4. use std::convert::From;
  5. #[cfg(feature = "robocraft")]
  6. #[test]
  7. fn robocraft_factory_api_init() -> Result<(), ()> {
  8. robocraft::FactoryAPI::new();
  9. Ok(())
  10. }
  11. #[cfg(feature = "robocraft")]
  12. #[tokio::test]
  13. async fn robocraft_factory_default_query() -> Result<(), ()> {
  14. let api = robocraft::FactoryAPI::new();
  15. let result = api.list().await;
  16. assert!(result.is_ok());
  17. let robo_info = result.unwrap();
  18. assert_ne!(robo_info.response.roboshop_items.len(), 0);
  19. assert_eq!(robo_info.status_code, 200);
  20. for robot in &robo_info.response.roboshop_items {
  21. assert_ne!(robot.item_name, "");
  22. assert_ne!(robot.added_by, "");
  23. assert_ne!(robot.added_by_display_name, "");
  24. assert_ne!(robot.thumbnail, "");
  25. println!("FactoryRobotListInfo.to_string() -> `{}`", robot.to_string());
  26. }
  27. Ok(())
  28. }
  29. #[cfg(feature = "robocraft")]
  30. fn builder() -> robocraft::FactorySearchBuilder {
  31. robocraft::FactoryAPI::new().list_builder()
  32. }
  33. #[cfg(feature = "robocraft")]
  34. fn assert_factory_list(robo_info: robocraft::FactoryInfo<robocraft::RoboShopItemsInfo>) -> Result<(), ()> {
  35. assert_ne!(robo_info.response.roboshop_items.len(), 0);
  36. assert_eq!(robo_info.status_code, 200);
  37. for robot in &robo_info.response.roboshop_items {
  38. assert_ne!(robot.item_name, "");
  39. assert_ne!(robot.added_by, "");
  40. assert_ne!(robot.added_by_display_name, "");
  41. assert_ne!(robot.thumbnail, "");
  42. println!("FactoryRobotListInfo.to_string() -> `{}`", robot.to_string());
  43. }
  44. Ok(())
  45. }
  46. #[cfg(feature = "robocraft")]
  47. #[tokio::test]
  48. async fn robocraft_factory_custom_query() -> Result<(), ()> {
  49. let api = robocraft::FactoryAPI::new();
  50. let result = api.list_builder()
  51. .movement_or(robocraft::FactoryMovementType::Wheels)
  52. .weapon_or(robocraft::FactoryWeaponType::Laser)
  53. .page(2)
  54. .items_per_page(10)
  55. .send().await;
  56. assert!(result.is_ok());
  57. let robo_info = result.unwrap();
  58. assert_ne!(robo_info.response.roboshop_items.len(), 0);
  59. //assert_eq!(robo_info.response.roboshop_items.len(), 16); the API behaviour is weird, I swear it's not me!
  60. assert!(robo_info.response.roboshop_items.len() >= 10);
  61. assert_eq!(robo_info.status_code, 200);
  62. for robot in &robo_info.response.roboshop_items {
  63. assert_ne!(robot.item_name, "");
  64. assert_ne!(robot.added_by, "");
  65. assert_ne!(robot.added_by_display_name, "");
  66. assert_ne!(robot.thumbnail, "");
  67. println!("FactoryRobotListInfo.to_string() -> `{}`", robot.to_string());
  68. }
  69. Ok(())
  70. }
  71. #[cfg(feature = "robocraft")]
  72. #[tokio::test]
  73. async fn robocraft_factory_player_query() -> Result<(), ()> {
  74. let result = builder()
  75. .text("Spacecam".to_string()) // there is a featured robot by this user, so this should never fail
  76. .text_search_type(robocraft::FactoryTextSearchType::Player)
  77. .items_per_page(10)
  78. .send().await;
  79. assert!(result.is_ok());
  80. assert_factory_list(result.unwrap())
  81. }
  82. #[cfg(feature = "robocraft")]
  83. #[tokio::test]
  84. async fn robocraft_factory_robot_query() -> Result<(), ()> {
  85. let api = robocraft::FactoryAPI::new();
  86. let result = api.get(6478345 /* featured robot id */).await;
  87. assert!(result.is_ok());
  88. let bot_info = result.unwrap();
  89. assert_ne!(bot_info.response.item_name, "");
  90. assert_eq!(bot_info.response.item_id, 6478345);
  91. assert_ne!(bot_info.response.cube_data, "");
  92. assert_ne!(bot_info.response.colour_data, "");
  93. Ok(())
  94. }
  95. #[cfg(feature = "robocraft")]
  96. #[tokio::test]
  97. async fn robocraft_factory_robot_cubes() -> Result<(), ()> {
  98. let api = robocraft::FactoryAPI::new();
  99. let result = api.get(6478345 /* featured robot id */).await;
  100. assert!(result.is_ok());
  101. let bot_info = result.unwrap();
  102. let cubes = robocraft::Cubes::from(bot_info.clone());
  103. println!("cube count: {} or {}", cubes.provided_len, cubes.len());
  104. /*for c in cubes.into_iter() {
  105. println!("Cube.to_string() -> `{}`", c.to_string());
  106. }*/
  107. let (cube_d, colour_d) = cubes.dump();
  108. let cube_str = base64::encode(&cube_d);
  109. let colour_str = base64::encode(&colour_d);
  110. assert_eq!(cube_str, bot_info.response.cube_data);
  111. assert_eq!(colour_str, bot_info.response.colour_data);
  112. Ok(())
  113. }