@etus/bhono-app 0.1.5 → 0.1.7

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 (300) hide show
  1. package/dist/index.js +0 -0
  2. package/package.json +7 -2
  3. package/templates/base/.claude/commands/check-skill-rules.md +112 -29
  4. package/templates/base/.claude/commands/linear/implement-issue.md +383 -55
  5. package/templates/base/.claude/commands/ship.md +77 -13
  6. package/templates/base/.claude/hooks/package-lock.json +0 -419
  7. package/templates/base/.claude/hooks/skill-activation-prompt.ts +185 -113
  8. package/templates/base/.claude/hooks/skill-tool-guard.sh +6 -0
  9. package/templates/base/.claude/hooks/skill-tool-guard.ts +198 -0
  10. package/templates/base/.claude/scripts/validate-skill-rules.sh +55 -32
  11. package/templates/base/.claude/settings.json +18 -11
  12. package/templates/base/.claude/skills/skill-rules.json +326 -173
  13. package/templates/base/.env.example +3 -0
  14. package/templates/base/CLAUDE.md +5 -5
  15. package/templates/base/README.md +40 -27
  16. package/templates/base/config/eslint.config.js +1 -0
  17. package/templates/base/config/wrangler.json +16 -17
  18. package/templates/base/docs/SETUP-GUIDE.md +566 -0
  19. package/templates/base/docs/app_spec.txt +13 -10
  20. package/templates/base/docs/architecture/README.md +162 -5
  21. package/templates/base/docs/architecture/api-catalog.md +575 -0
  22. package/templates/base/docs/architecture/c4-component.md +309 -0
  23. package/templates/base/docs/architecture/c4-container.md +183 -0
  24. package/templates/base/docs/architecture/c4-context.md +106 -0
  25. package/templates/base/docs/architecture/data-requirements.md +4 -3
  26. package/templates/base/docs/architecture/db-bootstrap.md +39 -0
  27. package/templates/base/docs/architecture/dependencies.md +327 -0
  28. package/templates/base/docs/architecture/drizzle-migration-plan.md +125 -0
  29. package/templates/base/docs/architecture/erd.md +1 -1
  30. package/templates/base/docs/architecture/sql-standards.md +100 -0
  31. package/templates/base/docs/architecture/tech-debt.md +184 -0
  32. package/templates/base/docs/testing.md +36 -29
  33. package/templates/base/package.json +26 -20
  34. package/templates/base/schema.sql +84 -0
  35. package/templates/base/scripts/capture-prod-session.ts +2 -2
  36. package/templates/base/scripts/init.sh +244 -59
  37. package/templates/base/scripts/sync-template.sh +104 -0
  38. package/templates/base/src/client/hooks/use-auth.ts +5 -0
  39. package/templates/base/src/client/routes/_authenticated/dashboard.tsx +1 -1
  40. package/templates/base/src/client/routes/index.tsx +1 -1
  41. package/templates/base/src/server/db/client.ts +3 -5
  42. package/templates/base/src/server/db/records.ts +81 -0
  43. package/templates/base/src/server/db/seed.ts +3 -2
  44. package/templates/base/src/server/db/sql.ts +116 -0
  45. package/templates/base/src/server/index.ts +17 -2
  46. package/templates/base/src/server/lib/audit.ts +74 -26
  47. package/templates/base/src/server/lib/audited-db.ts +219 -109
  48. package/templates/base/src/server/lib/transaction.ts +10 -16
  49. package/templates/base/src/server/middleware/account.ts +9 -16
  50. package/templates/base/src/server/middleware/auth.ts +102 -38
  51. package/templates/base/src/server/middleware/rate-limit.ts +8 -6
  52. package/templates/base/src/server/routes/accounts/handlers.ts +18 -6
  53. package/templates/base/src/server/routes/audits/handlers.ts +3 -1
  54. package/templates/base/src/server/routes/auth/handlers.ts +15 -10
  55. package/templates/base/src/server/routes/auth/test-login.ts +99 -45
  56. package/templates/base/src/server/routes/health/handlers.ts +4 -4
  57. package/templates/base/src/server/routes/index.ts +9 -0
  58. package/templates/base/src/server/routes/invitations/handlers.ts +9 -6
  59. package/templates/base/src/server/routes/openapi.ts +1 -1
  60. package/templates/base/src/server/routes/users/handlers.ts +21 -14
  61. package/templates/base/src/server/services/accounts.ts +242 -217
  62. package/templates/base/src/server/services/audits.ts +114 -61
  63. package/templates/base/src/server/services/auth.ts +310 -180
  64. package/templates/base/src/server/services/invitations.ts +282 -222
  65. package/templates/base/src/server/services/users.ts +383 -293
  66. package/templates/base/src/server/types/index.ts +1 -2
  67. package/templates/base/src/shared/types/api.ts +66 -198
  68. package/templates/base/tests/e2e/auth.setup.ts +1 -1
  69. package/templates/base/{src/server/__tests__/fixtures.ts → tests/fixtures/server.ts} +3 -3
  70. package/templates/base/{src/client/__tests__/setup-browser.ts → tests/helpers/client-setup-browser.ts} +2 -2
  71. package/templates/base/{src/client/__tests__/setup.ts → tests/helpers/client-setup.ts} +1 -1
  72. package/templates/base/{src/client/__tests__/test-utils.tsx → tests/helpers/client-test-utils.tsx} +2 -2
  73. package/templates/base/{src/server/__tests__/setup.ts → tests/helpers/server.ts} +9 -9
  74. package/templates/base/tests/integration/accounts/crud.test.ts +2 -11
  75. package/templates/base/tests/integration/audits/list.test.ts +2 -11
  76. package/templates/base/tests/integration/auth/auth-service.test.ts +1 -10
  77. package/templates/base/tests/integration/auth/invitation-token.test.ts +2 -11
  78. package/templates/base/tests/integration/auth/logout.test.ts +2 -11
  79. package/templates/base/tests/integration/auth/oauth.test.ts +23 -42
  80. package/templates/base/tests/integration/auth/refresh-token.test.ts +1 -9
  81. package/templates/base/tests/integration/auth/session-expiry.test.ts +1 -9
  82. package/templates/base/tests/integration/auth/session.test.ts +2 -11
  83. package/templates/base/tests/integration/auth/super-admin.test.ts +1 -9
  84. package/templates/base/tests/integration/authorization/analytics-role.test.ts +2 -11
  85. package/templates/base/tests/integration/authorization/billing-role.test.ts +2 -11
  86. package/templates/base/tests/integration/authorization/guards-roles.test.ts +1 -9
  87. package/templates/base/tests/integration/authorization/multi-tenancy.test.ts +2 -11
  88. package/templates/base/tests/integration/authorization/roles.test.ts +2 -11
  89. package/templates/base/tests/integration/config/production-behavior.test.ts +2 -11
  90. package/templates/base/tests/integration/health/health.test.ts +25 -44
  91. package/templates/base/tests/integration/invitations/crud.test.ts +2 -11
  92. package/templates/base/tests/integration/invitations/email.test.ts +1 -9
  93. package/templates/base/tests/integration/middleware/auth.test.ts +3 -12
  94. package/templates/base/tests/integration/middleware/request-logger.test.ts +1 -9
  95. package/templates/base/tests/integration/performance/response-times.test.ts +1 -9
  96. package/templates/base/tests/integration/security/cookie-security.test.ts +2 -11
  97. package/templates/base/tests/integration/security/csrf-protection.test.ts +2 -11
  98. package/templates/base/tests/integration/security/log-sanitization.test.ts +1 -9
  99. package/templates/base/tests/integration/security/rate-limiting.test.ts +1 -9
  100. package/templates/base/tests/integration/security/sql-injection.test.ts +7 -18
  101. package/templates/base/tests/integration/security/xss-prevention.test.ts +2 -11
  102. package/templates/base/tests/integration/setup.ts +13 -90
  103. package/templates/base/tests/integration/smoke.test.ts +3 -2
  104. package/templates/base/tests/integration/storage/upload.test.ts +2 -11
  105. package/templates/base/tests/integration/storage/validation.test.ts +2 -11
  106. package/templates/base/tests/integration/users/crud.test.ts +2 -11
  107. package/templates/base/tests/integration/users/list.test.ts +2 -11
  108. package/templates/base/tests/integration/vitest.config.ts +2 -9
  109. package/templates/base/{src/server/__tests__ → tests}/mocks/db.ts +1 -1
  110. package/templates/base/{src/server/__tests__ → tests}/mocks/index.ts +1 -1
  111. package/templates/base/{src/server/__tests__ → tests}/mocks/kv.ts +1 -1
  112. package/templates/base/{src/server/__tests__ → tests}/mocks/r2.ts +1 -1
  113. package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/sidebar.test.tsx +1 -1
  114. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/avatar.test.tsx +1 -1
  115. package/templates/base/{src/client/__tests__ → tests/unit/client/components/ui}/button.test.tsx +1 -1
  116. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/card.test.tsx +1 -1
  117. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/dialog.test.tsx +1 -1
  118. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/input.test.tsx +1 -1
  119. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/loading-skeleton.test.tsx +1 -1
  120. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/skeleton.test.tsx +1 -1
  121. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/sonner.test.tsx +1 -1
  122. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/tabs.test.tsx +1 -1
  123. package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/account.test.tsx +1 -1
  124. package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/integrations.test.tsx +1 -1
  125. package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/settings.test.tsx +1 -1
  126. package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/team.test.tsx +1 -1
  127. package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/authenticated-layout.test.tsx +1 -1
  128. package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/dashboard.test.tsx +1 -1
  129. package/templates/base/{src/client/routes/__tests__ → tests/unit/client/routes}/invite.test.tsx +1 -1
  130. package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/login.test.tsx +1 -1
  131. package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/navigation.test.tsx +1 -1
  132. package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/root-layout.test.tsx +1 -1
  133. package/templates/base/{src/server/auth/__tests__ → tests/unit/server/auth}/guards.test.ts +2 -2
  134. package/templates/base/{src → tests/unit}/server/auth/permissions.test.ts +1 -1
  135. package/templates/base/{src → tests/unit}/server/auth/roles.test.ts +1 -1
  136. package/templates/base/tests/unit/server/db/sql.test.ts +68 -0
  137. package/templates/base/{src → tests/unit}/server/env.test.ts +1 -1
  138. package/templates/base/tests/unit/server/lib/audited-db.test.ts +78 -0
  139. package/templates/base/{src → tests/unit}/server/lib/email.test.ts +1 -1
  140. package/templates/base/{src → tests/unit}/server/lib/errors.test.ts +1 -1
  141. package/templates/base/{src → tests/unit}/server/lib/oauth.test.ts +1 -1
  142. package/templates/base/{src → tests/unit}/server/lib/pagination.test.ts +1 -1
  143. package/templates/base/{src → tests/unit}/server/lib/password.test.ts +1 -1
  144. package/templates/base/{src → tests/unit}/server/lib/providers.test.ts +1 -1
  145. package/templates/base/{src → tests/unit}/server/lib/r2-storage.test.ts +2 -2
  146. package/templates/base/{src → tests/unit}/server/lib/session.test.ts +2 -2
  147. package/templates/base/{src → tests/unit}/server/lib/tokens.test.ts +1 -1
  148. package/templates/base/{src → tests/unit}/server/lib/transaction.test.ts +5 -14
  149. package/templates/base/{src → tests/unit}/server/middleware/account.test.ts +16 -24
  150. package/templates/base/tests/unit/server/middleware/auth.test.ts +647 -0
  151. package/templates/base/{src → tests/unit}/server/middleware/cors.test.ts +1 -1
  152. package/templates/base/{src → tests/unit}/server/middleware/error-handler.test.ts +2 -2
  153. package/templates/base/{src → tests/unit}/server/middleware/rate-limit.test.ts +3 -2
  154. package/templates/base/{src → tests/unit}/server/middleware/request-context.test.ts +1 -1
  155. package/templates/base/{src → tests/unit}/server/middleware/request-logger.test.ts +1 -1
  156. package/templates/base/{src/server/__tests__/mocks/__tests__ → tests/unit/server/mocks}/db.test.ts +1 -1
  157. package/templates/base/{src/server/__tests__/mocks/__tests__ → tests/unit/server/mocks}/kv.test.ts +1 -1
  158. package/templates/base/{src/server/__tests__/mocks/__tests__ → tests/unit/server/mocks}/r2.test.ts +1 -1
  159. package/templates/base/{src/server/routes/accounts/__tests__ → tests/unit/server/routes/accounts}/handlers.test.ts +12 -12
  160. package/templates/base/{src/server/routes/audits/__tests__ → tests/unit/server/routes/audits}/handlers.test.ts +11 -11
  161. package/templates/base/{src/server/routes/auth/__tests__ → tests/unit/server/routes/auth}/handlers.test.ts +124 -13
  162. package/templates/base/{src/server/routes/health/__tests__ → tests/unit/server/routes/health}/handlers.test.ts +27 -23
  163. package/templates/base/{src/server/routes/invitations/__tests__ → tests/unit/server/routes/invitations}/handlers.test.ts +14 -17
  164. package/templates/base/{src/server/routes/storage/__tests__ → tests/unit/server/routes/storage}/handlers.test.ts +6 -6
  165. package/templates/base/{src/server/routes/users/__tests__ → tests/unit/server/routes/users}/handlers.test.ts +81 -17
  166. package/templates/base/tests/unit/server/services/accounts.test.ts +406 -0
  167. package/templates/base/tests/unit/server/services/audits.test.ts +360 -0
  168. package/templates/base/tests/unit/server/services/auth.test.ts +656 -0
  169. package/templates/base/tests/unit/server/services/invitations.test.ts +343 -0
  170. package/templates/base/tests/unit/server/services/users.test.ts +706 -0
  171. package/templates/base/{src/shared/schemas/__tests__ → tests/unit/shared}/schemas.test.ts +1 -1
  172. package/templates/base/tsconfig.json +2 -1
  173. package/templates/base/vite.config.ts +3 -1
  174. package/templates/base/vitest.config.browser.ts +3 -2
  175. package/templates/base/vitest.config.frontend.ts +3 -2
  176. package/templates/base/vitest.config.ts +7 -14
  177. package/templates/base/.claude/settings.local.json +0 -11
  178. package/templates/base/.github/workflows/test.yml +0 -127
  179. package/templates/base/auth-setup-error.png +0 -0
  180. package/templates/base/config/drizzle.config.ts +0 -10
  181. package/templates/base/pnpm-lock.yaml +0 -8175
  182. package/templates/base/src/server/db/schema/accounts.ts +0 -20
  183. package/templates/base/src/server/db/schema/audit-logs.ts +0 -26
  184. package/templates/base/src/server/db/schema/index.ts +0 -7
  185. package/templates/base/src/server/db/schema/invitations.ts +0 -30
  186. package/templates/base/src/server/db/schema/refresh-tokens.ts +0 -22
  187. package/templates/base/src/server/db/schema/user-accounts.ts +0 -25
  188. package/templates/base/src/server/db/schema/users.ts +0 -33
  189. package/templates/base/src/server/lib/audited-db.test.ts +0 -107
  190. package/templates/base/src/server/lib/schema-helpers.ts +0 -16
  191. package/templates/base/src/server/middleware/auth.test.ts +0 -345
  192. package/templates/base/src/server/services/__tests__/accounts.test.ts +0 -764
  193. package/templates/base/src/server/services/__tests__/audits.test.ts +0 -235
  194. package/templates/base/src/server/services/__tests__/auth.test.ts +0 -765
  195. package/templates/base/src/server/services/__tests__/invitations.test.ts +0 -704
  196. package/templates/base/src/server/services/__tests__/users.test.ts +0 -755
  197. package/templates/base/tests/e2e/_auth/.gitkeep +0 -0
  198. package/templates/base/tests/integration/lib/schema-helpers.test.ts +0 -129
  199. package/templates/base/tsconfig.tsbuildinfo +0 -1
  200. /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
  201. /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
  202. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-handles-logout-button-click-1.png +0 -0
  203. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-handles-navigation-clicks-1.png +0 -0
  204. /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
  205. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-highlights-active-route-1.png +0 -0
  206. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-renders-sidebar-navigation-items-1.png +0 -0
  207. /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
  208. /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
  209. /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
  210. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/error-boundary.test.tsx +0 -0
  211. /package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/error-fallback.test.tsx +0 -0
  212. /package/templates/base/{src/client/hooks/__tests__ → tests/unit/client/hooks}/use-auth.test.tsx +0 -0
  213. /package/templates/base/{src/client/hooks/__tests__ → tests/unit/client/hooks}/use-theme.test.tsx +0 -0
  214. /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
  215. /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
  216. /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
  217. /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
  218. /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
  219. /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
  220. /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
  221. /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
  222. /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
  223. /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
  224. /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
  225. /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
  226. /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
  227. /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
  228. /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
  229. /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
  230. /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
  231. /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
  232. /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
  233. /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
  234. /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
  235. /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
  236. /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
  237. /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
  238. /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
  239. /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
  240. /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
  241. /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
  242. /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
  243. /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
  244. /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
  245. /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
  246. /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
  247. /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
  248. /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
  249. /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
  250. /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
  251. /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
  252. /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
  253. /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
  254. /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
  255. /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
  256. /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
  257. /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
  258. /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
  259. /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
  260. /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
  261. /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
  262. /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
  263. /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
  264. /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
  265. /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
  266. /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
  267. /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
  268. /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
  269. /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
  270. /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
  271. /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
  272. /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
  273. /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
  274. /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
  275. /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
  276. /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
  277. /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
  278. /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
  279. /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
  280. /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
  281. /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
  282. /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
  283. /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
  284. /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
  285. /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
  286. /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
  287. /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
  288. /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
  289. /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
  290. /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
  291. /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
  292. /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
  293. /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
  294. /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
  295. /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
  296. /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
  297. /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
  298. /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
  299. /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
  300. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/error-components.test.tsx +0 -0
@@ -0,0 +1,706 @@
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
+ toStringValue: (value: unknown) => {
22
+ if (typeof value === 'string') return value
23
+ if (typeof value === 'number' || typeof value === 'bigint') return String(value)
24
+ return ''
25
+ },
26
+ toNullableString: (value: unknown) => {
27
+ if (value === null || value === undefined) return null
28
+ if (typeof value === 'string') return value
29
+ if (typeof value === 'number' || typeof value === 'bigint') return String(value)
30
+ return null
31
+ },
32
+ }))
33
+
34
+ import { auditedUpdate, auditedDelete } from '@server/lib/audited-db'
35
+ import { logAudit } from '@server/lib/audit'
36
+ import { queryOne, queryAll, execute } from '@server/db/sql'
37
+
38
+ const db = {} as D1Database
39
+
40
+ function createMockContext(overrides: Partial<ServiceContext> = {}): ServiceContext {
41
+ const user = createUserFixture({
42
+ id: 'ctx-user-123',
43
+ email: 'context@example.com',
44
+ name: 'Context User',
45
+ })
46
+
47
+ return {
48
+ accountId: 'account-123',
49
+ user,
50
+ userRole: 'ADMIN',
51
+ transactionId: 'tx-123',
52
+ ip: '127.0.0.1',
53
+ userAgent: 'TestAgent/1.0',
54
+ ...overrides,
55
+ }
56
+ }
57
+
58
+ function createSuperAdminContext(overrides: Partial<ServiceContext> = {}): ServiceContext {
59
+ const user = createSuperAdminFixture({
60
+ id: 'super-admin-123',
61
+ email: 'superadmin@example.com',
62
+ name: 'Super Admin',
63
+ })
64
+
65
+ return {
66
+ accountId: 'account-123',
67
+ user,
68
+ userRole: 'ADMIN',
69
+ transactionId: 'tx-123',
70
+ ip: '127.0.0.1',
71
+ userAgent: 'TestAgent/1.0',
72
+ ...overrides,
73
+ }
74
+ }
75
+
76
+ describe('usersService', () => {
77
+ let ctx: ServiceContext
78
+ let superAdminCtx: ServiceContext
79
+
80
+ beforeEach(() => {
81
+ vi.clearAllMocks()
82
+ ctx = createMockContext()
83
+ superAdminCtx = createSuperAdminContext()
84
+ })
85
+
86
+ describe('findAll', () => {
87
+ const defaultPagination: PaginationQuery = { page: 1, limit: 10 }
88
+
89
+ it('should return paginated users for super admin', async () => {
90
+ const user = createUserFixture({ id: 'user-1', email: 'user@example.com' })
91
+
92
+ ;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
93
+ ;(queryAll as Mock).mockResolvedValueOnce([
94
+ {
95
+ id: user.id,
96
+ google_id: `google-${user.id}`,
97
+ email: user.email,
98
+ name: user.name,
99
+ avatar_url: user.avatarUrl,
100
+ status: user.status,
101
+ provider_ids: JSON.stringify(user.providerIds),
102
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
103
+ created_at: user.createdAt,
104
+ updated_at: user.updatedAt,
105
+ deleted_at: user.deletedAt,
106
+ },
107
+ ])
108
+
109
+ const result = await usersService.findAll(db, superAdminCtx, defaultPagination)
110
+
111
+ expect(result.data).toHaveLength(1)
112
+ expect(result.meta.totalItems).toBe(1)
113
+ })
114
+ })
115
+
116
+ describe('findById', () => {
117
+ it('should throw NotFound when user missing', async () => {
118
+ ;(queryOne as Mock).mockResolvedValueOnce(null)
119
+
120
+ await expect(usersService.findById(db, superAdminCtx, 'missing')).rejects.toThrow(NotFoundError)
121
+ })
122
+
123
+ it('should enforce membership for non-super-admin', async () => {
124
+ const user = createUserFixture({ id: 'user-1' })
125
+
126
+ ;(queryOne as Mock)
127
+ .mockResolvedValueOnce({
128
+ id: user.id,
129
+ google_id: `google-${user.id}`,
130
+ email: user.email,
131
+ name: user.name,
132
+ avatar_url: user.avatarUrl,
133
+ status: user.status,
134
+ provider_ids: JSON.stringify(user.providerIds),
135
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
136
+ created_at: user.createdAt,
137
+ updated_at: user.updatedAt,
138
+ deleted_at: user.deletedAt,
139
+ })
140
+ .mockResolvedValueOnce(null)
141
+
142
+ await expect(usersService.findById(db, ctx, user.id)).rejects.toThrow(NotFoundError)
143
+ })
144
+ })
145
+
146
+ describe('update', () => {
147
+ it('should update user and return record', async () => {
148
+ const user = createUserFixture({ id: 'user-1', name: 'Old Name' })
149
+
150
+ ;(queryOne as Mock).mockResolvedValueOnce({
151
+ id: user.id,
152
+ google_id: `google-${user.id}`,
153
+ email: user.email,
154
+ name: user.name,
155
+ avatar_url: user.avatarUrl,
156
+ status: user.status,
157
+ provider_ids: JSON.stringify(user.providerIds),
158
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
159
+ created_at: user.createdAt,
160
+ updated_at: user.updatedAt,
161
+ deleted_at: user.deletedAt,
162
+ })
163
+
164
+ const updated = { ...user, name: 'Updated Name' }
165
+ ;(auditedUpdate as Mock).mockResolvedValueOnce([
166
+ {
167
+ id: updated.id,
168
+ google_id: updated.googleId,
169
+ email: updated.email,
170
+ name: updated.name,
171
+ avatar_url: updated.avatarUrl,
172
+ status: updated.status,
173
+ provider_ids: JSON.stringify(updated.providerIds),
174
+ is_super_admin: updated.isSuperAdmin ? 1 : 0,
175
+ created_at: updated.createdAt,
176
+ updated_at: updated.updatedAt,
177
+ deleted_at: updated.deletedAt,
178
+ },
179
+ ])
180
+
181
+ const result = await usersService.update(db, superAdminCtx, user.id, { name: 'Updated Name' })
182
+
183
+ expect(result.name).toBe('Updated Name')
184
+ })
185
+ })
186
+
187
+ describe('delete', () => {
188
+ it('should delete user with audit', async () => {
189
+ const user = createUserFixture({ id: 'user-1' })
190
+ ;(queryOne as Mock).mockResolvedValueOnce({
191
+ id: user.id,
192
+ google_id: `google-${user.id}`,
193
+ email: user.email,
194
+ name: user.name,
195
+ avatar_url: user.avatarUrl,
196
+ status: user.status,
197
+ provider_ids: JSON.stringify(user.providerIds),
198
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
199
+ created_at: user.createdAt,
200
+ updated_at: user.updatedAt,
201
+ deleted_at: user.deletedAt,
202
+ })
203
+
204
+ await usersService.delete(db, superAdminCtx, user.id)
205
+
206
+ expect(auditedDelete).toHaveBeenCalled()
207
+ })
208
+ })
209
+
210
+ describe('restore', () => {
211
+ it('should restore soft-deleted user', async () => {
212
+ const user = createUserFixture({ id: 'user-1', deletedAt: new Date().toISOString() })
213
+ ;(queryOne as Mock).mockResolvedValueOnce({
214
+ id: user.id,
215
+ google_id: `google-${user.id}`,
216
+ email: user.email,
217
+ name: user.name,
218
+ avatar_url: user.avatarUrl,
219
+ status: user.status,
220
+ provider_ids: JSON.stringify(user.providerIds),
221
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
222
+ created_at: user.createdAt,
223
+ updated_at: user.updatedAt,
224
+ deleted_at: user.deletedAt,
225
+ })
226
+
227
+ const restored = { ...user, deletedAt: null }
228
+ ;(auditedUpdate as Mock).mockResolvedValueOnce([
229
+ {
230
+ id: restored.id,
231
+ google_id: restored.googleId,
232
+ email: restored.email,
233
+ name: restored.name,
234
+ avatar_url: restored.avatarUrl,
235
+ status: restored.status,
236
+ provider_ids: JSON.stringify(restored.providerIds),
237
+ is_super_admin: restored.isSuperAdmin ? 1 : 0,
238
+ created_at: restored.createdAt,
239
+ updated_at: restored.updatedAt,
240
+ deleted_at: restored.deletedAt,
241
+ },
242
+ ])
243
+
244
+ const result = await usersService.restore(db, superAdminCtx, user.id)
245
+
246
+ expect(result.deletedAt).toBeNull()
247
+ })
248
+ })
249
+
250
+ describe('listUserRoles', () => {
251
+ it('should list roles for user', async () => {
252
+ const user = createUserFixture({ id: 'user-1' })
253
+
254
+ ;(queryOne as Mock)
255
+ .mockResolvedValueOnce({
256
+ id: user.id,
257
+ google_id: `google-${user.id}`,
258
+ email: user.email,
259
+ name: user.name,
260
+ avatar_url: user.avatarUrl,
261
+ status: user.status,
262
+ provider_ids: JSON.stringify(user.providerIds),
263
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
264
+ created_at: user.createdAt,
265
+ updated_at: user.updatedAt,
266
+ deleted_at: user.deletedAt,
267
+ })
268
+ .mockResolvedValueOnce({ ok: 1 })
269
+
270
+ ;(queryAll as Mock).mockResolvedValueOnce([
271
+ { accountId: 'account-1', role: 'ADMIN' },
272
+ { accountId: 'account-2', role: 'VIEWER' },
273
+ ])
274
+
275
+ const result = await usersService.listUserRoles(db, ctx, user.id)
276
+
277
+ expect(result).toHaveLength(2)
278
+ })
279
+ })
280
+
281
+ describe('updateRole', () => {
282
+ it('should update role and log audit', async () => {
283
+ const user = createUserFixture({ id: 'user-1' })
284
+
285
+ ;(queryOne as Mock)
286
+ .mockResolvedValueOnce({
287
+ id: user.id,
288
+ google_id: `google-${user.id}`,
289
+ email: user.email,
290
+ name: user.name,
291
+ avatar_url: user.avatarUrl,
292
+ status: user.status,
293
+ provider_ids: JSON.stringify(user.providerIds),
294
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
295
+ created_at: user.createdAt,
296
+ updated_at: user.updatedAt,
297
+ deleted_at: user.deletedAt,
298
+ })
299
+ .mockResolvedValueOnce({ role: 'VIEWER' })
300
+
301
+ await usersService.updateRole(db, superAdminCtx, user.id, 'account-1', 'ADMIN')
302
+
303
+ expect(execute).toHaveBeenCalled()
304
+ expect(logAudit).toHaveBeenCalled()
305
+ })
306
+ })
307
+
308
+ describe('removeFromAccount', () => {
309
+ it('should remove membership and log audit', async () => {
310
+ const user = createUserFixture({ id: 'user-1' })
311
+
312
+ ;(queryOne as Mock).mockResolvedValueOnce({
313
+ id: user.id,
314
+ google_id: `google-${user.id}`,
315
+ email: user.email,
316
+ name: user.name,
317
+ avatar_url: user.avatarUrl,
318
+ status: user.status,
319
+ provider_ids: JSON.stringify(user.providerIds),
320
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
321
+ created_at: user.createdAt,
322
+ updated_at: user.updatedAt,
323
+ deleted_at: user.deletedAt,
324
+ })
325
+
326
+ await usersService.removeFromAccount(db, superAdminCtx, user.id, 'account-1')
327
+
328
+ expect(execute).toHaveBeenCalled()
329
+ expect(logAudit).toHaveBeenCalled()
330
+ })
331
+ })
332
+
333
+ describe('createUserAccounts', () => {
334
+ it('should upsert memberships and return count', async () => {
335
+ const items = [
336
+ { userId: 'user-1', accountId: 'account-1', role: 'ADMIN' as const },
337
+ { userId: 'user-2', accountId: 'account-1', role: 'VIEWER' as const },
338
+ ]
339
+
340
+ ;(queryOne as Mock).mockResolvedValue(null)
341
+
342
+ const result = await usersService.createUserAccounts(db, superAdminCtx, items)
343
+
344
+ expect(result.count).toBe(2)
345
+ expect(logAudit).toHaveBeenCalled()
346
+ })
347
+ })
348
+
349
+ describe('deleteUserAccounts', () => {
350
+ it('should delete memberships and return count', async () => {
351
+ const items = [
352
+ { userId: 'user-1', accountId: 'account-1', role: 'ADMIN' as const },
353
+ { userId: 'user-2', accountId: 'account-1', role: 'VIEWER' as const },
354
+ ]
355
+
356
+ const result = await usersService.deleteUserAccounts(db, superAdminCtx, items)
357
+
358
+ expect(result.count).toBe(2)
359
+ expect(logAudit).toHaveBeenCalled()
360
+ })
361
+ })
362
+
363
+ describe('findAll edge cases', () => {
364
+ const defaultPagination: PaginationQuery = { page: 1, limit: 10 }
365
+
366
+ it('should filter by query parameter', async () => {
367
+ ;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
368
+ ;(queryAll as Mock).mockResolvedValueOnce([
369
+ {
370
+ id: 'user-1',
371
+ google_id: 'google-1',
372
+ email: 'search@example.com',
373
+ name: 'Search User',
374
+ avatar_url: null,
375
+ status: 'active',
376
+ provider_ids: JSON.stringify(['google']),
377
+ is_super_admin: 0,
378
+ created_at: new Date().toISOString(),
379
+ updated_at: new Date().toISOString(),
380
+ deleted_at: null,
381
+ },
382
+ ])
383
+
384
+ const result = await usersService.findAll(db, superAdminCtx, { ...defaultPagination, query: 'search' })
385
+
386
+ expect(result.data).toHaveLength(1)
387
+ })
388
+
389
+ it('should filter by account for non-super-admin', async () => {
390
+ ;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
391
+ ;(queryAll as Mock).mockResolvedValueOnce([
392
+ {
393
+ id: 'user-1',
394
+ google_id: 'google-1',
395
+ email: 'user@example.com',
396
+ name: 'User',
397
+ avatar_url: null,
398
+ status: 'active',
399
+ provider_ids: '[]',
400
+ is_super_admin: 0,
401
+ created_at: new Date().toISOString(),
402
+ updated_at: new Date().toISOString(),
403
+ deleted_at: null,
404
+ },
405
+ ])
406
+
407
+ await usersService.findAll(db, ctx, defaultPagination)
408
+
409
+ // Check that account filter was applied
410
+ expect((queryOne as Mock).mock.calls[0][2]).toContain(ctx.accountId)
411
+ })
412
+
413
+ it('should handle null count result', async () => {
414
+ ;(queryOne as Mock).mockResolvedValueOnce(null)
415
+ ;(queryAll as Mock).mockResolvedValueOnce([])
416
+
417
+ const result = await usersService.findAll(db, superAdminCtx, defaultPagination)
418
+
419
+ expect(result.data).toHaveLength(0)
420
+ expect(result.meta.totalItems).toBe(0)
421
+ })
422
+
423
+ it('should parse providerIds as array', async () => {
424
+ ;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
425
+ ;(queryAll as Mock).mockResolvedValueOnce([
426
+ {
427
+ id: 'user-1',
428
+ google_id: 'google-1',
429
+ email: 'user@example.com',
430
+ name: 'User',
431
+ avatar_url: null,
432
+ status: 'active',
433
+ provider_ids: ['google', 'github'],
434
+ is_super_admin: 0,
435
+ created_at: new Date().toISOString(),
436
+ updated_at: new Date().toISOString(),
437
+ deleted_at: null,
438
+ },
439
+ ])
440
+
441
+ const result = await usersService.findAll(db, superAdminCtx, defaultPagination)
442
+
443
+ expect(result.data[0].providerIds).toEqual(['google', 'github'])
444
+ })
445
+
446
+ it('should handle invalid JSON in providerIds', async () => {
447
+ ;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
448
+ ;(queryAll as Mock).mockResolvedValueOnce([
449
+ {
450
+ id: 'user-1',
451
+ google_id: 'google-1',
452
+ email: 'user@example.com',
453
+ name: 'User',
454
+ avatar_url: null,
455
+ status: 'active',
456
+ provider_ids: 'invalid-json',
457
+ is_super_admin: 0,
458
+ created_at: new Date().toISOString(),
459
+ updated_at: new Date().toISOString(),
460
+ deleted_at: null,
461
+ },
462
+ ])
463
+
464
+ const result = await usersService.findAll(db, superAdminCtx, defaultPagination)
465
+
466
+ expect(result.data[0].providerIds).toEqual([])
467
+ })
468
+
469
+ it('should handle non-array JSON in providerIds', async () => {
470
+ ;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
471
+ ;(queryAll as Mock).mockResolvedValueOnce([
472
+ {
473
+ id: 'user-1',
474
+ google_id: 'google-1',
475
+ email: 'user@example.com',
476
+ name: 'User',
477
+ avatar_url: null,
478
+ status: 'active',
479
+ provider_ids: '{"key": "value"}',
480
+ is_super_admin: 0,
481
+ created_at: new Date().toISOString(),
482
+ updated_at: new Date().toISOString(),
483
+ deleted_at: null,
484
+ },
485
+ ])
486
+
487
+ const result = await usersService.findAll(db, superAdminCtx, defaultPagination)
488
+
489
+ expect(result.data[0].providerIds).toEqual([])
490
+ })
491
+
492
+ it('should handle isSuperAdmin as boolean true', async () => {
493
+ ;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
494
+ ;(queryAll as Mock).mockResolvedValueOnce([
495
+ {
496
+ id: 'user-1',
497
+ google_id: 'google-1',
498
+ email: 'user@example.com',
499
+ name: 'User',
500
+ avatar_url: null,
501
+ status: 'active',
502
+ provider_ids: '[]',
503
+ is_super_admin: true,
504
+ created_at: new Date().toISOString(),
505
+ updated_at: new Date().toISOString(),
506
+ deleted_at: null,
507
+ },
508
+ ])
509
+
510
+ const result = await usersService.findAll(db, superAdminCtx, defaultPagination)
511
+
512
+ expect(result.data[0].isSuperAdmin).toBe(true)
513
+ })
514
+
515
+ it('should handle isSuperAdmin as string "1"', async () => {
516
+ ;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
517
+ ;(queryAll as Mock).mockResolvedValueOnce([
518
+ {
519
+ id: 'user-1',
520
+ google_id: 'google-1',
521
+ email: 'user@example.com',
522
+ name: 'User',
523
+ avatar_url: null,
524
+ status: 'active',
525
+ provider_ids: '[]',
526
+ is_super_admin: '1',
527
+ created_at: new Date().toISOString(),
528
+ updated_at: new Date().toISOString(),
529
+ deleted_at: null,
530
+ },
531
+ ])
532
+
533
+ const result = await usersService.findAll(db, superAdminCtx, defaultPagination)
534
+
535
+ expect(result.data[0].isSuperAdmin).toBe(true)
536
+ })
537
+
538
+ it('should handle isSuperAdmin as string "true"', async () => {
539
+ ;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
540
+ ;(queryAll as Mock).mockResolvedValueOnce([
541
+ {
542
+ id: 'user-1',
543
+ google_id: 'google-1',
544
+ email: 'user@example.com',
545
+ name: 'User',
546
+ avatar_url: null,
547
+ status: 'active',
548
+ provider_ids: '[]',
549
+ is_super_admin: 'TRUE',
550
+ created_at: new Date().toISOString(),
551
+ updated_at: new Date().toISOString(),
552
+ deleted_at: null,
553
+ },
554
+ ])
555
+
556
+ const result = await usersService.findAll(db, superAdminCtx, defaultPagination)
557
+
558
+ expect(result.data[0].isSuperAdmin).toBe(true)
559
+ })
560
+ })
561
+
562
+ describe('update edge cases', () => {
563
+ it('should throw when auditedUpdate returns empty array', async () => {
564
+ const user = createUserFixture({ id: 'user-1' })
565
+
566
+ ;(queryOne as Mock).mockResolvedValueOnce({
567
+ id: user.id,
568
+ google_id: `google-${user.id}`,
569
+ email: user.email,
570
+ name: user.name,
571
+ avatar_url: user.avatarUrl,
572
+ status: user.status,
573
+ provider_ids: JSON.stringify(user.providerIds),
574
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
575
+ created_at: user.createdAt,
576
+ updated_at: user.updatedAt,
577
+ deleted_at: user.deletedAt,
578
+ })
579
+
580
+ ;(auditedUpdate as Mock).mockResolvedValueOnce([])
581
+
582
+ await expect(usersService.update(db, superAdminCtx, user.id, { name: 'New' })).rejects.toThrow('Failed to update user')
583
+ })
584
+ })
585
+
586
+ describe('restore edge cases', () => {
587
+ it('should throw NotFoundError when user not found', async () => {
588
+ ;(queryOne as Mock).mockResolvedValueOnce(null)
589
+
590
+ await expect(usersService.restore(db, superAdminCtx, 'missing')).rejects.toThrow(NotFoundError)
591
+ })
592
+
593
+ it('should throw NotFoundError when restore fails', async () => {
594
+ const user = createUserFixture({ id: 'user-1', deletedAt: new Date().toISOString() })
595
+
596
+ ;(queryOne as Mock).mockResolvedValueOnce({
597
+ id: user.id,
598
+ google_id: `google-${user.id}`,
599
+ email: user.email,
600
+ name: user.name,
601
+ avatar_url: user.avatarUrl,
602
+ status: user.status,
603
+ provider_ids: JSON.stringify(user.providerIds),
604
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
605
+ created_at: user.createdAt,
606
+ updated_at: user.updatedAt,
607
+ deleted_at: user.deletedAt,
608
+ })
609
+
610
+ ;(auditedUpdate as Mock).mockResolvedValueOnce([])
611
+
612
+ await expect(usersService.restore(db, superAdminCtx, user.id)).rejects.toThrow(NotFoundError)
613
+ })
614
+ })
615
+
616
+ describe('updateRole edge cases', () => {
617
+ it('should throw NotFoundError when membership not found', async () => {
618
+ const user = createUserFixture({ id: 'user-1' })
619
+
620
+ ;(queryOne as Mock)
621
+ .mockResolvedValueOnce({
622
+ id: user.id,
623
+ google_id: `google-${user.id}`,
624
+ email: user.email,
625
+ name: user.name,
626
+ avatar_url: user.avatarUrl,
627
+ status: user.status,
628
+ provider_ids: JSON.stringify(user.providerIds),
629
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
630
+ created_at: user.createdAt,
631
+ updated_at: user.updatedAt,
632
+ deleted_at: user.deletedAt,
633
+ })
634
+ .mockResolvedValueOnce(null)
635
+
636
+ await expect(usersService.updateRole(db, superAdminCtx, user.id, 'account-1', 'ADMIN')).rejects.toThrow('User not found in account')
637
+ })
638
+ })
639
+
640
+ describe('createUserAccounts edge cases', () => {
641
+ it('should update existing membership', async () => {
642
+ const items = [{ userId: 'user-1', accountId: 'account-1', role: 'ADMIN' as const }]
643
+
644
+ ;(queryOne as Mock).mockResolvedValueOnce({ role: 'VIEWER' })
645
+
646
+ const result = await usersService.createUserAccounts(db, superAdminCtx, items)
647
+
648
+ expect(result.count).toBe(1)
649
+ expect(execute).toHaveBeenCalled()
650
+ })
651
+ })
652
+
653
+ describe('listUserRoles edge cases', () => {
654
+ it('should handle snake_case column names', async () => {
655
+ const user = createUserFixture({ id: 'user-1' })
656
+
657
+ ;(queryOne as Mock)
658
+ .mockResolvedValueOnce({
659
+ id: user.id,
660
+ google_id: `google-${user.id}`,
661
+ email: user.email,
662
+ name: user.name,
663
+ avatar_url: user.avatarUrl,
664
+ status: user.status,
665
+ provider_ids: JSON.stringify(user.providerIds),
666
+ is_super_admin: user.isSuperAdmin ? 1 : 0,
667
+ created_at: user.createdAt,
668
+ updated_at: user.updatedAt,
669
+ deleted_at: user.deletedAt,
670
+ })
671
+ .mockResolvedValueOnce({ ok: 1 })
672
+
673
+ ;(queryAll as Mock).mockResolvedValueOnce([{ account_id: 'account-1', role: 'ADMIN' }])
674
+
675
+ const result = await usersService.listUserRoles(db, ctx, user.id)
676
+
677
+ expect(result[0].accountId).toBe('account-1')
678
+ })
679
+ })
680
+
681
+ describe('findById edge cases', () => {
682
+ it('should return user for super admin without membership check', async () => {
683
+ const user = createUserFixture({ id: 'user-1' })
684
+
685
+ ;(queryOne as Mock).mockResolvedValueOnce({
686
+ id: user.id,
687
+ googleId: user.googleId,
688
+ email: user.email,
689
+ name: user.name,
690
+ avatarUrl: user.avatarUrl,
691
+ status: user.status,
692
+ providerIds: user.providerIds,
693
+ isSuperAdmin: user.isSuperAdmin,
694
+ createdAt: user.createdAt,
695
+ updatedAt: user.updatedAt,
696
+ deletedAt: user.deletedAt,
697
+ })
698
+
699
+ const result = await usersService.findById(db, superAdminCtx, user.id)
700
+
701
+ expect(result.id).toBe(user.id)
702
+ // queryOne should only be called once (no membership check)
703
+ expect(queryOne).toHaveBeenCalledTimes(1)
704
+ })
705
+ })
706
+ })
@@ -7,7 +7,7 @@ import {
7
7
  UpdateAccountSchema,
8
8
  CreateInvitationSchema,
9
9
  CreateWebhookSchema,
10
- } from '../index'
10
+ } from '@shared/schemas'
11
11
 
12
12
  describe('User Schemas', () => {
13
13
  describe('CreateUserSchema', () => {