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.

112 lines
3.9KB

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