server_api_mock.rs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. use crate::{
  2. entities::{SignInParams, SignInResponse, SignUpParams, SignUpResponse, UserDetail},
  3. errors::{ErrorBuilder, ErrorCode, UserError},
  4. services::user::UserServerAPI,
  5. };
  6. use crate::entities::UpdateUserParams;
  7. use flowy_infra::future::ResultFuture;
  8. pub struct UserServerMock {}
  9. impl UserServerMock {}
  10. impl UserServerAPI for UserServerMock {
  11. fn sign_up(&self, params: SignUpParams) -> ResultFuture<SignUpResponse, UserError> {
  12. let uid = params.email.clone();
  13. ResultFuture::new(async move {
  14. Ok(SignUpResponse {
  15. uid,
  16. name: params.name,
  17. email: params.email,
  18. token: "fake token".to_owned(),
  19. })
  20. })
  21. }
  22. fn sign_in(&self, params: SignInParams) -> ResultFuture<SignInResponse, UserError> {
  23. ResultFuture::new(async {
  24. Ok(SignInResponse {
  25. uid: "fake id".to_owned(),
  26. name: "fake name".to_owned(),
  27. email: params.email,
  28. token: "fake token".to_string(),
  29. })
  30. })
  31. }
  32. fn sign_out(&self, _token: &str) -> ResultFuture<(), UserError> {
  33. ResultFuture::new(async { Ok(()) })
  34. }
  35. fn update_user(&self, _token: &str, _params: UpdateUserParams) -> ResultFuture<(), UserError> {
  36. ResultFuture::new(async { Ok(()) })
  37. }
  38. fn get_user_detail(&self, _token: &str) -> ResultFuture<UserDetail, UserError> {
  39. ResultFuture::new(async {
  40. Err(ErrorBuilder::new(ErrorCode::Unknown)
  41. .msg("mock data, ignore this error")
  42. .build())
  43. })
  44. }
  45. }