useAuthClient.mock.js 850 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { mockNuxtImport } from "@nuxt/test-utils/runtime"
  2. import { NIL as NIL_UUID } from "uuid"
  3. function inYearsFromNow(years) {
  4. const now = new Date()
  5. const YEAR_IN_MS = 365 * 24 * 60 * 60 * 1000
  6. return new Date().setTime(now.getTime() + years * YEAR_IN_MS)
  7. }
  8. const user = {
  9. name: "Test User",
  10. email: "test@example.com",
  11. role: "user",
  12. username: "test",
  13. id: NIL_UUID
  14. }
  15. const session = {
  16. token: "0".repeat(32),
  17. userId: user.id,
  18. id: NIL_UUID,
  19. createdAt: now,
  20. updatedAt: now,
  21. expiresAt: inYearsFromNow(20)
  22. }
  23. mockNuxtImport("useAuthClient", () => {
  24. return () => {
  25. return {
  26. user: ref(user),
  27. session: ref(session),
  28. isSignedIn: ref(true),
  29. signIn: () => null,
  30. signUp: () => null,
  31. signOut: () => null,
  32. fetchSession: () => ({ session, user }),
  33. authClient: {}
  34. }
  35. }
  36. })