@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
@@ -1,9 +1,9 @@
1
1
  // src/server/routes/health/__tests__/handlers.test.ts
2
2
  import { describe, it, expect, vi, beforeEach } from 'vitest'
3
3
  import { Hono } from 'hono'
4
- import type { HonoEnv } from '../../../types'
5
- import { health } from '../index'
6
- import { createMockEnv } from '../../../__tests__/setup'
4
+ import type { HonoEnv } from '@server/types'
5
+ import { health } from '@server/routes/index'
6
+ import { createMockEnv } from '@tests/helpers/server'
7
7
 
8
8
  describe('Health Routes', () => {
9
9
  let mockEnv: ReturnType<typeof createMockEnv>
@@ -13,19 +13,15 @@ describe('Health Routes', () => {
13
13
  mockEnv = createMockEnv()
14
14
  })
15
15
 
16
- // Helper to create app with specific db mock
17
- function createApp(dbMock?: any) {
16
+ // Helper to create app with environment overrides
17
+ function createApp(envOverrides?: Partial<typeof mockEnv>) {
18
18
  const app = new Hono<HonoEnv>()
19
19
 
20
20
  // Setup middleware to inject mock environment
21
21
  app.use('*', async (c, next) => {
22
+ const env = { ...mockEnv, ...(envOverrides ?? {}) }
22
23
  // Set environment bindings by mutating c.env
23
- ;(c as any).env = mockEnv
24
- // Create mock db that supports sql template literal
25
- const mockDb = dbMock ?? {
26
- run: vi.fn().mockResolvedValue({ rows: [{ 1: 1 }] }),
27
- }
28
- c.set('db', mockDb)
24
+ ;(c as any).env = env
29
25
  await next()
30
26
  })
31
27
 
@@ -64,9 +60,11 @@ describe('Health Routes', () => {
64
60
 
65
61
  // Create app with failing db
66
62
  const failingDb = {
67
- run: vi.fn().mockRejectedValue(new Error('DB connection failed')),
68
- }
69
- const app = createApp(failingDb)
63
+ prepare: vi.fn(() => {
64
+ throw new Error('DB connection failed')
65
+ }),
66
+ } as D1Database
67
+ const app = createApp({ DB: failingDb })
70
68
 
71
69
  const res = await app.request('/health', {
72
70
  method: 'GET',
@@ -125,9 +123,11 @@ describe('Health Routes', () => {
125
123
 
126
124
  // Create app with failing db
127
125
  const failingDb = {
128
- run: vi.fn().mockRejectedValue(new Error('DB connection failed')),
129
- }
130
- const app = createApp(failingDb)
126
+ prepare: vi.fn(() => {
127
+ throw new Error('DB connection failed')
128
+ }),
129
+ } as D1Database
130
+ const app = createApp({ DB: failingDb })
131
131
 
132
132
  const res = await app.request('/health', {
133
133
  method: 'GET',
@@ -156,9 +156,11 @@ describe('Health Routes', () => {
156
156
  it('returns 503 when db is down', async () => {
157
157
  // Create app with failing db
158
158
  const failingDb = {
159
- run: vi.fn().mockRejectedValue(new Error('DB connection failed')),
160
- }
161
- const app = createApp(failingDb)
159
+ prepare: vi.fn(() => {
160
+ throw new Error('DB connection failed')
161
+ }),
162
+ } as D1Database
163
+ const app = createApp({ DB: failingDb })
162
164
 
163
165
  const res = await app.request('/health/ready', {
164
166
  method: 'GET',
@@ -196,9 +198,11 @@ describe('Health Routes', () => {
196
198
  it('returns alive even when db is down', async () => {
197
199
  // Create app with failing db
198
200
  const failingDb = {
199
- run: vi.fn().mockRejectedValue(new Error('DB connection failed')),
200
- }
201
- const app = createApp(failingDb)
201
+ prepare: vi.fn(() => {
202
+ throw new Error('DB connection failed')
203
+ }),
204
+ } as D1Database
205
+ const app = createApp({ DB: failingDb })
202
206
 
203
207
  const res = await app.request('/health/live', {
204
208
  method: 'GET',
@@ -1,11 +1,11 @@
1
1
  // src/server/routes/invitations/__tests__/handlers.test.ts
2
2
  import { describe, it, expect, vi, beforeEach } from 'vitest'
3
3
  import { Hono } from 'hono'
4
- import type { HonoEnv } from '../../../types'
5
- import { invitationsRouter } from '../index'
6
- import { createMockEnv } from '../../../__tests__/setup'
7
- import { createUserFixture, createAccountFixture } from '../../../__tests__/fixtures'
8
- import { NotFoundError, ConflictError, ForbiddenError } from '../../../lib/errors'
4
+ import type { HonoEnv } from '@server/types'
5
+ import { invitationsRouter } from '@server/routes/index'
6
+ import { createMockEnv } from '@tests/helpers/server'
7
+ import { createUserFixture, createAccountFixture } from '@tests/fixtures/server'
8
+ import { NotFoundError, ConflictError, ForbiddenError } from '@server/lib/errors'
9
9
 
10
10
  // Test UUIDs
11
11
  const TEST_USER_ID = '550e8400-e29b-41d4-a716-446655440001'
@@ -14,7 +14,7 @@ const TEST_INVITATION_ID = '550e8400-e29b-41d4-a716-446655440201'
14
14
  const NON_EXISTENT_ID = '550e8400-e29b-41d4-a716-446655440999'
15
15
 
16
16
  // Mock the invitations service
17
- vi.mock('../../../services/invitations', () => ({
17
+ vi.mock('@server/services/invitations', () => ({
18
18
  invitationsService: {
19
19
  create: vi.fn(),
20
20
  list: vi.fn(),
@@ -22,7 +22,7 @@ vi.mock('../../../services/invitations', () => ({
22
22
  },
23
23
  }))
24
24
 
25
- import { invitationsService } from '../../../services/invitations'
25
+ import { invitationsService } from '@server/services/invitations'
26
26
 
27
27
  describe('Invitations Routes', () => {
28
28
  let mockEnv: ReturnType<typeof createMockEnv>
@@ -214,7 +214,7 @@ describe('Invitations Routes', () => {
214
214
  })
215
215
 
216
216
  expect(invitationsService.create).toHaveBeenCalledWith(
217
- mockDb,
217
+ mockEnv.DB,
218
218
  mockEnv,
219
219
  expect.objectContaining({
220
220
  accountId: testAccount.id,
@@ -289,7 +289,7 @@ describe('Invitations Routes', () => {
289
289
  })
290
290
 
291
291
  expect(invitationsService.list).toHaveBeenCalledWith(
292
- mockDb,
292
+ mockEnv.DB,
293
293
  expect.objectContaining({
294
294
  accountId: testAccount.id,
295
295
  user: expect.objectContaining({ id: testUser.id }),
@@ -311,7 +311,7 @@ describe('Invitations Routes', () => {
311
311
 
312
312
  expect(res.status).toBe(204)
313
313
  expect(invitationsService.revoke).toHaveBeenCalledWith(
314
- mockDb,
314
+ mockEnv.DB,
315
315
  expect.objectContaining({
316
316
  accountId: testAccount.id,
317
317
  user: expect.objectContaining({ id: testUser.id }),
@@ -363,9 +363,11 @@ describe('Invitations Routes', () => {
363
363
  const brokenApp = new Hono<HonoEnv>()
364
364
  const testUser = createUserFixture({ id: TEST_USER_ID })
365
365
  const testAccount = createAccountFixture({ id: TEST_ACCOUNT_ID })
366
+ const mockEnv = createMockEnv()
367
+ ;(mockEnv as any).DB = undefined
366
368
 
367
369
  brokenApp.use('*', async (c, next) => {
368
- ;(c as any).env = createMockEnv()
370
+ ;(c as any).env = mockEnv
369
371
  c.set('db', null) // No database
370
372
  c.set('transactionId', 'test-transaction-id')
371
373
  c.set('ip', '127.0.0.1')
@@ -388,12 +390,7 @@ describe('Invitations Routes', () => {
388
390
 
389
391
  brokenApp.use('*', async (c, next) => {
390
392
  ;(c as any).env = mockEnv
391
- c.set('db', {
392
- select: vi.fn().mockReturnThis(),
393
- from: vi.fn().mockReturnThis(),
394
- where: vi.fn().mockReturnThis(),
395
- limit: vi.fn().mockResolvedValue([]),
396
- })
393
+ c.set('db', mockEnv.DB)
397
394
  c.set('transactionId', 'test-transaction-id')
398
395
  c.set('ip', '127.0.0.1')
399
396
  c.set('userAgent', 'TestAgent/1.0')
@@ -1,13 +1,13 @@
1
1
  // src/server/routes/storage/__tests__/handlers.test.ts
2
2
  import { describe, it, expect, vi, beforeEach } from 'vitest'
3
3
  import { Hono } from 'hono'
4
- import type { HonoEnv } from '../../../types'
5
- import { storage } from '../index'
6
- import { createMockEnv } from '../../../__tests__/setup'
7
- import { createUserFixture, createAccountFixture } from '../../../__tests__/fixtures'
4
+ import type { HonoEnv } from '@server/types'
5
+ import { storage } from '@server/routes/index'
6
+ import { createMockEnv } from '@tests/helpers/server'
7
+ import { createUserFixture, createAccountFixture } from '@tests/fixtures/server'
8
8
 
9
9
  // Mock the r2-storage lib
10
- vi.mock('../../../lib/r2-storage', () => ({
10
+ vi.mock('@server/lib/r2-storage', () => ({
11
11
  generateUploadUrl: vi.fn(),
12
12
  uploadFile: vi.fn(),
13
13
  deleteFile: vi.fn(),
@@ -19,7 +19,7 @@ import {
19
19
  uploadFile,
20
20
  deleteFile,
21
21
  getFileMetadata,
22
- } from '../../../lib/r2-storage'
22
+ } from '@server/lib/r2-storage'
23
23
 
24
24
  // Test UUIDs
25
25
  const TEST_USER_ID = '550e8400-e29b-41d4-a716-446655440001'
@@ -1,15 +1,15 @@
1
1
  // src/server/routes/users/__tests__/handlers.test.ts
2
2
  import { describe, it, expect, vi, beforeEach } from 'vitest'
3
3
  import { Hono } from 'hono'
4
- import type { HonoEnv } from '../../../types'
5
- import { users } from '../index'
6
- import { createMockEnv } from '../../../__tests__/setup'
4
+ import type { HonoEnv } from '@server/types'
5
+ import { users } from '@server/routes/index'
6
+ import { createMockEnv } from '@tests/helpers/server'
7
7
  import {
8
8
  createUserFixture,
9
9
  createAccountFixture,
10
10
  createDeletedUserFixture,
11
- } from '../../../__tests__/fixtures'
12
- import { NotFoundError } from '../../../lib/errors'
11
+ } from '@tests/fixtures/server'
12
+ import { NotFoundError } from '@server/lib/errors'
13
13
 
14
14
  // Test UUIDs
15
15
  const TEST_USER_ID = '550e8400-e29b-41d4-a716-446655440001'
@@ -18,7 +18,7 @@ const TEST_ACCOUNT_ID = '550e8400-e29b-41d4-a716-446655440101'
18
18
  const NON_EXISTENT_ID = '550e8400-e29b-41d4-a716-446655440999'
19
19
 
20
20
  // Mock the users service
21
- vi.mock('../../../services', () => ({
21
+ vi.mock('@server/services', () => ({
22
22
  usersService: {
23
23
  findAll: vi.fn(),
24
24
  findById: vi.fn(),
@@ -30,7 +30,7 @@ vi.mock('../../../services', () => ({
30
30
  },
31
31
  }))
32
32
 
33
- import { usersService } from '../../../services'
33
+ import { usersService } from '@server/services'
34
34
 
35
35
  describe('Users Routes', () => {
36
36
  let app: Hono<HonoEnv>
@@ -162,7 +162,7 @@ describe('Users Routes', () => {
162
162
 
163
163
  expect(res.status).toBe(200)
164
164
  expect(usersService.findAll).toHaveBeenCalledWith(
165
- mockDb,
165
+ mockEnv.DB,
166
166
  expect.objectContaining({
167
167
  accountId: testAccount.id,
168
168
  }),
@@ -212,7 +212,7 @@ describe('Users Routes', () => {
212
212
 
213
213
  expect(res.status).toBe(200)
214
214
  expect(usersService.findAll).toHaveBeenCalledWith(
215
- mockDb,
215
+ mockEnv.DB,
216
216
  expect.anything(),
217
217
  expect.objectContaining({
218
218
  query: 'search',
@@ -270,7 +270,7 @@ describe('Users Routes', () => {
270
270
  })
271
271
 
272
272
  expect(usersService.findById).toHaveBeenCalledWith(
273
- mockDb,
273
+ mockEnv.DB,
274
274
  expect.objectContaining({
275
275
  accountId: testAccount.id,
276
276
  user: expect.objectContaining({ id: testUser.id }),
@@ -328,7 +328,7 @@ describe('Users Routes', () => {
328
328
 
329
329
  expect(res.status).toBe(200)
330
330
  expect(usersService.update).toHaveBeenCalledWith(
331
- mockDb,
331
+ mockEnv.DB,
332
332
  expect.anything(),
333
333
  TEST_USER_ID,
334
334
  expect.objectContaining({ status: 'inactive' })
@@ -373,7 +373,7 @@ describe('Users Routes', () => {
373
373
 
374
374
  expect(res.status).toBe(204)
375
375
  expect(usersService.delete).toHaveBeenCalledWith(
376
- mockDb,
376
+ mockEnv.DB,
377
377
  expect.anything(),
378
378
  TEST_USER_ID
379
379
  )
@@ -0,0 +1,258 @@
1
+ // src/server/services/__tests__/accounts.test.ts
2
+ import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest'
3
+ import { accountsService } from '@server/services/accounts'
4
+ import { NotFoundError, ForbiddenError, ConflictError } from '@server/lib/errors'
5
+ import type { ServiceContext, PaginationQuery } from '@server/types'
6
+ import {
7
+ createUserFixture,
8
+ createSuperAdminFixture,
9
+ createAccountFixture,
10
+ createDeletedAccountFixture,
11
+ } from '@tests/fixtures/server'
12
+
13
+ vi.mock('@server/lib/audited-db', () => ({
14
+ auditedInsert: vi.fn(),
15
+ auditedUpdate: vi.fn(),
16
+ auditedDelete: vi.fn(),
17
+ }))
18
+
19
+ vi.mock('@server/db/sql', () => ({
20
+ queryOne: vi.fn(),
21
+ queryAll: vi.fn(),
22
+ execute: vi.fn(),
23
+ }))
24
+
25
+ import { auditedInsert, auditedUpdate, auditedDelete } from '@server/lib/audited-db'
26
+ import { queryOne, queryAll } from '@server/db/sql'
27
+
28
+ const db = {} as D1Database
29
+
30
+ function createMockContext(overrides: Partial<ServiceContext> = {}): ServiceContext {
31
+ const user = createUserFixture({
32
+ id: 'ctx-user-123',
33
+ email: 'context@example.com',
34
+ name: 'Context User',
35
+ })
36
+
37
+ return {
38
+ accountId: 'account-123',
39
+ user,
40
+ userRole: 'ADMIN',
41
+ transactionId: 'tx-123',
42
+ ip: '127.0.0.1',
43
+ userAgent: 'TestAgent/1.0',
44
+ ...overrides,
45
+ }
46
+ }
47
+
48
+ function createSuperAdminContext(overrides: Partial<ServiceContext> = {}): ServiceContext {
49
+ const user = createSuperAdminFixture({
50
+ id: 'super-admin-123',
51
+ email: 'superadmin@example.com',
52
+ name: 'Super Admin',
53
+ })
54
+
55
+ return {
56
+ accountId: 'account-123',
57
+ user,
58
+ userRole: 'ADMIN',
59
+ transactionId: 'tx-123',
60
+ ip: '127.0.0.1',
61
+ userAgent: 'TestAgent/1.0',
62
+ ...overrides,
63
+ }
64
+ }
65
+
66
+ describe('accountsService', () => {
67
+ let ctx: ServiceContext
68
+ let superAdminCtx: ServiceContext
69
+
70
+ beforeEach(() => {
71
+ vi.clearAllMocks()
72
+ ctx = createMockContext()
73
+ superAdminCtx = createSuperAdminContext()
74
+ })
75
+
76
+ describe('findAll', () => {
77
+ const defaultPagination: PaginationQuery = { page: 1, limit: 10 }
78
+
79
+ it('should return paginated accounts for super admin', async () => {
80
+ const account1 = createAccountFixture({ id: 'account-1', name: 'Account One' })
81
+ const account2 = createAccountFixture({ id: 'account-2', name: 'Account Two' })
82
+
83
+ ;(queryOne as Mock).mockResolvedValueOnce({ count: 2 })
84
+ ;(queryAll as Mock).mockResolvedValueOnce([
85
+ { ...account1, created_at: account1.createdAt, updated_at: account1.updatedAt, deleted_at: account1.deletedAt },
86
+ { ...account2, created_at: account2.createdAt, updated_at: account2.updatedAt, deleted_at: account2.deletedAt },
87
+ ])
88
+
89
+ const result = await accountsService.findAll(db, superAdminCtx, defaultPagination)
90
+
91
+ expect(result.data).toHaveLength(2)
92
+ expect(result.meta.totalItems).toBe(2)
93
+ })
94
+
95
+ it('should include user filter for non-super-admin', async () => {
96
+ const account = createAccountFixture({ id: 'account-1', name: 'User Account' })
97
+
98
+ ;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
99
+ ;(queryAll as Mock).mockResolvedValueOnce([
100
+ { ...account, created_at: account.createdAt, updated_at: account.updatedAt, deleted_at: account.deletedAt },
101
+ ])
102
+
103
+ await accountsService.findAll(db, ctx, defaultPagination)
104
+
105
+ expect((queryOne as Mock).mock.calls[0][2]).toContain(ctx.user.id)
106
+ })
107
+ })
108
+
109
+ describe('findById', () => {
110
+ it('should return account for super admin', async () => {
111
+ const account = createAccountFixture({ id: 'account-1' })
112
+ ;(queryOne as Mock).mockResolvedValueOnce({
113
+ ...account,
114
+ created_at: account.createdAt,
115
+ updated_at: account.updatedAt,
116
+ deleted_at: account.deletedAt,
117
+ })
118
+
119
+ const result = await accountsService.findById(db, superAdminCtx, account.id)
120
+
121
+ expect(result.id).toBe(account.id)
122
+ })
123
+
124
+ it('should throw NotFound when account missing', async () => {
125
+ ;(queryOne as Mock).mockResolvedValueOnce(null)
126
+
127
+ await expect(accountsService.findById(db, superAdminCtx, 'missing')).rejects.toThrow(NotFoundError)
128
+ })
129
+
130
+ it('should enforce membership for non-super-admin', async () => {
131
+ const account = createAccountFixture({ id: 'account-1' })
132
+ ;(queryOne as Mock)
133
+ .mockResolvedValueOnce({
134
+ ...account,
135
+ created_at: account.createdAt,
136
+ updated_at: account.updatedAt,
137
+ deleted_at: account.deletedAt,
138
+ })
139
+ .mockResolvedValueOnce(null)
140
+
141
+ await expect(accountsService.findById(db, ctx, account.id)).rejects.toThrow(NotFoundError)
142
+ })
143
+ })
144
+
145
+ describe('create', () => {
146
+ it('should reject non-super-admin users', async () => {
147
+ await expect(accountsService.create(db, ctx, { name: 'New' })).rejects.toThrow(ForbiddenError)
148
+ })
149
+
150
+ it('should reject duplicate domain', async () => {
151
+ ;(queryOne as Mock).mockResolvedValueOnce({ ok: 1 })
152
+
153
+ await expect(
154
+ accountsService.create(db, superAdminCtx, { name: 'Dup', domain: 'acme.com' })
155
+ ).rejects.toThrow(ConflictError)
156
+ })
157
+
158
+ it('should create account and return record', async () => {
159
+ const account = createAccountFixture({ id: 'account-1', name: 'New Account' })
160
+ ;(auditedInsert as Mock).mockResolvedValueOnce([
161
+ { ...account, created_at: account.createdAt, updated_at: account.updatedAt, deleted_at: account.deletedAt },
162
+ ])
163
+
164
+ const result = await accountsService.create(db, superAdminCtx, { name: 'New Account' })
165
+
166
+ expect(result.name).toBe('New Account')
167
+ expect(auditedInsert).toHaveBeenCalled()
168
+ })
169
+ })
170
+
171
+ describe('update', () => {
172
+ it('should reject non-super-admin users', async () => {
173
+ await expect(accountsService.update(db, ctx, 'account-1', { name: 'Updated' })).rejects.toThrow(ForbiddenError)
174
+ })
175
+
176
+ it('should reject duplicate domain', async () => {
177
+ const account = createAccountFixture({ id: 'account-1' })
178
+ ;(queryOne as Mock)
179
+ .mockResolvedValueOnce({
180
+ ...account,
181
+ created_at: account.createdAt,
182
+ updated_at: account.updatedAt,
183
+ deleted_at: account.deletedAt,
184
+ })
185
+ .mockResolvedValueOnce({ ok: 1 })
186
+
187
+ await expect(
188
+ accountsService.update(db, superAdminCtx, account.id, { domain: 'dup.com' })
189
+ ).rejects.toThrow(ConflictError)
190
+ })
191
+
192
+ it('should update account and return record', async () => {
193
+ const account = createAccountFixture({ id: 'account-1', name: 'Original' })
194
+ ;(queryOne as Mock)
195
+ .mockResolvedValueOnce({
196
+ ...account,
197
+ created_at: account.createdAt,
198
+ updated_at: account.updatedAt,
199
+ deleted_at: account.deletedAt,
200
+ })
201
+
202
+ const updated = { ...account, name: 'Updated' }
203
+ ;(auditedUpdate as Mock).mockResolvedValueOnce([
204
+ { ...updated, created_at: updated.createdAt, updated_at: updated.updatedAt, deleted_at: updated.deletedAt },
205
+ ])
206
+
207
+ const result = await accountsService.update(db, superAdminCtx, account.id, { name: 'Updated' })
208
+
209
+ expect(result.name).toBe('Updated')
210
+ expect(auditedUpdate).toHaveBeenCalled()
211
+ })
212
+ })
213
+
214
+ describe('delete', () => {
215
+ it('should reject non-super-admin users', async () => {
216
+ await expect(accountsService.delete(db, ctx, 'account-1')).rejects.toThrow(ForbiddenError)
217
+ })
218
+
219
+ it('should delete account for super admin', async () => {
220
+ const account = createAccountFixture({ id: 'account-1' })
221
+ ;(queryOne as Mock).mockResolvedValueOnce({
222
+ ...account,
223
+ created_at: account.createdAt,
224
+ updated_at: account.updatedAt,
225
+ deleted_at: account.deletedAt,
226
+ })
227
+
228
+ await accountsService.delete(db, superAdminCtx, account.id)
229
+
230
+ expect(auditedDelete).toHaveBeenCalled()
231
+ })
232
+ })
233
+
234
+ describe('restore', () => {
235
+ it('should reject non-super-admin users', async () => {
236
+ await expect(accountsService.restore(db, ctx, 'account-1')).rejects.toThrow(ForbiddenError)
237
+ })
238
+
239
+ it('should restore soft-deleted account', async () => {
240
+ const deleted = createDeletedAccountFixture({ id: 'account-1' })
241
+ ;(queryOne as Mock).mockResolvedValueOnce({
242
+ ...deleted,
243
+ created_at: deleted.createdAt,
244
+ updated_at: deleted.updatedAt,
245
+ deleted_at: deleted.deletedAt,
246
+ })
247
+
248
+ const restored = createAccountFixture({ id: 'account-1' })
249
+ ;(auditedUpdate as Mock).mockResolvedValueOnce([
250
+ { ...restored, created_at: restored.createdAt, updated_at: restored.updatedAt, deleted_at: restored.deletedAt },
251
+ ])
252
+
253
+ const result = await accountsService.restore(db, superAdminCtx, deleted.id)
254
+
255
+ expect(result.deletedAt).toBeNull()
256
+ })
257
+ })
258
+ })