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.

robocraft_auth.rs 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #[cfg(feature = "robocraft")]
  2. use libfj::robocraft;
  3. #[cfg(feature = "robocraft2")]
  4. use libfj::robocraft2;
  5. #[cfg(feature = "robocraft")]
  6. use libfj::robocraft::ITokenProvider;
  7. #[cfg(feature = "robocraft")]
  8. #[test]
  9. fn robocraft_auth_login() -> Result<(), ()> {
  10. let token_maybe = robocraft::AuthenticatedTokenProvider::with_email("melon.spoik@gmail.com", "P4$$w0rd");
  11. assert!(token_maybe.is_ok());
  12. let token_maybe = robocraft::AuthenticatedTokenProvider::with_username("FJAPIC00L", "P4$$w0rd");
  13. assert!(token_maybe.is_ok());
  14. let token_p = token_maybe.unwrap();
  15. let raw_token_maybe = token_p.token();
  16. assert!(raw_token_maybe.is_ok());
  17. println!("Token: {}", raw_token_maybe.unwrap());
  18. Ok(())
  19. }
  20. #[cfg(feature = "robocraft")]
  21. #[test]
  22. fn robocraft_account() -> Result<(), ()> {
  23. let token_maybe = robocraft::AuthenticatedTokenProvider::with_username("FJAPIC00L", "P4$$w0rd");
  24. assert!(token_maybe.is_ok());
  25. let token_provider = token_maybe.unwrap();
  26. let account_maybe = token_provider.get_account_info();
  27. assert!(account_maybe.is_ok());
  28. let account = account_maybe.unwrap();
  29. assert_eq!(account.display_name, "FJAPIC00L");
  30. assert_eq!(account.created_date, "2019-01-18T14:48:09");
  31. Ok(())
  32. }
  33. // this requires human-interaction so it's disabled by default
  34. #[cfg(feature = "robocraft2")]
  35. #[allow(dead_code)]
  36. //#[tokio::test]
  37. async fn robocraft2_account() -> Result<(), ()> {
  38. let token_maybe = robocraft2::PortalTokenProvider::portal().await;
  39. assert!(token_maybe.is_ok());
  40. let token_provider = token_maybe.unwrap();
  41. let account_maybe = token_provider.get_account_info();
  42. assert!(account_maybe.is_ok());
  43. let account = account_maybe.unwrap();
  44. assert_eq!(account.display_name, "NGniusness");
  45. assert_eq!(account.created_date, "2014-09-17T21:02:46");
  46. Ok(())
  47. }
  48. #[cfg(feature = "robocraft2")]
  49. #[tokio::test]
  50. async fn robocraft2_simple_account() -> Result<(), ()> {
  51. let token_maybe = robocraft2::PortalTokenProvider::with_username("FJAPIC00L", "P4$$w0rd").await;
  52. assert!(token_maybe.is_ok());
  53. let token_provider = token_maybe.unwrap();
  54. let account_maybe = token_provider.get_account_info();
  55. assert!(account_maybe.is_ok());
  56. let account = account_maybe.unwrap();
  57. assert_eq!(account.display_name, "FJAPIC00L");
  58. assert_eq!(account.created_date, "2019-01-18T14:48:09");
  59. Ok(())
  60. }