server_api_mock.rs 1.5 KB

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