user.test.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { AuthBackendService, UserBackendService } from '../appflowy_app/stores/effects/user/backend_service';
  2. import { randomFillSync } from 'crypto';
  3. import { nanoid } from '@reduxjs/toolkit';
  4. beforeAll(() => {
  5. //@ts-ignore
  6. window.crypto = {
  7. // @ts-ignore
  8. getRandomValues: function (buffer) {
  9. // @ts-ignore
  10. return randomFillSync(buffer);
  11. },
  12. };
  13. });
  14. describe('User backend service', () => {
  15. it('sign up', async () => {
  16. const service = new AuthBackendService();
  17. const result = await service.autoSignUp();
  18. expect(result.ok).toBeTruthy;
  19. });
  20. it('sign in', async () => {
  21. const authService = new AuthBackendService();
  22. const email = nanoid(4) + '@appflowy.io';
  23. const password = nanoid(10);
  24. const signUpResult = await authService.signUp({ name: 'nathan', email: email, password: password });
  25. expect(signUpResult.ok).toBeTruthy;
  26. const signInResult = await authService.signIn({ email: email, password: password });
  27. expect(signInResult.ok).toBeTruthy;
  28. });
  29. it('get user profile', async () => {
  30. const service = new AuthBackendService();
  31. const result = await service.autoSignUp();
  32. const userProfile = result.unwrap();
  33. const userService = new UserBackendService(userProfile.id);
  34. expect((await userService.getUserProfile()).unwrap()).toBe(userProfile);
  35. });
  36. });