@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.
- package/dist/index.js +0 -0
- package/package.json +7 -2
- package/templates/base/.claude/commands/check-skill-rules.md +112 -29
- package/templates/base/.claude/commands/linear/implement-issue.md +383 -55
- package/templates/base/.claude/commands/ship.md +77 -13
- package/templates/base/.claude/hooks/package-lock.json +0 -419
- package/templates/base/.claude/hooks/skill-activation-prompt.ts +185 -113
- package/templates/base/.claude/hooks/skill-tool-guard.sh +6 -0
- package/templates/base/.claude/hooks/skill-tool-guard.ts +198 -0
- package/templates/base/.claude/scripts/validate-skill-rules.sh +55 -32
- package/templates/base/.claude/settings.json +18 -11
- package/templates/base/.claude/skills/skill-rules.json +326 -173
- package/templates/base/.env.example +3 -0
- package/templates/base/CLAUDE.md +5 -5
- package/templates/base/README.md +40 -27
- package/templates/base/config/eslint.config.js +1 -0
- package/templates/base/config/wrangler.json +16 -17
- package/templates/base/docs/SETUP-GUIDE.md +566 -0
- package/templates/base/docs/app_spec.txt +13 -10
- package/templates/base/docs/architecture/README.md +162 -5
- package/templates/base/docs/architecture/api-catalog.md +575 -0
- package/templates/base/docs/architecture/c4-component.md +309 -0
- package/templates/base/docs/architecture/c4-container.md +183 -0
- package/templates/base/docs/architecture/c4-context.md +106 -0
- package/templates/base/docs/architecture/data-requirements.md +4 -3
- package/templates/base/docs/architecture/db-bootstrap.md +39 -0
- package/templates/base/docs/architecture/dependencies.md +327 -0
- package/templates/base/docs/architecture/drizzle-migration-plan.md +125 -0
- package/templates/base/docs/architecture/erd.md +1 -1
- package/templates/base/docs/architecture/sql-standards.md +100 -0
- package/templates/base/docs/architecture/tech-debt.md +184 -0
- package/templates/base/docs/testing.md +36 -29
- package/templates/base/package.json +26 -20
- package/templates/base/schema.sql +84 -0
- package/templates/base/scripts/capture-prod-session.ts +2 -2
- package/templates/base/scripts/init.sh +244 -59
- package/templates/base/scripts/sync-template.sh +104 -0
- package/templates/base/src/client/hooks/use-auth.ts +5 -0
- package/templates/base/src/client/routes/_authenticated/dashboard.tsx +1 -1
- package/templates/base/src/client/routes/index.tsx +1 -1
- package/templates/base/src/server/db/client.ts +3 -5
- package/templates/base/src/server/db/records.ts +81 -0
- package/templates/base/src/server/db/seed.ts +3 -2
- package/templates/base/src/server/db/sql.ts +116 -0
- package/templates/base/src/server/index.ts +17 -2
- package/templates/base/src/server/lib/audit.ts +74 -26
- package/templates/base/src/server/lib/audited-db.ts +219 -109
- package/templates/base/src/server/lib/transaction.ts +10 -16
- package/templates/base/src/server/middleware/account.ts +9 -16
- package/templates/base/src/server/middleware/auth.ts +102 -38
- package/templates/base/src/server/middleware/rate-limit.ts +8 -6
- package/templates/base/src/server/routes/accounts/handlers.ts +18 -6
- package/templates/base/src/server/routes/audits/handlers.ts +3 -1
- package/templates/base/src/server/routes/auth/handlers.ts +15 -10
- package/templates/base/src/server/routes/auth/test-login.ts +99 -45
- package/templates/base/src/server/routes/health/handlers.ts +4 -4
- package/templates/base/src/server/routes/index.ts +9 -0
- package/templates/base/src/server/routes/invitations/handlers.ts +9 -6
- package/templates/base/src/server/routes/openapi.ts +1 -1
- package/templates/base/src/server/routes/users/handlers.ts +21 -14
- package/templates/base/src/server/services/accounts.ts +242 -217
- package/templates/base/src/server/services/audits.ts +114 -61
- package/templates/base/src/server/services/auth.ts +310 -180
- package/templates/base/src/server/services/invitations.ts +282 -222
- package/templates/base/src/server/services/users.ts +383 -293
- package/templates/base/src/server/types/index.ts +1 -2
- package/templates/base/src/shared/types/api.ts +66 -198
- package/templates/base/tests/e2e/auth.setup.ts +1 -1
- package/templates/base/{src/server/__tests__/fixtures.ts → tests/fixtures/server.ts} +3 -3
- package/templates/base/{src/client/__tests__/setup-browser.ts → tests/helpers/client-setup-browser.ts} +2 -2
- package/templates/base/{src/client/__tests__/setup.ts → tests/helpers/client-setup.ts} +1 -1
- package/templates/base/{src/client/__tests__/test-utils.tsx → tests/helpers/client-test-utils.tsx} +2 -2
- package/templates/base/{src/server/__tests__/setup.ts → tests/helpers/server.ts} +9 -9
- package/templates/base/tests/integration/accounts/crud.test.ts +2 -11
- package/templates/base/tests/integration/audits/list.test.ts +2 -11
- package/templates/base/tests/integration/auth/auth-service.test.ts +1 -10
- package/templates/base/tests/integration/auth/invitation-token.test.ts +2 -11
- package/templates/base/tests/integration/auth/logout.test.ts +2 -11
- package/templates/base/tests/integration/auth/oauth.test.ts +23 -42
- package/templates/base/tests/integration/auth/refresh-token.test.ts +1 -9
- package/templates/base/tests/integration/auth/session-expiry.test.ts +1 -9
- package/templates/base/tests/integration/auth/session.test.ts +2 -11
- package/templates/base/tests/integration/auth/super-admin.test.ts +1 -9
- package/templates/base/tests/integration/authorization/analytics-role.test.ts +2 -11
- package/templates/base/tests/integration/authorization/billing-role.test.ts +2 -11
- package/templates/base/tests/integration/authorization/guards-roles.test.ts +1 -9
- package/templates/base/tests/integration/authorization/multi-tenancy.test.ts +2 -11
- package/templates/base/tests/integration/authorization/roles.test.ts +2 -11
- package/templates/base/tests/integration/config/production-behavior.test.ts +2 -11
- package/templates/base/tests/integration/health/health.test.ts +25 -44
- package/templates/base/tests/integration/invitations/crud.test.ts +2 -11
- package/templates/base/tests/integration/invitations/email.test.ts +1 -9
- package/templates/base/tests/integration/middleware/auth.test.ts +3 -12
- package/templates/base/tests/integration/middleware/request-logger.test.ts +1 -9
- package/templates/base/tests/integration/performance/response-times.test.ts +1 -9
- package/templates/base/tests/integration/security/cookie-security.test.ts +2 -11
- package/templates/base/tests/integration/security/csrf-protection.test.ts +2 -11
- package/templates/base/tests/integration/security/log-sanitization.test.ts +1 -9
- package/templates/base/tests/integration/security/rate-limiting.test.ts +1 -9
- package/templates/base/tests/integration/security/sql-injection.test.ts +7 -18
- package/templates/base/tests/integration/security/xss-prevention.test.ts +2 -11
- package/templates/base/tests/integration/setup.ts +13 -90
- package/templates/base/tests/integration/smoke.test.ts +3 -2
- package/templates/base/tests/integration/storage/upload.test.ts +2 -11
- package/templates/base/tests/integration/storage/validation.test.ts +2 -11
- package/templates/base/tests/integration/users/crud.test.ts +2 -11
- package/templates/base/tests/integration/users/list.test.ts +2 -11
- package/templates/base/tests/integration/vitest.config.ts +2 -9
- package/templates/base/{src/server/__tests__ → tests}/mocks/db.ts +1 -1
- package/templates/base/{src/server/__tests__ → tests}/mocks/index.ts +1 -1
- package/templates/base/{src/server/__tests__ → tests}/mocks/kv.ts +1 -1
- package/templates/base/{src/server/__tests__ → tests}/mocks/r2.ts +1 -1
- package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/sidebar.test.tsx +1 -1
- package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/avatar.test.tsx +1 -1
- package/templates/base/{src/client/__tests__ → tests/unit/client/components/ui}/button.test.tsx +1 -1
- package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/card.test.tsx +1 -1
- package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/dialog.test.tsx +1 -1
- package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/input.test.tsx +1 -1
- package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/loading-skeleton.test.tsx +1 -1
- package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/skeleton.test.tsx +1 -1
- package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/sonner.test.tsx +1 -1
- package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/tabs.test.tsx +1 -1
- package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/account.test.tsx +1 -1
- package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/integrations.test.tsx +1 -1
- package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/settings.test.tsx +1 -1
- package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/team.test.tsx +1 -1
- package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/authenticated-layout.test.tsx +1 -1
- package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/dashboard.test.tsx +1 -1
- package/templates/base/{src/client/routes/__tests__ → tests/unit/client/routes}/invite.test.tsx +1 -1
- package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/login.test.tsx +1 -1
- package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/navigation.test.tsx +1 -1
- package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/root-layout.test.tsx +1 -1
- package/templates/base/{src/server/auth/__tests__ → tests/unit/server/auth}/guards.test.ts +2 -2
- package/templates/base/{src → tests/unit}/server/auth/permissions.test.ts +1 -1
- package/templates/base/{src → tests/unit}/server/auth/roles.test.ts +1 -1
- package/templates/base/tests/unit/server/db/sql.test.ts +68 -0
- package/templates/base/{src → tests/unit}/server/env.test.ts +1 -1
- package/templates/base/tests/unit/server/lib/audited-db.test.ts +78 -0
- package/templates/base/{src → tests/unit}/server/lib/email.test.ts +1 -1
- package/templates/base/{src → tests/unit}/server/lib/errors.test.ts +1 -1
- package/templates/base/{src → tests/unit}/server/lib/oauth.test.ts +1 -1
- package/templates/base/{src → tests/unit}/server/lib/pagination.test.ts +1 -1
- package/templates/base/{src → tests/unit}/server/lib/password.test.ts +1 -1
- package/templates/base/{src → tests/unit}/server/lib/providers.test.ts +1 -1
- package/templates/base/{src → tests/unit}/server/lib/r2-storage.test.ts +2 -2
- package/templates/base/{src → tests/unit}/server/lib/session.test.ts +2 -2
- package/templates/base/{src → tests/unit}/server/lib/tokens.test.ts +1 -1
- package/templates/base/{src → tests/unit}/server/lib/transaction.test.ts +5 -14
- package/templates/base/{src → tests/unit}/server/middleware/account.test.ts +16 -24
- package/templates/base/tests/unit/server/middleware/auth.test.ts +647 -0
- package/templates/base/{src → tests/unit}/server/middleware/cors.test.ts +1 -1
- package/templates/base/{src → tests/unit}/server/middleware/error-handler.test.ts +2 -2
- package/templates/base/{src → tests/unit}/server/middleware/rate-limit.test.ts +3 -2
- package/templates/base/{src → tests/unit}/server/middleware/request-context.test.ts +1 -1
- package/templates/base/{src → tests/unit}/server/middleware/request-logger.test.ts +1 -1
- package/templates/base/{src/server/__tests__/mocks/__tests__ → tests/unit/server/mocks}/db.test.ts +1 -1
- package/templates/base/{src/server/__tests__/mocks/__tests__ → tests/unit/server/mocks}/kv.test.ts +1 -1
- package/templates/base/{src/server/__tests__/mocks/__tests__ → tests/unit/server/mocks}/r2.test.ts +1 -1
- package/templates/base/{src/server/routes/accounts/__tests__ → tests/unit/server/routes/accounts}/handlers.test.ts +12 -12
- package/templates/base/{src/server/routes/audits/__tests__ → tests/unit/server/routes/audits}/handlers.test.ts +11 -11
- package/templates/base/{src/server/routes/auth/__tests__ → tests/unit/server/routes/auth}/handlers.test.ts +124 -13
- package/templates/base/{src/server/routes/health/__tests__ → tests/unit/server/routes/health}/handlers.test.ts +27 -23
- package/templates/base/{src/server/routes/invitations/__tests__ → tests/unit/server/routes/invitations}/handlers.test.ts +14 -17
- package/templates/base/{src/server/routes/storage/__tests__ → tests/unit/server/routes/storage}/handlers.test.ts +6 -6
- package/templates/base/{src/server/routes/users/__tests__ → tests/unit/server/routes/users}/handlers.test.ts +81 -17
- package/templates/base/tests/unit/server/services/accounts.test.ts +406 -0
- package/templates/base/tests/unit/server/services/audits.test.ts +360 -0
- package/templates/base/tests/unit/server/services/auth.test.ts +656 -0
- package/templates/base/tests/unit/server/services/invitations.test.ts +343 -0
- package/templates/base/tests/unit/server/services/users.test.ts +706 -0
- package/templates/base/{src/shared/schemas/__tests__ → tests/unit/shared}/schemas.test.ts +1 -1
- package/templates/base/tsconfig.json +2 -1
- package/templates/base/vite.config.ts +3 -1
- package/templates/base/vitest.config.browser.ts +3 -2
- package/templates/base/vitest.config.frontend.ts +3 -2
- package/templates/base/vitest.config.ts +7 -14
- package/templates/base/.claude/settings.local.json +0 -11
- package/templates/base/.github/workflows/test.yml +0 -127
- package/templates/base/auth-setup-error.png +0 -0
- package/templates/base/config/drizzle.config.ts +0 -10
- package/templates/base/pnpm-lock.yaml +0 -8175
- package/templates/base/src/server/db/schema/accounts.ts +0 -20
- package/templates/base/src/server/db/schema/audit-logs.ts +0 -26
- package/templates/base/src/server/db/schema/index.ts +0 -7
- package/templates/base/src/server/db/schema/invitations.ts +0 -30
- package/templates/base/src/server/db/schema/refresh-tokens.ts +0 -22
- package/templates/base/src/server/db/schema/user-accounts.ts +0 -25
- package/templates/base/src/server/db/schema/users.ts +0 -33
- package/templates/base/src/server/lib/audited-db.test.ts +0 -107
- package/templates/base/src/server/lib/schema-helpers.ts +0 -16
- package/templates/base/src/server/middleware/auth.test.ts +0 -345
- package/templates/base/src/server/services/__tests__/accounts.test.ts +0 -764
- package/templates/base/src/server/services/__tests__/audits.test.ts +0 -235
- package/templates/base/src/server/services/__tests__/auth.test.ts +0 -765
- package/templates/base/src/server/services/__tests__/invitations.test.ts +0 -704
- package/templates/base/src/server/services/__tests__/users.test.ts +0 -755
- package/templates/base/tests/e2e/_auth/.gitkeep +0 -0
- package/templates/base/tests/integration/lib/schema-helpers.test.ts +0 -129
- package/templates/base/tsconfig.tsbuildinfo +0 -1
- /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
- /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
- /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-handles-logout-button-click-1.png +0 -0
- /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-handles-navigation-clicks-1.png +0 -0
- /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
- /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-highlights-active-route-1.png +0 -0
- /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-renders-sidebar-navigation-items-1.png +0 -0
- /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
- /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
- /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
- /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/error-boundary.test.tsx +0 -0
- /package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/error-fallback.test.tsx +0 -0
- /package/templates/base/{src/client/hooks/__tests__ → tests/unit/client/hooks}/use-auth.test.tsx +0 -0
- /package/templates/base/{src/client/hooks/__tests__ → tests/unit/client/hooks}/use-theme.test.tsx +0 -0
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /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
- /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/error-components.test.tsx +0 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
// src/server/services/__tests__/audits.test.ts
|
|
2
|
+
import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest'
|
|
3
|
+
import { auditsService, type AuditLogFilters } from '@server/services/audits'
|
|
4
|
+
import type { ServiceContext, AuditLog } from '@server/types'
|
|
5
|
+
import { createUserFixture, createSuperAdminFixture } from '@tests/fixtures/server'
|
|
6
|
+
|
|
7
|
+
vi.mock('@server/db/sql', () => ({
|
|
8
|
+
queryOne: vi.fn(),
|
|
9
|
+
queryAll: vi.fn(),
|
|
10
|
+
toStringValue: (value: unknown) => {
|
|
11
|
+
if (typeof value === 'string') return value
|
|
12
|
+
if (typeof value === 'number' || typeof value === 'bigint') return String(value)
|
|
13
|
+
return ''
|
|
14
|
+
},
|
|
15
|
+
toNullableString: (value: unknown) => {
|
|
16
|
+
if (value === null || value === undefined) return null
|
|
17
|
+
if (typeof value === 'string') return value
|
|
18
|
+
if (typeof value === 'number' || typeof value === 'bigint') return String(value)
|
|
19
|
+
return null
|
|
20
|
+
},
|
|
21
|
+
}))
|
|
22
|
+
|
|
23
|
+
import { queryOne, queryAll } from '@server/db/sql'
|
|
24
|
+
|
|
25
|
+
const db = {} as D1Database
|
|
26
|
+
|
|
27
|
+
function createMockContext(overrides: Partial<ServiceContext> = {}): ServiceContext {
|
|
28
|
+
const user = createUserFixture({
|
|
29
|
+
id: 'ctx-user-123',
|
|
30
|
+
email: 'user@test.com',
|
|
31
|
+
name: 'Test User',
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
accountId: 'account-123',
|
|
36
|
+
user,
|
|
37
|
+
userRole: 'ADMIN',
|
|
38
|
+
transactionId: 'tx-123',
|
|
39
|
+
ip: '127.0.0.1',
|
|
40
|
+
userAgent: 'TestAgent/1.0',
|
|
41
|
+
...overrides,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function createSuperAdminContext(overrides: Partial<ServiceContext> = {}): ServiceContext {
|
|
46
|
+
const user = createSuperAdminFixture({
|
|
47
|
+
id: 'super-admin-123',
|
|
48
|
+
email: 'superadmin@test.com',
|
|
49
|
+
name: 'Super Admin',
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
accountId: 'account-123',
|
|
54
|
+
user,
|
|
55
|
+
userRole: 'ADMIN',
|
|
56
|
+
transactionId: 'tx-123',
|
|
57
|
+
ip: '127.0.0.1',
|
|
58
|
+
userAgent: 'TestAgent/1.0',
|
|
59
|
+
...overrides,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function createMockAuditLog(overrides: Partial<AuditLog> = {}): AuditLog {
|
|
64
|
+
return {
|
|
65
|
+
id: 'log-1',
|
|
66
|
+
transactionId: 'tx-1',
|
|
67
|
+
accountId: 'account-123',
|
|
68
|
+
userId: 'user-123',
|
|
69
|
+
entity: 'user',
|
|
70
|
+
entityId: 'user-456',
|
|
71
|
+
action: 'INSERT',
|
|
72
|
+
changes: { name: 'New Name' },
|
|
73
|
+
ipAddress: '127.0.0.1',
|
|
74
|
+
userAgent: 'TestAgent',
|
|
75
|
+
timestamp: '2025-01-01T00:00:00Z',
|
|
76
|
+
...overrides,
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
describe('auditsService', () => {
|
|
81
|
+
let ctx: ServiceContext
|
|
82
|
+
let superAdminCtx: ServiceContext
|
|
83
|
+
|
|
84
|
+
beforeEach(() => {
|
|
85
|
+
vi.clearAllMocks()
|
|
86
|
+
ctx = createMockContext()
|
|
87
|
+
superAdminCtx = createSuperAdminContext()
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
describe('findAll', () => {
|
|
91
|
+
const defaultFilters: AuditLogFilters = { page: 1, limit: 10 }
|
|
92
|
+
|
|
93
|
+
it('should return paginated audit logs with correct meta', async () => {
|
|
94
|
+
const mockLogs = [
|
|
95
|
+
createMockAuditLog({ id: 'log-1', entity: 'user', action: 'INSERT' }),
|
|
96
|
+
createMockAuditLog({ id: 'log-2', entity: 'account', action: 'UPDATE' }),
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
;(queryOne as Mock).mockResolvedValueOnce({ count: 2 })
|
|
100
|
+
;(queryAll as Mock).mockResolvedValueOnce(mockLogs.map((log) => ({
|
|
101
|
+
id: log.id,
|
|
102
|
+
transactionId: log.transactionId,
|
|
103
|
+
accountId: log.accountId,
|
|
104
|
+
userId: log.userId,
|
|
105
|
+
entity: log.entity,
|
|
106
|
+
entityId: log.entityId,
|
|
107
|
+
action: log.action,
|
|
108
|
+
changes: JSON.stringify(log.changes),
|
|
109
|
+
ipAddress: log.ipAddress,
|
|
110
|
+
userAgent: log.userAgent,
|
|
111
|
+
timestamp: log.timestamp,
|
|
112
|
+
})))
|
|
113
|
+
|
|
114
|
+
const result = await auditsService.findAll(db, superAdminCtx, defaultFilters)
|
|
115
|
+
|
|
116
|
+
expect(result.data).toHaveLength(2)
|
|
117
|
+
expect(result.meta.totalItems).toBe(2)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
it('should include account filter for non-super-admin', async () => {
|
|
121
|
+
;(queryOne as Mock).mockResolvedValueOnce({ count: 0 })
|
|
122
|
+
;(queryAll as Mock).mockResolvedValueOnce([])
|
|
123
|
+
|
|
124
|
+
await auditsService.findAll(db, ctx, defaultFilters)
|
|
125
|
+
|
|
126
|
+
expect((queryOne as Mock).mock.calls[0][2]).toContain(ctx.accountId)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('should filter by entity when provided', async () => {
|
|
130
|
+
const mockLogs = [createMockAuditLog({ id: 'log-1', entity: 'user' })]
|
|
131
|
+
|
|
132
|
+
;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
|
|
133
|
+
;(queryAll as Mock).mockResolvedValueOnce(mockLogs.map((log) => ({
|
|
134
|
+
id: log.id,
|
|
135
|
+
transactionId: log.transactionId,
|
|
136
|
+
accountId: log.accountId,
|
|
137
|
+
userId: log.userId,
|
|
138
|
+
entity: log.entity,
|
|
139
|
+
entityId: log.entityId,
|
|
140
|
+
action: log.action,
|
|
141
|
+
changes: JSON.stringify(log.changes),
|
|
142
|
+
ipAddress: log.ipAddress,
|
|
143
|
+
userAgent: log.userAgent,
|
|
144
|
+
timestamp: log.timestamp,
|
|
145
|
+
})))
|
|
146
|
+
|
|
147
|
+
const result = await auditsService.findAll(db, superAdminCtx, { ...defaultFilters, entity: 'user' })
|
|
148
|
+
|
|
149
|
+
expect(result.data).toHaveLength(1)
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it('should filter by entityId when provided', async () => {
|
|
153
|
+
;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
|
|
154
|
+
;(queryAll as Mock).mockResolvedValueOnce([{
|
|
155
|
+
id: 'log-1',
|
|
156
|
+
transactionId: 'tx-1',
|
|
157
|
+
accountId: 'account-123',
|
|
158
|
+
userId: 'user-123',
|
|
159
|
+
entity: 'user',
|
|
160
|
+
entityId: 'specific-entity-id',
|
|
161
|
+
action: 'INSERT',
|
|
162
|
+
changes: null,
|
|
163
|
+
ipAddress: '127.0.0.1',
|
|
164
|
+
userAgent: 'TestAgent',
|
|
165
|
+
timestamp: '2025-01-01T00:00:00Z',
|
|
166
|
+
}])
|
|
167
|
+
|
|
168
|
+
const result = await auditsService.findAll(db, superAdminCtx, { ...defaultFilters, entityId: 'specific-entity-id' })
|
|
169
|
+
|
|
170
|
+
expect(result.data).toHaveLength(1)
|
|
171
|
+
expect(result.data[0].entityId).toBe('specific-entity-id')
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
it('should filter by action when provided', async () => {
|
|
175
|
+
;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
|
|
176
|
+
;(queryAll as Mock).mockResolvedValueOnce([{
|
|
177
|
+
id: 'log-1',
|
|
178
|
+
transactionId: 'tx-1',
|
|
179
|
+
accountId: 'account-123',
|
|
180
|
+
userId: 'user-123',
|
|
181
|
+
entity: 'user',
|
|
182
|
+
entityId: 'user-456',
|
|
183
|
+
action: 'DELETE',
|
|
184
|
+
changes: null,
|
|
185
|
+
ipAddress: '127.0.0.1',
|
|
186
|
+
userAgent: 'TestAgent',
|
|
187
|
+
timestamp: '2025-01-01T00:00:00Z',
|
|
188
|
+
}])
|
|
189
|
+
|
|
190
|
+
const result = await auditsService.findAll(db, superAdminCtx, { ...defaultFilters, action: 'DELETE' })
|
|
191
|
+
|
|
192
|
+
expect(result.data).toHaveLength(1)
|
|
193
|
+
expect(result.data[0].action).toBe('DELETE')
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
it('should handle null count result', async () => {
|
|
197
|
+
;(queryOne as Mock).mockResolvedValueOnce(null)
|
|
198
|
+
;(queryAll as Mock).mockResolvedValueOnce([])
|
|
199
|
+
|
|
200
|
+
const result = await auditsService.findAll(db, superAdminCtx, defaultFilters)
|
|
201
|
+
|
|
202
|
+
expect(result.data).toHaveLength(0)
|
|
203
|
+
expect(result.meta.totalItems).toBe(0)
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
it('should handle snake_case column names', async () => {
|
|
207
|
+
;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
|
|
208
|
+
;(queryAll as Mock).mockResolvedValueOnce([{
|
|
209
|
+
id: 'log-1',
|
|
210
|
+
transaction_id: 'tx-snake',
|
|
211
|
+
account_id: 'account-snake',
|
|
212
|
+
user_id: 'user-snake',
|
|
213
|
+
entity: 'user',
|
|
214
|
+
entity_id: 'entity-snake',
|
|
215
|
+
action: 'UPDATE',
|
|
216
|
+
changes: '{"field": "value"}',
|
|
217
|
+
ip_address: '192.168.1.1',
|
|
218
|
+
user_agent: 'SnakeAgent',
|
|
219
|
+
timestamp: '2025-01-01T00:00:00Z',
|
|
220
|
+
}])
|
|
221
|
+
|
|
222
|
+
const result = await auditsService.findAll(db, superAdminCtx, defaultFilters)
|
|
223
|
+
|
|
224
|
+
expect(result.data[0].transactionId).toBe('tx-snake')
|
|
225
|
+
expect(result.data[0].accountId).toBe('account-snake')
|
|
226
|
+
expect(result.data[0].userId).toBe('user-snake')
|
|
227
|
+
expect(result.data[0].entityId).toBe('entity-snake')
|
|
228
|
+
expect(result.data[0].ipAddress).toBe('192.168.1.1')
|
|
229
|
+
expect(result.data[0].userAgent).toBe('SnakeAgent')
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
it('should parse changes as JSON string', async () => {
|
|
233
|
+
;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
|
|
234
|
+
;(queryAll as Mock).mockResolvedValueOnce([{
|
|
235
|
+
id: 'log-1',
|
|
236
|
+
transactionId: 'tx-1',
|
|
237
|
+
accountId: 'account-123',
|
|
238
|
+
userId: 'user-123',
|
|
239
|
+
entity: 'user',
|
|
240
|
+
entityId: 'user-456',
|
|
241
|
+
action: 'UPDATE',
|
|
242
|
+
changes: '{"old": "value", "new": "changed"}',
|
|
243
|
+
ipAddress: null,
|
|
244
|
+
userAgent: null,
|
|
245
|
+
timestamp: '2025-01-01T00:00:00Z',
|
|
246
|
+
}])
|
|
247
|
+
|
|
248
|
+
const result = await auditsService.findAll(db, superAdminCtx, defaultFilters)
|
|
249
|
+
|
|
250
|
+
expect(result.data[0].changes).toEqual({ old: 'value', new: 'changed' })
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
it('should parse changes as object', async () => {
|
|
254
|
+
;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
|
|
255
|
+
;(queryAll as Mock).mockResolvedValueOnce([{
|
|
256
|
+
id: 'log-1',
|
|
257
|
+
transactionId: 'tx-1',
|
|
258
|
+
accountId: 'account-123',
|
|
259
|
+
userId: 'user-123',
|
|
260
|
+
entity: 'user',
|
|
261
|
+
entityId: 'user-456',
|
|
262
|
+
action: 'UPDATE',
|
|
263
|
+
changes: { already: 'object' },
|
|
264
|
+
ipAddress: null,
|
|
265
|
+
userAgent: null,
|
|
266
|
+
timestamp: '2025-01-01T00:00:00Z',
|
|
267
|
+
}])
|
|
268
|
+
|
|
269
|
+
const result = await auditsService.findAll(db, superAdminCtx, defaultFilters)
|
|
270
|
+
|
|
271
|
+
expect(result.data[0].changes).toEqual({ already: 'object' })
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
it('should handle invalid JSON in changes', async () => {
|
|
275
|
+
;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
|
|
276
|
+
;(queryAll as Mock).mockResolvedValueOnce([{
|
|
277
|
+
id: 'log-1',
|
|
278
|
+
transactionId: 'tx-1',
|
|
279
|
+
accountId: 'account-123',
|
|
280
|
+
userId: 'user-123',
|
|
281
|
+
entity: 'user',
|
|
282
|
+
entityId: 'user-456',
|
|
283
|
+
action: 'UPDATE',
|
|
284
|
+
changes: 'not-valid-json',
|
|
285
|
+
ipAddress: null,
|
|
286
|
+
userAgent: null,
|
|
287
|
+
timestamp: '2025-01-01T00:00:00Z',
|
|
288
|
+
}])
|
|
289
|
+
|
|
290
|
+
const result = await auditsService.findAll(db, superAdminCtx, defaultFilters)
|
|
291
|
+
|
|
292
|
+
expect(result.data[0].changes).toBeNull()
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
it('should handle null/undefined changes', async () => {
|
|
296
|
+
;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
|
|
297
|
+
;(queryAll as Mock).mockResolvedValueOnce([{
|
|
298
|
+
id: 'log-1',
|
|
299
|
+
transactionId: 'tx-1',
|
|
300
|
+
accountId: 'account-123',
|
|
301
|
+
userId: 'user-123',
|
|
302
|
+
entity: 'user',
|
|
303
|
+
entityId: 'user-456',
|
|
304
|
+
action: 'DELETE',
|
|
305
|
+
changes: null,
|
|
306
|
+
ipAddress: null,
|
|
307
|
+
userAgent: null,
|
|
308
|
+
timestamp: '2025-01-01T00:00:00Z',
|
|
309
|
+
}])
|
|
310
|
+
|
|
311
|
+
const result = await auditsService.findAll(db, superAdminCtx, defaultFilters)
|
|
312
|
+
|
|
313
|
+
expect(result.data[0].changes).toBeNull()
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
it('should handle null accountId and userId', async () => {
|
|
317
|
+
;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
|
|
318
|
+
;(queryAll as Mock).mockResolvedValueOnce([{
|
|
319
|
+
id: 'log-1',
|
|
320
|
+
transactionId: 'tx-1',
|
|
321
|
+
accountId: null,
|
|
322
|
+
userId: null,
|
|
323
|
+
entity: 'system',
|
|
324
|
+
entityId: 'sys-1',
|
|
325
|
+
action: 'INSERT',
|
|
326
|
+
changes: null,
|
|
327
|
+
ipAddress: null,
|
|
328
|
+
userAgent: null,
|
|
329
|
+
timestamp: '2025-01-01T00:00:00Z',
|
|
330
|
+
}])
|
|
331
|
+
|
|
332
|
+
const result = await auditsService.findAll(db, superAdminCtx, defaultFilters)
|
|
333
|
+
|
|
334
|
+
expect(result.data[0].accountId).toBeNull()
|
|
335
|
+
expect(result.data[0].userId).toBeNull()
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
it('should handle non-object parsed JSON in changes', async () => {
|
|
339
|
+
;(queryOne as Mock).mockResolvedValueOnce({ count: 1 })
|
|
340
|
+
;(queryAll as Mock).mockResolvedValueOnce([{
|
|
341
|
+
id: 'log-1',
|
|
342
|
+
transactionId: 'tx-1',
|
|
343
|
+
accountId: 'account-123',
|
|
344
|
+
userId: 'user-123',
|
|
345
|
+
entity: 'user',
|
|
346
|
+
entityId: 'user-456',
|
|
347
|
+
action: 'UPDATE',
|
|
348
|
+
changes: '"just a string"',
|
|
349
|
+
ipAddress: null,
|
|
350
|
+
userAgent: null,
|
|
351
|
+
timestamp: '2025-01-01T00:00:00Z',
|
|
352
|
+
}])
|
|
353
|
+
|
|
354
|
+
const result = await auditsService.findAll(db, superAdminCtx, defaultFilters)
|
|
355
|
+
|
|
356
|
+
// A JSON string that parses to a primitive should return null
|
|
357
|
+
expect(result.data[0].changes).toBeNull()
|
|
358
|
+
})
|
|
359
|
+
})
|
|
360
|
+
})
|