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.

92 lines
3.2KB

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