@etus/bhono-app 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/dist/index.js +0 -0
  2. package/package.json +5 -1
  3. package/templates/base/.husky/pre-push +26 -0
  4. package/templates/base/CLAUDE.md +5 -5
  5. package/templates/base/README.md +31 -20
  6. package/templates/base/docs/app_spec.txt +13 -10
  7. package/templates/base/docs/architecture/README.md +3 -0
  8. package/templates/base/docs/architecture/data-requirements.md +4 -3
  9. package/templates/base/docs/architecture/db-bootstrap.md +39 -0
  10. package/templates/base/docs/architecture/drizzle-migration-plan.md +125 -0
  11. package/templates/base/docs/architecture/erd.md +1 -1
  12. package/templates/base/docs/architecture/sql-standards.md +100 -0
  13. package/templates/base/docs/testing.md +36 -29
  14. package/templates/base/package.json +6 -5
  15. package/templates/base/pnpm-lock.yaml +0 -123
  16. package/templates/base/schema.sql +84 -0
  17. package/templates/base/scripts/init.sh +244 -59
  18. package/templates/base/src/client/hooks/use-auth.ts +5 -0
  19. package/templates/base/src/client/routes/_authenticated/dashboard.tsx +1 -1
  20. package/templates/base/src/client/routes/index.tsx +1 -1
  21. package/templates/base/src/server/db/client.ts +3 -5
  22. package/templates/base/src/server/db/records.ts +81 -0
  23. package/templates/base/src/server/db/seed.ts +3 -2
  24. package/templates/base/src/server/db/sql.ts +96 -0
  25. package/templates/base/src/server/index.ts +16 -2
  26. package/templates/base/src/server/lib/audit.ts +74 -26
  27. package/templates/base/src/server/lib/audited-db.ts +219 -109
  28. package/templates/base/src/server/lib/transaction.ts +10 -16
  29. package/templates/base/src/server/middleware/account.ts +8 -15
  30. package/templates/base/src/server/middleware/auth.ts +102 -38
  31. package/templates/base/src/server/middleware/rate-limit.ts +6 -1
  32. package/templates/base/src/server/routes/accounts/handlers.ts +18 -6
  33. package/templates/base/src/server/routes/audits/handlers.ts +3 -1
  34. package/templates/base/src/server/routes/auth/handlers.ts +14 -9
  35. package/templates/base/src/server/routes/auth/test-login.ts +99 -45
  36. package/templates/base/src/server/routes/health/handlers.ts +4 -4
  37. package/templates/base/src/server/routes/invitations/handlers.ts +6 -3
  38. package/templates/base/src/server/routes/users/handlers.ts +21 -14
  39. package/templates/base/src/server/services/accounts.ts +242 -217
  40. package/templates/base/src/server/services/audits.ts +114 -61
  41. package/templates/base/src/server/services/auth.ts +310 -180
  42. package/templates/base/src/server/services/invitations.ts +282 -222
  43. package/templates/base/src/server/services/users.ts +383 -293
  44. package/templates/base/src/server/types/index.ts +1 -2
  45. package/templates/base/{src/server/__tests__/fixtures.ts → tests/fixtures/server.ts} +3 -3
  46. package/templates/base/{src/client/__tests__/setup-browser.ts → tests/helpers/client-setup-browser.ts} +2 -2
  47. package/templates/base/{src/client/__tests__/setup.ts → tests/helpers/client-setup.ts} +1 -1
  48. package/templates/base/{src/client/__tests__/test-utils.tsx → tests/helpers/client-test-utils.tsx} +2 -2
  49. package/templates/base/{src/server/__tests__/setup.ts → tests/helpers/server.ts} +9 -9
  50. package/templates/base/tests/integration/accounts/crud.test.ts +2 -11
  51. package/templates/base/tests/integration/audits/list.test.ts +2 -11
  52. package/templates/base/tests/integration/auth/auth-service.test.ts +1 -10
  53. package/templates/base/tests/integration/auth/invitation-token.test.ts +2 -11
  54. package/templates/base/tests/integration/auth/logout.test.ts +2 -11
  55. package/templates/base/tests/integration/auth/oauth.test.ts +23 -42
  56. package/templates/base/tests/integration/auth/refresh-token.test.ts +1 -9
  57. package/templates/base/tests/integration/auth/session-expiry.test.ts +1 -9
  58. package/templates/base/tests/integration/auth/session.test.ts +2 -11
  59. package/templates/base/tests/integration/auth/super-admin.test.ts +1 -9
  60. package/templates/base/tests/integration/authorization/analytics-role.test.ts +2 -11
  61. package/templates/base/tests/integration/authorization/billing-role.test.ts +2 -11
  62. package/templates/base/tests/integration/authorization/guards-roles.test.ts +1 -9
  63. package/templates/base/tests/integration/authorization/multi-tenancy.test.ts +2 -11
  64. package/templates/base/tests/integration/authorization/roles.test.ts +2 -11
  65. package/templates/base/tests/integration/config/production-behavior.test.ts +2 -11
  66. package/templates/base/tests/integration/health/health.test.ts +25 -44
  67. package/templates/base/tests/integration/invitations/crud.test.ts +2 -11
  68. package/templates/base/tests/integration/invitations/email.test.ts +1 -9
  69. package/templates/base/tests/integration/middleware/auth.test.ts +3 -12
  70. package/templates/base/tests/integration/middleware/request-logger.test.ts +1 -9
  71. package/templates/base/tests/integration/performance/response-times.test.ts +1 -9
  72. package/templates/base/tests/integration/security/cookie-security.test.ts +2 -11
  73. package/templates/base/tests/integration/security/csrf-protection.test.ts +2 -11
  74. package/templates/base/tests/integration/security/log-sanitization.test.ts +1 -9
  75. package/templates/base/tests/integration/security/rate-limiting.test.ts +1 -9
  76. package/templates/base/tests/integration/security/sql-injection.test.ts +7 -18
  77. package/templates/base/tests/integration/security/xss-prevention.test.ts +2 -11
  78. package/templates/base/tests/integration/setup.ts +13 -90
  79. package/templates/base/tests/integration/smoke.test.ts +3 -2
  80. package/templates/base/tests/integration/storage/upload.test.ts +2 -11
  81. package/templates/base/tests/integration/storage/validation.test.ts +2 -11
  82. package/templates/base/tests/integration/users/crud.test.ts +2 -11
  83. package/templates/base/tests/integration/users/list.test.ts +2 -11
  84. package/templates/base/tests/integration/vitest.config.ts +2 -9
  85. package/templates/base/{src/server/__tests__ → tests}/mocks/db.ts +1 -1
  86. package/templates/base/{src/server/__tests__ → tests}/mocks/index.ts +1 -1
  87. package/templates/base/{src/server/__tests__ → tests}/mocks/kv.ts +1 -1
  88. package/templates/base/{src/server/__tests__ → tests}/mocks/r2.ts +1 -1
  89. package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/sidebar.test.tsx +1 -1
  90. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/avatar.test.tsx +1 -1
  91. package/templates/base/{src/client/__tests__ → tests/unit/client/components/ui}/button.test.tsx +1 -1
  92. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/card.test.tsx +1 -1
  93. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/dialog.test.tsx +1 -1
  94. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/input.test.tsx +1 -1
  95. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/loading-skeleton.test.tsx +1 -1
  96. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/skeleton.test.tsx +1 -1
  97. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/sonner.test.tsx +1 -1
  98. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/tabs.test.tsx +1 -1
  99. package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/account.test.tsx +1 -1
  100. package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/integrations.test.tsx +1 -1
  101. package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/settings.test.tsx +1 -1
  102. package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/team.test.tsx +1 -1
  103. package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/authenticated-layout.test.tsx +1 -1
  104. package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/dashboard.test.tsx +1 -1
  105. package/templates/base/{src/client/routes/__tests__ → tests/unit/client/routes}/invite.test.tsx +1 -1
  106. package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/login.test.tsx +1 -1
  107. package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/navigation.test.tsx +1 -1
  108. package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/root-layout.test.tsx +1 -1
  109. package/templates/base/{src/server/auth/__tests__ → tests/unit/server/auth}/guards.test.ts +2 -2
  110. package/templates/base/{src → tests/unit}/server/auth/permissions.test.ts +1 -1
  111. package/templates/base/{src → tests/unit}/server/auth/roles.test.ts +1 -1
  112. package/templates/base/tests/unit/server/db/sql.test.ts +68 -0
  113. package/templates/base/{src → tests/unit}/server/env.test.ts +1 -1
  114. package/templates/base/tests/unit/server/lib/audited-db.test.ts +78 -0
  115. package/templates/base/{src → tests/unit}/server/lib/email.test.ts +1 -1
  116. package/templates/base/{src → tests/unit}/server/lib/errors.test.ts +1 -1
  117. package/templates/base/{src → tests/unit}/server/lib/oauth.test.ts +1 -1
  118. package/templates/base/{src → tests/unit}/server/lib/pagination.test.ts +1 -1
  119. package/templates/base/{src → tests/unit}/server/lib/password.test.ts +1 -1
  120. package/templates/base/{src → tests/unit}/server/lib/providers.test.ts +1 -1
  121. package/templates/base/{src → tests/unit}/server/lib/r2-storage.test.ts +2 -2
  122. package/templates/base/{src → tests/unit}/server/lib/session.test.ts +2 -2
  123. package/templates/base/{src → tests/unit}/server/lib/tokens.test.ts +1 -1
  124. package/templates/base/{src → tests/unit}/server/lib/transaction.test.ts +5 -14
  125. package/templates/base/{src → tests/unit}/server/middleware/account.test.ts +16 -24
  126. package/templates/base/{src → tests/unit}/server/middleware/auth.test.ts +71 -42
  127. package/templates/base/{src → tests/unit}/server/middleware/cors.test.ts +1 -1
  128. package/templates/base/{src → tests/unit}/server/middleware/error-handler.test.ts +2 -2
  129. package/templates/base/{src → tests/unit}/server/middleware/rate-limit.test.ts +3 -2
  130. package/templates/base/{src → tests/unit}/server/middleware/request-context.test.ts +1 -1
  131. package/templates/base/{src → tests/unit}/server/middleware/request-logger.test.ts +1 -1
  132. package/templates/base/{src/server/__tests__/mocks/__tests__ → tests/unit/server/mocks}/db.test.ts +1 -1
  133. package/templates/base/{src/server/__tests__/mocks/__tests__ → tests/unit/server/mocks}/kv.test.ts +1 -1
  134. package/templates/base/{src/server/__tests__/mocks/__tests__ → tests/unit/server/mocks}/r2.test.ts +1 -1
  135. package/templates/base/{src/server/routes/accounts/__tests__ → tests/unit/server/routes/accounts}/handlers.test.ts +12 -12
  136. package/templates/base/{src/server/routes/audits/__tests__ → tests/unit/server/routes/audits}/handlers.test.ts +11 -11
  137. package/templates/base/{src/server/routes/auth/__tests__ → tests/unit/server/routes/auth}/handlers.test.ts +13 -13
  138. package/templates/base/{src/server/routes/health/__tests__ → tests/unit/server/routes/health}/handlers.test.ts +27 -23
  139. package/templates/base/{src/server/routes/invitations/__tests__ → tests/unit/server/routes/invitations}/handlers.test.ts +14 -17
  140. package/templates/base/{src/server/routes/storage/__tests__ → tests/unit/server/routes/storage}/handlers.test.ts +6 -6
  141. package/templates/base/{src/server/routes/users/__tests__ → tests/unit/server/routes/users}/handlers.test.ts +12 -12
  142. package/templates/base/tests/unit/server/services/accounts.test.ts +258 -0
  143. package/templates/base/tests/unit/server/services/audits.test.ts +141 -0
  144. package/templates/base/tests/unit/server/services/auth.test.ts +179 -0
  145. package/templates/base/tests/unit/server/services/invitations.test.ts +165 -0
  146. package/templates/base/tests/unit/server/services/users.test.ts +351 -0
  147. package/templates/base/tsconfig.json +2 -1
  148. package/templates/base/vitest.config.browser.ts +3 -2
  149. package/templates/base/vitest.config.frontend.ts +3 -2
  150. package/templates/base/vitest.config.ts +7 -14
  151. package/templates/base/.claude/settings.local.json +0 -11
  152. package/templates/base/config/drizzle.config.ts +0 -10
  153. package/templates/base/src/server/db/schema/accounts.ts +0 -20
  154. package/templates/base/src/server/db/schema/audit-logs.ts +0 -26
  155. package/templates/base/src/server/db/schema/index.ts +0 -7
  156. package/templates/base/src/server/db/schema/invitations.ts +0 -30
  157. package/templates/base/src/server/db/schema/refresh-tokens.ts +0 -22
  158. package/templates/base/src/server/db/schema/user-accounts.ts +0 -25
  159. package/templates/base/src/server/db/schema/users.ts +0 -33
  160. package/templates/base/src/server/lib/audited-db.test.ts +0 -107
  161. package/templates/base/src/server/lib/schema-helpers.ts +0 -16
  162. package/templates/base/src/server/services/__tests__/accounts.test.ts +0 -764
  163. package/templates/base/src/server/services/__tests__/audits.test.ts +0 -235
  164. package/templates/base/src/server/services/__tests__/auth.test.ts +0 -765
  165. package/templates/base/src/server/services/__tests__/invitations.test.ts +0 -704
  166. package/templates/base/src/server/services/__tests__/users.test.ts +0 -755
  167. package/templates/base/tests/integration/lib/schema-helpers.test.ts +0 -129
  168. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-can-be-collapsed-by-default-1.png +0 -0
  169. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-expands-when-collapsed-and-expand-button-is-clicked-1.png +0 -0
  170. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-handles-logout-button-click-1.png +0 -0
  171. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-handles-navigation-clicks-1.png +0 -0
  172. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-hides-navigation-labels-when-collapsed-1.png +0 -0
  173. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-highlights-active-route-1.png +0 -0
  174. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-renders-sidebar-navigation-items-1.png +0 -0
  175. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-shows-keyboard-shortcut-hint-when-expanded-1.png +0 -0
  176. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-shows-user-info-when-authenticated-1.png +0 -0
  177. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-shows-user-initials-in-avatar-fallback-1.png +0 -0
  178. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/error-boundary.test.tsx +0 -0
  179. /package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/error-fallback.test.tsx +0 -0
  180. /package/templates/base/{src/client/hooks/__tests__ → tests/unit/client/hooks}/use-auth.test.tsx +0 -0
  181. /package/templates/base/{src/client/hooks/__tests__ → tests/unit/client/hooks}/use-theme.test.tsx +0 -0
  182. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-display-dashboard-stats-cards-1.png +0 -0
  183. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-display-quick-action-cards-1.png +0 -0
  184. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-display-recent-activity-section-1.png +0 -0
  185. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-display-user-first-name-in-welcome-message-1.png +0 -0
  186. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-display-user-information-in-sidebar-1.png +0 -0
  187. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-render-dashboard-when-authenticated-1.png +0 -0
  188. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-show-navigation-sidebar-1.png +0 -0
  189. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-unauthenticated-should-redirect-to-login-when-not-authenticated-1.png +0 -0
  190. /package/templates/base/{src/client/routes/__tests__ → tests/unit/client/routes}/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-display-accept-invitation-button-1.png +0 -0
  191. /package/templates/base/{src/client/routes/__tests__ → tests/unit/client/routes}/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-display-decline-button-linking-to-homepage-1.png +0 -0
  192. /package/templates/base/{src/client/routes/__tests__ → tests/unit/client/routes}/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-display-invitation-details--email--workspace--role--1.png +0 -0
  193. /package/templates/base/{src/client/routes/__tests__ → tests/unit/client/routes}/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-have-a-logo-link-to-homepage-1.png +0 -0
  194. /package/templates/base/{src/client/routes/__tests__ → tests/unit/client/routes}/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-render-invitation-page-with-inviter-name-and-workspace-1.png +0 -0
  195. /package/templates/base/{src/client/routes/__tests__ → tests/unit/client/routes}/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-show-terms-of-service-and-privacy-policy-links-1.png +0 -0
  196. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/login.test.tsx/Login-Page-should-display-Google-OAuth-login-button-1.png +0 -0
  197. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/login.test.tsx/Login-Page-should-have-a-link-back-to-home-page-1.png +0 -0
  198. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/login.test.tsx/Login-Page-should-render-login-content-without-waiting-for-authentication-1.png +0 -0
  199. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/login.test.tsx/Login-Page-should-render-login-page-at--login-route-1.png +0 -0
  200. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/login.test.tsx/Login-Page-should-show-Terms-of-Service-and-Privacy-Policy-links-1.png +0 -0
  201. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/login.test.tsx/Login-Page-should-trigger-OAuth-flow-when-clicking-login-button-1.png +0 -0
  202. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-404-handling-should-display-404-text-on-not-found-page-1.png +0 -0
  203. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-404-handling-should-have-navigation-options-on-404-page-1.png +0 -0
  204. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-404-handling-should-render-404-page-for-unknown-routes-1.png +0 -0
  205. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-authenticated-navigation-should-navigate-from-dashboard-to-account-page-1.png +0 -0
  206. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-authenticated-navigation-should-navigate-from-dashboard-to-integrations-page-1.png +0 -0
  207. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-authenticated-navigation-should-navigate-from-dashboard-to-settings-page-1.png +0 -0
  208. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-authenticated-navigation-should-navigate-from-dashboard-to-team-page-1.png +0 -0
  209. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-home-page-navigation-should-display-navigation-links-on-home-page-1.png +0 -0
  210. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-home-page-navigation-should-have-correct-link-destinations-on-home-page-1.png +0 -0
  211. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-unauthenticated-navigation-should-allow-access-to-home-page-without-authentication-1.png +0 -0
  212. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-unauthenticated-navigation-should-allow-access-to-login-page-without-authentication-1.png +0 -0
  213. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-unauthenticated-navigation-should-redirect-unauthenticated-users-from-dashboard-to-login-1.png +0 -0
  214. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-unauthenticated-navigation-should-redirect-unauthenticated-users-from-settings-to-login-1.png +0 -0
  215. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-unauthenticated-navigation-should-redirect-unauthenticated-users-from-team-to-login-1.png +0 -0
  216. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/account.test.tsx/Account-Page-should-render-Active-Sessions-section-with-session-cards-1.png +0 -0
  217. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/account.test.tsx/Account-Page-should-render-page-with-correct-title--Account--1.png +0 -0
  218. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/account.test.tsx/Account-Page-should-show-API-Access-section-1.png +0 -0
  219. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/account.test.tsx/Account-Page-should-show-Connected-Accounts-section-with-Google-connected-1.png +0 -0
  220. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/account.test.tsx/Account-Page-should-show-Danger-Zone-section-with-delete-button-1.png +0 -0
  221. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/account.test.tsx/Account-Page-should-show-Security-section-with-Two-Factor-Authentication-1.png +0 -0
  222. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-API-documentation-section-should-display-API-documentation-link-section-1.png +0 -0
  223. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-Create-Webhook-Dialog-should-have-Add-Webhook-trigger-button-1.png +0 -0
  224. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-category-filters-should-display-all-category-buttons-1.png +0 -0
  225. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-integration-cards-should-display-all-integration-cards-with-names-1.png +0 -0
  226. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-integration-cards-should-display-category-badges-on-cards-1.png +0 -0
  227. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-integration-cards-should-show-Configure-button-for-connected-integrations-1.png +0 -0
  228. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-integration-cards-should-show-Connect-button-for-not-connected-integrations-1.png +0 -0
  229. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-integration-cards-should-show-Connected-badge-for-connected-integrations-1.png +0 -0
  230. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-display-Available-Integrations-section-1.png +0 -0
  231. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-display-Webhooks-section-1.png +0 -0
  232. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-display-connected-count-1.png +0 -0
  233. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-display-page-description-1.png +0 -0
  234. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-display-search-input-1.png +0 -0
  235. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-render-with-correct-title--Integrations--1.png +0 -0
  236. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-search-functionality-should-filter-integrations-based-on-search-query-1.png +0 -0
  237. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-search-functionality-should-search-by-description-1.png +0 -0
  238. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-search-functionality-should-show-no-results-message-when-search-has-no-matches-1.png +0 -0
  239. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-webhooks-section-should-display-existing-webhook-1.png +0 -0
  240. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-webhooks-section-should-display-webhook-events-1.png +0 -0
  241. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-webhooks-section-should-display-webhook-last-delivery-info-1.png +0 -0
  242. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-webhooks-section-should-display-webhook-success-status-1.png +0 -0
  243. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-webhooks-section-should-have-Add-Webhook-button-1.png +0 -0
  244. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Account-tab-should-display-connected-accounts-section-with-Google-provider-1.png +0 -0
  245. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Account-tab-should-display-sessions-and-danger-zone-sections-1.png +0 -0
  246. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Notifications-tab-should-display-all-notification-toggle-options-1.png +0 -0
  247. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Notifications-tab-should-display-email-notifications-section-1.png +0 -0
  248. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Notifications-tab-should-display-toggle-switches-for-notification-options-1.png +0 -0
  249. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Notifications-tab-should-have-toggles-checked-by-default-1.png +0 -0
  250. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display--Save-Changes--button-1.png +0 -0
  251. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display-personal-information-form-1.png +0 -0
  252. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display-profile-picture-section-1.png +0 -0
  253. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display-user-email-in-disabled-email-input-1.png +0 -0
  254. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display-user-initials-in-avatar-1.png +0 -0
  255. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display-user-name-in-the-name-input-1.png +0 -0
  256. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-page-rendering-should-display-all-three-tabs-1.png +0 -0
  257. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-page-rendering-should-display-page-description-1.png +0 -0
  258. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-page-rendering-should-render-with-correct-title--Settings--1.png +0 -0
  259. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-tab-navigation-should-show-Profile-tab-as-default-active-tab-1.png +0 -0
  260. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-tab-navigation-should-switch-to-Account-tab-when-clicked-1.png +0 -0
  261. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-tab-navigation-should-switch-to-Notifications-tab-when-clicked-1.png +0 -0
  262. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/team.test.tsx/Team-Page-should-display-Active-Members-section-with-member-count-1.png +0 -0
  263. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/team.test.tsx/Team-Page-should-display-Pending-Invitations-section-with-invitation-details-1.png +0 -0
  264. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/team.test.tsx/Team-Page-should-have-invite-member-button-that-can-be-clicked-1.png +0 -0
  265. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/team.test.tsx/Team-Page-should-render-page-with-correct-title-and-description-1.png +0 -0
  266. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/team.test.tsx/Team-Page-should-render-search-input-that-filters-team-members-1.png +0 -0
  267. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/team.test.tsx/Team-Page-should-show-current-user-with---you---indicator-and-role-badge-1.png +0 -0
  268. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/error-components.test.tsx +0 -0
  269. /package/templates/base/{src/shared/schemas/__tests__ → tests/unit/shared}/schemas.test.ts +0 -0
@@ -0,0 +1,351 @@
1
+ // src/server/services/__tests__/users.test.ts
2
+ import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest'
3
+ import { usersService } from '@server/services/users'
4
+ import { NotFoundError } from '@server/lib/errors'
5
+ import type { ServiceContext, PaginationQuery } from '@server/types'
6
+ import { createUserFixture, createSuperAdminFixture } from '@tests/fixtures/server'
7
+
8
+ vi.mock('@server/lib/audited-db', () => ({
9
+ auditedUpdate: vi.fn(),
10
+ auditedDelete: vi.fn(),
11
+ }))
12
+
13
+ vi.mock('@server/lib/audit', () => ({
14
+ logAudit: vi.fn(),
15
+ }))
16
+
17
+ vi.mock('@server/db/sql', () => ({
18
+ queryOne: vi.fn(),
19
+ queryAll: vi.fn(),
20
+ execute: vi.fn(),
21
+ }))
22
+
23
+ import { auditedUpdate, auditedDelete } from '@server/lib/audited-db'
24
+ import { logAudit } from '@server/lib/audit'
25
+ import { queryOne, queryAll, execute } from '@server/db/sql'
26
+
27
+ const db = {} as D1Database
28
+
29
+ function createMockContext(overrides: Partial<ServiceContext> = {}): ServiceContext {
30
+ const user = createUserFixture({
31
+ id: 'ctx-user-123',
32
+ email: 'context@example.com',
33
+ name: 'Context User',
34
+ })
35
+
36
+ return {
37
+ accountId: 'account-123',
38
+ user,
39
+ userRole: 'ADMIN',
40
+ transactionId: 'tx-123',
41
+ ip: '127.0.0.1',
42
+ userAgent: 'TestAgent/1.0',
43
+ ...overrides,
44
+ }
45
+ }
46
+
47
+ function createSuperAdminContext(overrides: Partial<ServiceContext> = {}): ServiceContext {
48
+ const user = createSuperAdminFixture({
49
+ id: 'super-admin-123',
50
+ email: 'superadmin@example.com',
51
+ name: 'Super Admin',
52
+ })
53
+
54
+ return {
55
+ accountId: 'account-123',
56
+ user,
57
+ userRole: 'ADMIN',
58
+ transactionId: 'tx-123',
59
+ ip: '127.0.0.1',
60
+ userAgent: 'TestAgent/1.0',
61
+ ...overrides,
62
+ }
63
+ }
64
+
65
+ describe('usersService', () => {
66
+ let ctx: ServiceContext
67
+ let superAdminCtx: ServiceContext
68
+
69
+ beforeEach(() => {
70
+ vi.clearAllMocks()
71
+ ctx = createMockContext()
72
+ superAdminCtx = createSuperAdminContext()
73
+ })
74
+
75
+ describe('findAll', () => {
76
+ const defaultPagination: PaginationQuery = { page: 1, limit: 10 }
77
+
78
+ it('should return paginated users for super admin', async () => {
79
+ const user = createUserFixture({ id: 'user-1', email: 'user@example.com' })
80
+
81
+ ;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
82
+ ;(queryAll as Mock).mockResolvedValueOnce([
83
+ {
84
+ id: user.id,
85
+ google_id: user.googleId,
86
+ email: user.email,
87
+ name: user.name,
88
+ avatar_url: user.avatarUrl,
89
+ status: user.status,
90
+ provider_ids: JSON.stringify(user.providerIds),
91
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
92
+ created_at: user.createdAt,
93
+ updated_at: user.updatedAt,
94
+ deleted_at: user.deletedAt,
95
+ },
96
+ ])
97
+
98
+ const result = await usersService.findAll(db, superAdminCtx, defaultPagination)
99
+
100
+ expect(result.data).toHaveLength(1)
101
+ expect(result.meta.totalItems).toBe(1)
102
+ })
103
+ })
104
+
105
+ describe('findById', () => {
106
+ it('should throw NotFound when user missing', async () => {
107
+ ;(queryOne as Mock).mockResolvedValueOnce(null)
108
+
109
+ await expect(usersService.findById(db, superAdminCtx, 'missing')).rejects.toThrow(NotFoundError)
110
+ })
111
+
112
+ it('should enforce membership for non-super-admin', async () => {
113
+ const user = createUserFixture({ id: 'user-1' })
114
+
115
+ ;(queryOne as Mock)
116
+ .mockResolvedValueOnce({
117
+ id: user.id,
118
+ google_id: user.googleId,
119
+ email: user.email,
120
+ name: user.name,
121
+ avatar_url: user.avatarUrl,
122
+ status: user.status,
123
+ provider_ids: JSON.stringify(user.providerIds),
124
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
125
+ created_at: user.createdAt,
126
+ updated_at: user.updatedAt,
127
+ deleted_at: user.deletedAt,
128
+ })
129
+ .mockResolvedValueOnce(null)
130
+
131
+ await expect(usersService.findById(db, ctx, user.id)).rejects.toThrow(NotFoundError)
132
+ })
133
+ })
134
+
135
+ describe('update', () => {
136
+ it('should update user and return record', async () => {
137
+ const user = createUserFixture({ id: 'user-1', name: 'Old Name' })
138
+
139
+ ;(queryOne as Mock).mockResolvedValueOnce({
140
+ id: user.id,
141
+ google_id: user.googleId,
142
+ email: user.email,
143
+ name: user.name,
144
+ avatar_url: user.avatarUrl,
145
+ status: user.status,
146
+ provider_ids: JSON.stringify(user.providerIds),
147
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
148
+ created_at: user.createdAt,
149
+ updated_at: user.updatedAt,
150
+ deleted_at: user.deletedAt,
151
+ })
152
+
153
+ const updated = { ...user, name: 'Updated Name' }
154
+ ;(auditedUpdate as Mock).mockResolvedValueOnce([
155
+ {
156
+ id: updated.id,
157
+ google_id: updated.googleId,
158
+ email: updated.email,
159
+ name: updated.name,
160
+ avatar_url: updated.avatarUrl,
161
+ status: updated.status,
162
+ provider_ids: JSON.stringify(updated.providerIds),
163
+ is_super_admin: updated.isSuperAdmin ? 1 : 0,
164
+ created_at: updated.createdAt,
165
+ updated_at: updated.updatedAt,
166
+ deleted_at: updated.deletedAt,
167
+ },
168
+ ])
169
+
170
+ const result = await usersService.update(db, superAdminCtx, user.id, { name: 'Updated Name' })
171
+
172
+ expect(result.name).toBe('Updated Name')
173
+ })
174
+ })
175
+
176
+ describe('delete', () => {
177
+ it('should delete user with audit', async () => {
178
+ const user = createUserFixture({ id: 'user-1' })
179
+ ;(queryOne as Mock).mockResolvedValueOnce({
180
+ id: user.id,
181
+ google_id: user.googleId,
182
+ email: user.email,
183
+ name: user.name,
184
+ avatar_url: user.avatarUrl,
185
+ status: user.status,
186
+ provider_ids: JSON.stringify(user.providerIds),
187
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
188
+ created_at: user.createdAt,
189
+ updated_at: user.updatedAt,
190
+ deleted_at: user.deletedAt,
191
+ })
192
+
193
+ await usersService.delete(db, superAdminCtx, user.id)
194
+
195
+ expect(auditedDelete).toHaveBeenCalled()
196
+ })
197
+ })
198
+
199
+ describe('restore', () => {
200
+ it('should restore soft-deleted user', async () => {
201
+ const user = createUserFixture({ id: 'user-1', deletedAt: new Date().toISOString() })
202
+ ;(queryOne as Mock).mockResolvedValueOnce({
203
+ id: user.id,
204
+ google_id: user.googleId,
205
+ email: user.email,
206
+ name: user.name,
207
+ avatar_url: user.avatarUrl,
208
+ status: user.status,
209
+ provider_ids: JSON.stringify(user.providerIds),
210
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
211
+ created_at: user.createdAt,
212
+ updated_at: user.updatedAt,
213
+ deleted_at: user.deletedAt,
214
+ })
215
+
216
+ const restored = { ...user, deletedAt: null }
217
+ ;(auditedUpdate as Mock).mockResolvedValueOnce([
218
+ {
219
+ id: restored.id,
220
+ google_id: restored.googleId,
221
+ email: restored.email,
222
+ name: restored.name,
223
+ avatar_url: restored.avatarUrl,
224
+ status: restored.status,
225
+ provider_ids: JSON.stringify(restored.providerIds),
226
+ is_super_admin: restored.isSuperAdmin ? 1 : 0,
227
+ created_at: restored.createdAt,
228
+ updated_at: restored.updatedAt,
229
+ deleted_at: restored.deletedAt,
230
+ },
231
+ ])
232
+
233
+ const result = await usersService.restore(db, superAdminCtx, user.id)
234
+
235
+ expect(result.deletedAt).toBeNull()
236
+ })
237
+ })
238
+
239
+ describe('listUserRoles', () => {
240
+ it('should list roles for user', async () => {
241
+ const user = createUserFixture({ id: 'user-1' })
242
+
243
+ ;(queryOne as Mock)
244
+ .mockResolvedValueOnce({
245
+ id: user.id,
246
+ google_id: user.googleId,
247
+ email: user.email,
248
+ name: user.name,
249
+ avatar_url: user.avatarUrl,
250
+ status: user.status,
251
+ provider_ids: JSON.stringify(user.providerIds),
252
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
253
+ created_at: user.createdAt,
254
+ updated_at: user.updatedAt,
255
+ deleted_at: user.deletedAt,
256
+ })
257
+ .mockResolvedValueOnce({ ok: 1 })
258
+
259
+ ;(queryAll as Mock).mockResolvedValueOnce([
260
+ { accountId: 'account-1', role: 'ADMIN' },
261
+ { accountId: 'account-2', role: 'VIEWER' },
262
+ ])
263
+
264
+ const result = await usersService.listUserRoles(db, ctx, user.id)
265
+
266
+ expect(result).toHaveLength(2)
267
+ })
268
+ })
269
+
270
+ describe('updateRole', () => {
271
+ it('should update role and log audit', async () => {
272
+ const user = createUserFixture({ id: 'user-1' })
273
+
274
+ ;(queryOne as Mock)
275
+ .mockResolvedValueOnce({
276
+ id: user.id,
277
+ google_id: user.googleId,
278
+ email: user.email,
279
+ name: user.name,
280
+ avatar_url: user.avatarUrl,
281
+ status: user.status,
282
+ provider_ids: JSON.stringify(user.providerIds),
283
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
284
+ created_at: user.createdAt,
285
+ updated_at: user.updatedAt,
286
+ deleted_at: user.deletedAt,
287
+ })
288
+ .mockResolvedValueOnce({ role: 'VIEWER' })
289
+
290
+ await usersService.updateRole(db, superAdminCtx, user.id, 'account-1', 'ADMIN')
291
+
292
+ expect(execute).toHaveBeenCalled()
293
+ expect(logAudit).toHaveBeenCalled()
294
+ })
295
+ })
296
+
297
+ describe('removeFromAccount', () => {
298
+ it('should remove membership and log audit', async () => {
299
+ const user = createUserFixture({ id: 'user-1' })
300
+
301
+ ;(queryOne as Mock).mockResolvedValueOnce({
302
+ id: user.id,
303
+ google_id: user.googleId,
304
+ email: user.email,
305
+ name: user.name,
306
+ avatar_url: user.avatarUrl,
307
+ status: user.status,
308
+ provider_ids: JSON.stringify(user.providerIds),
309
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
310
+ created_at: user.createdAt,
311
+ updated_at: user.updatedAt,
312
+ deleted_at: user.deletedAt,
313
+ })
314
+
315
+ await usersService.removeFromAccount(db, superAdminCtx, user.id, 'account-1')
316
+
317
+ expect(execute).toHaveBeenCalled()
318
+ expect(logAudit).toHaveBeenCalled()
319
+ })
320
+ })
321
+
322
+ describe('createUserAccounts', () => {
323
+ it('should upsert memberships and return count', async () => {
324
+ const items = [
325
+ { userId: 'user-1', accountId: 'account-1', role: 'ADMIN' as const },
326
+ { userId: 'user-2', accountId: 'account-1', role: 'VIEWER' as const },
327
+ ]
328
+
329
+ ;(queryOne as Mock).mockResolvedValue(null)
330
+
331
+ const result = await usersService.createUserAccounts(db, superAdminCtx, items)
332
+
333
+ expect(result.count).toBe(2)
334
+ expect(logAudit).toHaveBeenCalled()
335
+ })
336
+ })
337
+
338
+ describe('deleteUserAccounts', () => {
339
+ it('should delete memberships and return count', async () => {
340
+ const items = [
341
+ { userId: 'user-1', accountId: 'account-1', role: 'ADMIN' as const },
342
+ { userId: 'user-2', accountId: 'account-1', role: 'VIEWER' as const },
343
+ ]
344
+
345
+ const result = await usersService.deleteUserAccounts(db, superAdminCtx, items)
346
+
347
+ expect(result.count).toBe(2)
348
+ expect(logAudit).toHaveBeenCalled()
349
+ })
350
+ })
351
+ })
@@ -19,7 +19,8 @@
19
19
  "paths": {
20
20
  "@/*": ["./src/client/*"],
21
21
  "@shared/*": ["./src/shared/*"],
22
- "@server/*": ["./src/server/*"]
22
+ "@server/*": ["./src/server/*"],
23
+ "@tests/*": ["./tests/*"]
23
24
  }
24
25
  },
25
26
  "include": ["src"],
@@ -13,6 +13,7 @@ export default defineConfig({
13
13
  alias: {
14
14
  "@": fileURLToPath(new URL("./src/client", import.meta.url)),
15
15
  "@shared": fileURLToPath(new URL("./src/shared", import.meta.url)),
16
+ "@tests": fileURLToPath(new URL("./tests", import.meta.url)),
16
17
  },
17
18
  },
18
19
  test: {
@@ -27,9 +28,9 @@ export default defineConfig({
27
28
  // Vitest 4: Schema matching with Zod
28
29
  setupFiles: [
29
30
  "./src/test/vitest-zod-matcher.ts",
30
- "./src/client/__tests__/setup-browser.ts",
31
+ "./tests/helpers/client-setup-browser.ts",
31
32
  ],
32
- include: ["src/client/**/*.test.{ts,tsx}"],
33
+ include: ["tests/unit/client/**/*.test.{ts,tsx}"],
33
34
  exclude: ["node_modules", ".claude", "dist"],
34
35
  coverage: {
35
36
  provider: "v8",
@@ -10,13 +10,14 @@ export default defineConfig({
10
10
  alias: {
11
11
  "@": fileURLToPath(new URL("./src/client", import.meta.url)),
12
12
  "@shared": fileURLToPath(new URL("./src/shared", import.meta.url)),
13
+ "@tests": fileURLToPath(new URL("./tests", import.meta.url)),
13
14
  },
14
15
  },
15
16
  test: {
16
17
  globals: true,
17
18
  environment: "jsdom",
18
- setupFiles: ["./src/client/__tests__/setup.ts"],
19
- include: ["src/client/**/*.test.{ts,tsx}"],
19
+ setupFiles: ["./tests/helpers/client-setup.ts"],
20
+ include: ["tests/unit/client/**/*.test.{ts,tsx}"],
20
21
  exclude: ["node_modules", ".claude", "dist"],
21
22
  // Increase timeout for route tests that have async loading
22
23
  testTimeout: 15000,
@@ -11,6 +11,7 @@ export default defineConfig({
11
11
  "@": fileURLToPath(new URL("./src/client", import.meta.url)),
12
12
  "@shared": fileURLToPath(new URL("./src/shared", import.meta.url)),
13
13
  "@server": fileURLToPath(new URL("./src/server", import.meta.url)),
14
+ "@tests": fileURLToPath(new URL("./tests", import.meta.url)),
14
15
  },
15
16
  },
16
17
  test: {
@@ -18,13 +19,14 @@ export default defineConfig({
18
19
  environment: "node",
19
20
  // Vitest 4: Schema matching with Zod
20
21
  setupFiles: ["./src/test/vitest-zod-matcher.ts"],
21
- include: ["src/server/**/*.test.ts", "src/shared/**/*.test.ts"],
22
+ include: ["tests/unit/server/**/*.test.ts", "tests/unit/shared/**/*.test.ts"],
22
23
  exclude: [
23
24
  "**/node_modules/**",
24
25
  "**/.claude/**",
25
26
  "**/dist/**",
26
27
  "**/e2e/**",
27
28
  "**/src/client/**",
29
+ "**/tests/unit/client/**",
28
30
  ],
29
31
  coverage: {
30
32
  provider: "v8",
@@ -42,18 +44,11 @@ export default defineConfig({
42
44
  // Database setup (not business logic)
43
45
  "src/server/db/client.ts",
44
46
  "src/server/db/seed.ts",
47
+ "src/server/db/records.ts",
45
48
  // Barrel exports (just re-exports, no logic)
46
- "src/server/db/schema/index.ts",
47
49
  "src/server/services/index.ts",
48
50
  "src/server/middleware/index.ts",
49
51
  "src/shared/schemas/index.ts",
50
- // Drizzle schema definitions (table structures, not business logic)
51
- "src/server/db/schema/users.ts",
52
- "src/server/db/schema/accounts.ts",
53
- "src/server/db/schema/user-accounts.ts",
54
- "src/server/db/schema/audit-logs.ts",
55
- "src/server/db/schema/refresh-tokens.ts",
56
- "src/server/db/schema/invitations.ts",
57
52
  // Utility/infrastructure with hard-to-test edge cases
58
53
  "src/server/lib/password.ts",
59
54
  "src/server/lib/audit.ts",
@@ -62,8 +57,6 @@ export default defineConfig({
62
57
  // API documentation and router config (not testable)
63
58
  "src/server/routes/api.ts",
64
59
  "src/server/routes/index.ts",
65
- // Simple utilities (low value to test)
66
- "src/server/lib/schema-helpers.ts",
67
60
  // Dev-only endpoint (tested via E2E)
68
61
  "src/server/routes/auth/test-login.ts",
69
62
  // Integration test fixtures
@@ -72,10 +65,10 @@ export default defineConfig({
72
65
  "src/server/__integration__/fixtures/**",
73
66
  ],
74
67
  thresholds: {
75
- statements: 90,
76
- branches: 84, // Handlers have hard-to-test error branches
68
+ statements: 85,
69
+ branches: 80,
77
70
  functions: 85,
78
- lines: 90,
71
+ lines: 85,
79
72
  },
80
73
  },
81
74
  },
@@ -1,11 +0,0 @@
1
- {
2
- "permissions": {
3
- "additionalDirectories": [
4
- "/Users/albertoandre/Dropbox/aa-projects/Github/etus-nest-boilerplate/boilerplate/",
5
- "/Users/albertoandre/Dropbox/aa-projects/Github/oauth-gateway/"
6
- ],
7
- "allow": [
8
- "Skill(superpowers:subagent-driven-development)"
9
- ]
10
- }
11
- }
@@ -1,10 +0,0 @@
1
- import { defineConfig } from 'drizzle-kit'
2
-
3
- export default defineConfig({
4
- schema: '../src/server/db/schema/index.ts',
5
- out: '../src/server/db/migrations',
6
- dialect: 'sqlite',
7
- dbCredentials: {
8
- url: '../.wrangler/state/v3/d1/miniflare-D1DatabaseObject/a9de77f83189-41d984dda38d3c9c27bd.sqlite',
9
- },
10
- })
@@ -1,20 +0,0 @@
1
- // src/db/schema/accounts.ts
2
- import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
3
- import { sql } from 'drizzle-orm'
4
-
5
- export const accounts = sqliteTable('accounts', {
6
- id: text('id')
7
- .primaryKey()
8
- .$defaultFn(() => crypto.randomUUID()),
9
- name: text('name').notNull(),
10
- description: text('description'),
11
- domain: text('domain').unique(),
12
-
13
- // Soft delete fields
14
- createdAt: text('created_at').default(sql`(datetime('now'))`).notNull(),
15
- updatedAt: text('updated_at').default(sql`(datetime('now'))`).notNull(),
16
- deletedAt: text('deleted_at'),
17
- })
18
-
19
- export type AccountRecord = typeof accounts.$inferSelect
20
- export type NewAccount = typeof accounts.$inferInsert
@@ -1,26 +0,0 @@
1
- // src/db/schema/audit-logs.ts
2
- import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
3
- import { sql } from 'drizzle-orm'
4
- import { users } from './users'
5
- import { accounts } from './accounts'
6
-
7
- export const auditLogs = sqliteTable('audit_logs', {
8
- id: text('id')
9
- .primaryKey()
10
- .$defaultFn(() => crypto.randomUUID()),
11
- transactionId: text('transaction_id').notNull(),
12
- accountId: text('account_id').references(() => accounts.id),
13
- userId: text('user_id').references(() => users.id),
14
- entity: text('entity').notNull(),
15
- entityId: text('entity_id').notNull(),
16
- action: text('action', {
17
- enum: ['INSERT', 'UPDATE', 'DELETE', 'LOGIN', 'LOGOUT', 'SIGNUP', 'TOKEN_REFRESH', 'LOGIN_FAILED']
18
- }).notNull(),
19
- changes: text('changes', { mode: 'json' }).$type<Record<string, unknown>>(),
20
- ipAddress: text('ip_address'),
21
- userAgent: text('user_agent'),
22
- timestamp: text('timestamp').default(sql`(datetime('now'))`).notNull(),
23
- })
24
-
25
- export type AuditLogRecord = typeof auditLogs.$inferSelect
26
- export type NewAuditLog = typeof auditLogs.$inferInsert
@@ -1,7 +0,0 @@
1
- // src/db/schema/index.ts
2
- export * from './users'
3
- export * from './accounts'
4
- export * from './user-accounts'
5
- export * from './audit-logs'
6
- export * from './refresh-tokens'
7
- export * from './invitations'
@@ -1,30 +0,0 @@
1
- // src/db/schema/invitations.ts
2
- import { sqliteTable, text, uniqueIndex } from 'drizzle-orm/sqlite-core'
3
- import { sql } from 'drizzle-orm'
4
- import { accounts } from './accounts'
5
- import { users } from './users'
6
-
7
- export const invitations = sqliteTable('invitations', {
8
- id: text('id')
9
- .primaryKey()
10
- .$defaultFn(() => crypto.randomUUID()),
11
- accountId: text('account_id')
12
- .notNull()
13
- .references(() => accounts.id, { onDelete: 'cascade' }),
14
- email: text('email').notNull(),
15
- role: text('role', {
16
- enum: ['ADMIN', 'MANAGER', 'EDITOR', 'AUTHOR', 'VIEWER', 'BILLING', 'ANALYTICS'],
17
- }).notNull(),
18
- token: text('token').notNull().unique(),
19
- invitedById: text('invited_by_id')
20
- .notNull()
21
- .references(() => users.id),
22
- expiresAt: text('expires_at').notNull(),
23
- acceptedAt: text('accepted_at'),
24
- createdAt: text('created_at').default(sql`(datetime('now'))`).notNull(),
25
- }, (table) => [
26
- uniqueIndex('account_email_idx').on(table.accountId, table.email),
27
- ])
28
-
29
- export type InvitationRecord = typeof invitations.$inferSelect
30
- export type NewInvitation = typeof invitations.$inferInsert
@@ -1,22 +0,0 @@
1
- // src/db/schema/refresh-tokens.ts
2
- import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core'
3
- import { sql } from 'drizzle-orm'
4
- import { users } from './users'
5
-
6
- export const refreshTokens = sqliteTable('refresh_tokens', {
7
- id: text('id')
8
- .primaryKey()
9
- .$defaultFn(() => crypto.randomUUID()),
10
- userId: text('user_id')
11
- .notNull()
12
- .references(() => users.id, { onDelete: 'cascade' }),
13
- tokenHash: text('token_hash').notNull(),
14
- expiresAt: integer('expires_at', { mode: 'timestamp' }).notNull(),
15
- createdAt: integer('created_at', { mode: 'timestamp' })
16
- .notNull()
17
- .default(sql`(unixepoch())`),
18
- revokedAt: integer('revoked_at', { mode: 'timestamp' }),
19
- })
20
-
21
- export type RefreshTokenRecord = typeof refreshTokens.$inferSelect
22
- export type NewRefreshToken = typeof refreshTokens.$inferInsert
@@ -1,25 +0,0 @@
1
- // src/db/schema/user-accounts.ts
2
- import { sqliteTable, text, primaryKey } from 'drizzle-orm/sqlite-core'
3
- import { users } from './users'
4
- import { accounts } from './accounts'
5
-
6
- export const userAccounts = sqliteTable(
7
- 'user_accounts',
8
- {
9
- userId: text('user_id')
10
- .notNull()
11
- .references(() => users.id, { onDelete: 'cascade' }),
12
- accountId: text('account_id')
13
- .notNull()
14
- .references(() => accounts.id, { onDelete: 'cascade' }),
15
- role: text('role', {
16
- enum: ['ADMIN', 'MANAGER', 'EDITOR', 'AUTHOR', 'VIEWER', 'BILLING', 'ANALYTICS'],
17
- }).notNull(),
18
- },
19
- (table) => [
20
- primaryKey({ columns: [table.userId, table.accountId] }),
21
- ]
22
- )
23
-
24
- export type UserAccountRecord = typeof userAccounts.$inferSelect
25
- export type NewUserAccount = typeof userAccounts.$inferInsert
@@ -1,33 +0,0 @@
1
- // src/db/schema/users.ts
2
- import { sqliteTable, text, integer, type AnySQLiteColumn } from 'drizzle-orm/sqlite-core'
3
- import { sql } from 'drizzle-orm'
4
-
5
- export const users = sqliteTable('users', {
6
- id: text('id')
7
- .primaryKey()
8
- .$defaultFn(() => crypto.randomUUID()),
9
- googleId: text('google_id').notNull().unique(),
10
- email: text('email').notNull(),
11
- name: text('name').notNull(),
12
- avatarUrl: text('avatar_url'),
13
- status: text('status', { enum: ['active', 'inactive'] })
14
- .default('active')
15
- .notNull(),
16
- providerIds: text('provider_ids', { mode: 'json' })
17
- .$type<string[]>()
18
- .default([]),
19
- isSuperAdmin: integer('is_super_admin', { mode: 'boolean' })
20
- .default(false)
21
- .notNull(),
22
-
23
- // Soft delete + audit fields
24
- createdAt: text('created_at').default(sql`(datetime('now'))`).notNull(),
25
- updatedAt: text('updated_at').default(sql`(datetime('now'))`).notNull(),
26
- deletedAt: text('deleted_at'),
27
- createdById: text('created_by_id').references((): AnySQLiteColumn => users.id),
28
- updatedById: text('updated_by_id').references((): AnySQLiteColumn => users.id),
29
- deletedById: text('deleted_by_id').references((): AnySQLiteColumn => users.id),
30
- })
31
-
32
- export type UserRecord = typeof users.$inferSelect
33
- export type NewUser = typeof users.$inferInsert