create-huenei-template 0.2.7 → 0.2.9
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/config/templates.js +14 -0
- package/dist/core/file-operations.js +15 -0
- package/dist/core/prompts.js +77 -135
- package/dist/index.js +55 -11
- package/dist/templates/README.md +7 -1
- package/dist/templates/backend/README.md +19 -9
- package/dist/templates/backend/nestjs-api-mysql/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/agents/prisma-guardian.md +67 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/agents/test-runner.md +57 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/blockDangerous.ts +98 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/formatOnEdit.ts +70 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/protectSecrets.ts +101 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/sessionInit.ts +104 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks/validatePrisma.ts +121 -0
- package/dist/templates/backend/nestjs-api-mysql/.cursor/hooks.json +46 -0
- package/dist/templates/backend/nestjs-api-mysql/README.md +26 -0
- package/dist/templates/backend/nestjs-api-mysql/eslint.config.mjs +1 -1
- package/dist/templates/backend/nestjs-api-mysql/package.json +7 -7
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/prisma-guardian.md +62 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/security-auditor.md +71 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/agents/test-runner.md +58 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/auto-retry.ts +62 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/block-dangerous.ts +202 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/format-and-validate.ts +124 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/protect-secrets.ts +105 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks/session-context.ts +130 -0
- package/dist/templates/backend/nestjs-api-postgres/.cursor/hooks.json +36 -0
- package/dist/templates/backend/nestjs-api-postgres/eslint.config.mjs +1 -1
- package/dist/templates/backend/nestjs-api-postgres/package.json +6 -6
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/code-reviewer.md +153 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/nestjs-architect.md +138 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/prisma-analyst.md +164 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/security-auditor.md +150 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/agents/test-engineer.md +290 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/auto-format.ts +80 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/block-dangerous-commands.ts +144 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/prisma-schema-watcher.ts +64 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/protect-sensitive-files.ts +122 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks/session-context.ts +105 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/hooks.json +18 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/conventional-commits/SKILL.md +318 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/docker/SKILL.md +82 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/jest/SKILL.md +72 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/logging-best-practices/SKILL.md +127 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/prisma-database-setup/SKILL.md +186 -0
- package/dist/templates/backend/nestjs-api-sqlite/.cursor/skills/quality-gates-enforcer/SKILL.md +301 -0
- package/dist/templates/backend/nestjs-api-sqlite/README.md +34 -1
- package/dist/templates/backend/nestjs-api-sqlite/eslint.config.mjs +1 -1
- package/dist/templates/backend/nestjs-api-sqlite/package.json +6 -6
- package/dist/templates/backend/nestjs-api-sqlite/prisma/schema.prisma +1 -0
- package/dist/templates/backend/nestjs-api-sqlite/prisma/seed.ts +2 -2
- package/dist/templates/backend/nestjs-api-sqlite/src/posts/dto/post-response.dto.ts +5 -1
- package/dist/templates/backend/nestjs-api-sqlite/src/users/dto/profile-response.dto.ts +1 -1
- package/dist/templates/backend/nestjs-api-sqlite/src/users/dto/update-profile.dto.ts +1 -1
- package/dist/templates/backend/nestjs-api-sqlite/src/users/dto/user-response.dto.ts +4 -0
- package/dist/templates/backend/nestjs-api-sqlite/src/users/profile.service.ts +24 -8
- package/dist/templates/backend/nestjs-api-sqlite/src/users/users.service.ts +1 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/agents/prisma-guardian.md +67 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/agents/test-runner.md +57 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-endpoint.md +209 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-model.md +201 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/blockDangerous.ts +98 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/formatOnEdit.ts +70 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/protectSecrets.ts +101 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/sessionInit.ts +104 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks/validatePrisma.ts +121 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/hooks.json +46 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/api-rest.mdc +126 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/authentication-security.mdc +86 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/dto-validation.mdc +93 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/general-rules.mdc +126 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/nestjs-architecture.mdc +83 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/prisma-standards.mdc +111 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/rules/swagger-documentation.mdc +90 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/api-security-best-practices/SKILL.md +907 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/docker-expert/SKILL.md +409 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-expert/SKILL.md +552 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/AGENTS.md +5958 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/SKILL.md +130 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/nodejs-best-practices/SKILL.md +333 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/prisma-expert/SKILL.md +355 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.cursor/skills/sqlserver-table-design/SKILL.md +125 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.dockerignore +50 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.env.example +17 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.env.test +17 -0
- package/dist/templates/backend/nestjs-api-sqlserver/.prettierrc +4 -0
- package/dist/templates/backend/nestjs-api-sqlserver/README.md +587 -0
- package/dist/templates/backend/nestjs-api-sqlserver/docker-compose.yml +24 -0
- package/dist/templates/backend/nestjs-api-sqlserver/eslint.config.mjs +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/nest-cli.json +8 -0
- package/dist/templates/backend/nestjs-api-sqlserver/package.json +107 -0
- package/dist/templates/backend/nestjs-api-sqlserver/prisma/schema.prisma +70 -0
- package/dist/templates/backend/nestjs-api-sqlserver/prisma/seed.ts +215 -0
- package/dist/templates/backend/nestjs-api-sqlserver/prisma.config.ts +12 -0
- package/dist/templates/backend/nestjs-api-sqlserver/scripts/check-docker.js +64 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/app.module.ts +39 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/app.service.ts +8 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/auth.controller.ts +36 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/auth.module.ts +22 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/auth.service.ts +64 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/decorators/roles.decorator.ts +5 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/dto/login-response.dto.ts +23 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/dto/login.dto.ts +27 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/enums/role.enum.ts +5 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/guards/jwt-auth.guard.ts +20 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/guards/roles.guard.ts +23 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/strategies/jwt.strategy.ts +32 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/auth/types.ts +18 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/common/dto/paginated-response.dto.ts +16 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/common/dto/pagination.dto.ts +31 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/common/filters/http-exception.filter.ts +53 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/config/env.validation.ts +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/health/health.controller.ts +35 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/health/health.module.ts +7 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/main.ts +87 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/dto/create-post.dto.ts +32 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/dto/post-response.dto.ts +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/dto/update-post.dto.ts +31 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/posts.controller.ts +161 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/posts.module.ts +12 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/posts/posts.service.ts +171 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.module.ts +9 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.service.ts +62 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/constants/settings.constants.ts +9 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/profile-response.dto.ts +39 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/settings-response.dto.ts +18 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/update-profile.dto.ts +48 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/update-settings.dto.ts +40 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/dto/user-response.dto.ts +18 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/profile.service.ts +67 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/settings.service.ts +77 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/users.controller.ts +102 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/users.module.ts +14 -0
- package/dist/templates/backend/nestjs-api-sqlserver/src/users/users.service.ts +27 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/README.md +412 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/auth.e2e-spec.ts +147 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/health.e2e-spec.ts +62 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/posts.e2e-spec.ts +407 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/e2e/users.e2e-spec.ts +287 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/fixtures/test-data.ts +109 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/helpers/auth.helper.ts +54 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/helpers/db.helper.ts +68 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/jest-e2e.json +12 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/setup-e2e.ts +8 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/app.service.spec.ts +24 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/auth.controller.spec.ts +91 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/auth.service.spec.ts +161 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/health.controller.spec.ts +78 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/http-exception.filter.spec.ts +150 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/jwt-auth.guard.spec.ts +50 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/jwt.strategy.spec.ts +41 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/posts.controller.spec.ts +249 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/posts.service.spec.ts +328 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/profile.service.spec.ts +146 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/settings.service.spec.ts +242 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/users.controller.spec.ts +178 -0
- package/dist/templates/backend/nestjs-api-sqlserver/test/unit/users.service.spec.ts +96 -0
- package/dist/templates/backend/nestjs-api-sqlserver/tsconfig.build.json +4 -0
- package/dist/templates/backend/nestjs-api-sqlserver/tsconfig.json +28 -0
- package/dist/templates/cursor/.cursor/commands/configurar-cursor.md +763 -0
- package/dist/templates/cursor/.cursor/skills/create-huenei-subagent/SKILL.md +223 -0
- package/dist/templates/cursor/.cursor/skills/create-huenei-subagent/examples.md +236 -0
- package/dist/templates/cursor/.cursor/skills/cursor-hooks/SKILL.md +1100 -0
- package/dist/templates/cursor/.cursor/skills/find-skills/SKILL.md +133 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/accessibility-reviewer.md +67 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/angular-code-reviewer.md +60 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/qa-test-expert.md +70 -0
- package/dist/templates/frontend/angular-base/.cursor/agents/security-auditor.md +58 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/auto-format.ts +70 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/auto-test-on-stop.ts +113 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/block-dangerous-commands.ts +160 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/ensure-tests-exist.ts +363 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/protect-sensitive-files.ts +118 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks/session-context.ts +110 -0
- package/dist/templates/frontend/angular-base/.cursor/hooks.json +41 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/angular-code-reviewer.md +64 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/nx-architecture-guardian.md +69 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/qa-test-expert.md +75 -0
- package/dist/templates/frontend/angular-nx/.cursor/agents/security-auditor.md +61 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/auto-format.ts +70 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/auto-test-on-stop.ts +115 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/block-dangerous-commands.ts +188 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/ensure-tests-exist.ts +399 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/protect-sensitive-files.ts +128 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks/session-context.ts +121 -0
- package/dist/templates/frontend/angular-nx/.cursor/hooks.json +41 -0
- package/dist/templates/frontend/react-vite/.cursor/agents/frontend-senior.agent.md +49 -49
- package/dist/templates/frontend/react-vite/.cursor/agents/qa-test-expert.agent.md +126 -49
- package/dist/templates/frontend/react-vite/.cursor/agents/security-expert.agent.md +39 -39
- package/dist/templates/frontend/react-vite/.cursor/agents/ux-ui-expert.agent.md +45 -45
- package/dist/templates/frontend/react-vite/.cursor/hooks/autoTestOnStop.ts +117 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/blockDangerous.ts +75 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/ensureTestsExist.ts +306 -220
- package/dist/templates/frontend/react-vite/.cursor/hooks/formatOnEdit.ts +49 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/protectSecrets.ts +88 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks/sessionInit.ts +77 -0
- package/dist/templates/frontend/react-vite/.cursor/hooks.json +41 -10
- package/dist/templates/frontend/react-vite/.cursor/settings.json +13 -13
- package/dist/templates/frontend/react-vite/.vscode/settings.json +31 -31
- package/dist/templates/frontend/react-vite/README.md +34 -34
- package/dist/templates/frontend/react-vite/package.json +82 -82
- package/dist/templates/frontend/react-vite/pnpm-lock.yaml +6575 -6575
- package/dist/templates/frontend/react-vite/src/__tests__/components/layout/navbar.test.tsx +63 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/avatar.test.tsx +74 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/badge.test.tsx +55 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/breadcrumb.test.tsx +140 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/button.test.tsx +121 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/card.test.tsx +144 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/dialog.test.tsx +121 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/form.test.tsx +165 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/input.test.tsx +52 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/label.test.tsx +40 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/password-input.test.tsx +59 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/separator.test.tsx +40 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/table.test.tsx +254 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/tabs.test.tsx +82 -0
- package/dist/templates/frontend/react-vite/src/__tests__/components/ui/textarea.test.tsx +47 -0
- package/dist/templates/frontend/react-vite/src/__tests__/helpers/render.tsx +114 -0
- package/dist/templates/frontend/react-vite/src/__tests__/hooks/useLocalStorage.test.ts +95 -0
- package/dist/templates/frontend/react-vite/src/__tests__/lib/queryClient.test.ts +24 -0
- package/dist/templates/frontend/react-vite/src/__tests__/lib/utils.test.ts +43 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/index.test.tsx +111 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/otra-ruta.test.tsx +126 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/root.test.tsx +78 -0
- package/dist/templates/frontend/react-vite/src/__tests__/routes/ui-components.test.tsx +286 -0
- package/dist/templates/frontend/react-vite/src/components/layout/navbar.tsx +38 -38
- package/dist/templates/frontend/react-vite/src/components/ui/avatar.tsx +42 -42
- package/dist/templates/frontend/react-vite/src/components/ui/dialog.tsx +122 -122
- package/dist/templates/frontend/react-vite/src/components/ui/table.tsx +229 -244
- package/dist/templates/frontend/react-vite/src/hooks/useLocalStorage.ts +32 -32
- package/dist/templates/frontend/react-vite/src/routes/__root.tsx +48 -48
- package/dist/templates/frontend/react-vite/src/routes/ui-components.tsx +359 -85
- package/dist/templates/frontend/react-vite/src/test/setup.ts +24 -24
- package/dist/templates/frontend/react-vite/vite.config.ts +2 -2
- package/dist/templates/frontend/react-vite/vitest.config.ts +13 -2
- package/dist/templates/frontend/react-vite-help/.cursor/RECONSTRUCTION-PROMPT.md +738 -0
- package/package.json +1 -1
- package/templates/README.md +7 -1
- package/templates/backend/README.md +19 -9
- package/templates/backend/nestjs-api-mysql/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/templates/backend/nestjs-api-mysql/.cursor/agents/prisma-guardian.md +67 -0
- package/templates/backend/nestjs-api-mysql/.cursor/agents/test-runner.md +57 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/blockDangerous.ts +98 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/formatOnEdit.ts +70 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/protectSecrets.ts +101 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/sessionInit.ts +104 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks/validatePrisma.ts +121 -0
- package/templates/backend/nestjs-api-mysql/.cursor/hooks.json +46 -0
- package/templates/backend/nestjs-api-mysql/README.md +26 -0
- package/templates/backend/nestjs-api-mysql/dist/tsconfig.build.tsbuildinfo +1 -1
- package/templates/backend/nestjs-api-mysql/eslint.config.mjs +1 -1
- package/templates/backend/nestjs-api-mysql/package.json +7 -7
- package/templates/backend/nestjs-api-postgres/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/templates/backend/nestjs-api-postgres/.cursor/agents/prisma-guardian.md +62 -0
- package/templates/backend/nestjs-api-postgres/.cursor/agents/security-auditor.md +71 -0
- package/templates/backend/nestjs-api-postgres/.cursor/agents/test-runner.md +58 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/auto-retry.ts +62 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/block-dangerous.ts +202 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/format-and-validate.ts +124 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/protect-secrets.ts +105 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks/session-context.ts +130 -0
- package/templates/backend/nestjs-api-postgres/.cursor/hooks.json +36 -0
- package/templates/backend/nestjs-api-postgres/eslint.config.mjs +1 -1
- package/templates/backend/nestjs-api-postgres/package.json +6 -6
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/code-reviewer.md +153 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/nestjs-architect.md +138 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/prisma-analyst.md +164 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/security-auditor.md +150 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/agents/test-engineer.md +290 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/auto-format.ts +80 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/block-dangerous-commands.ts +144 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/prisma-schema-watcher.ts +64 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/protect-sensitive-files.ts +122 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks/session-context.ts +105 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/hooks.json +18 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/conventional-commits/SKILL.md +318 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/docker/SKILL.md +82 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/jest/SKILL.md +72 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/logging-best-practices/SKILL.md +127 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/prisma-database-setup/SKILL.md +186 -0
- package/templates/backend/nestjs-api-sqlite/.cursor/skills/quality-gates-enforcer/SKILL.md +301 -0
- package/templates/backend/nestjs-api-sqlite/README.md +34 -1
- package/templates/backend/nestjs-api-sqlite/eslint.config.mjs +1 -1
- package/templates/backend/nestjs-api-sqlite/package.json +6 -6
- package/templates/backend/nestjs-api-sqlite/prisma/schema.prisma +1 -0
- package/templates/backend/nestjs-api-sqlite/prisma/seed.ts +2 -2
- package/templates/backend/nestjs-api-sqlite/src/posts/dto/post-response.dto.ts +5 -1
- package/templates/backend/nestjs-api-sqlite/src/users/dto/profile-response.dto.ts +1 -1
- package/templates/backend/nestjs-api-sqlite/src/users/dto/update-profile.dto.ts +1 -1
- package/templates/backend/nestjs-api-sqlite/src/users/dto/user-response.dto.ts +4 -0
- package/templates/backend/nestjs-api-sqlite/src/users/profile.service.ts +24 -8
- package/templates/backend/nestjs-api-sqlite/src/users/users.service.ts +1 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/agents/nestjs-code-reviewer.md +54 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/agents/prisma-guardian.md +67 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/agents/test-runner.md +57 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-endpoint.md +209 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/commands/new-model.md +201 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/autoTestOnStop.ts +127 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/blockDangerous.ts +98 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/ensureTestsExist.ts +405 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/formatOnEdit.ts +70 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/protectSecrets.ts +101 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/sessionInit.ts +104 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks/validatePrisma.ts +121 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/hooks.json +46 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/api-rest.mdc +126 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/authentication-security.mdc +86 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/dto-validation.mdc +93 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/general-rules.mdc +126 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/nestjs-architecture.mdc +83 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/prisma-standards.mdc +111 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/rules/swagger-documentation.mdc +90 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/api-security-best-practices/SKILL.md +907 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/docker-expert/SKILL.md +409 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-expert/SKILL.md +552 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/AGENTS.md +5958 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nestjs-the-best-practices/SKILL.md +130 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/nodejs-best-practices/SKILL.md +333 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/prisma-expert/SKILL.md +355 -0
- package/templates/backend/nestjs-api-sqlserver/.cursor/skills/sqlserver-table-design/SKILL.md +125 -0
- package/templates/backend/nestjs-api-sqlserver/.dockerignore +50 -0
- package/templates/backend/nestjs-api-sqlserver/.env.example +17 -0
- package/templates/backend/nestjs-api-sqlserver/.env.test +17 -0
- package/templates/backend/nestjs-api-sqlserver/.prettierrc +4 -0
- package/templates/backend/nestjs-api-sqlserver/README.md +587 -0
- package/templates/backend/nestjs-api-sqlserver/docker-compose.yml +24 -0
- package/templates/backend/nestjs-api-sqlserver/eslint.config.mjs +41 -0
- package/templates/backend/nestjs-api-sqlserver/nest-cli.json +8 -0
- package/templates/backend/nestjs-api-sqlserver/package.json +107 -0
- package/templates/backend/nestjs-api-sqlserver/prisma/schema.prisma +70 -0
- package/templates/backend/nestjs-api-sqlserver/prisma/seed.ts +215 -0
- package/templates/backend/nestjs-api-sqlserver/prisma.config.ts +12 -0
- package/templates/backend/nestjs-api-sqlserver/scripts/check-docker.js +64 -0
- package/templates/backend/nestjs-api-sqlserver/src/app.module.ts +39 -0
- package/templates/backend/nestjs-api-sqlserver/src/app.service.ts +8 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/auth.controller.ts +36 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/auth.module.ts +22 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/auth.service.ts +64 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/decorators/roles.decorator.ts +5 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/dto/login-response.dto.ts +23 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/dto/login.dto.ts +27 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/enums/role.enum.ts +5 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/guards/jwt-auth.guard.ts +20 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/guards/roles.guard.ts +23 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/strategies/jwt.strategy.ts +32 -0
- package/templates/backend/nestjs-api-sqlserver/src/auth/types.ts +18 -0
- package/templates/backend/nestjs-api-sqlserver/src/common/dto/paginated-response.dto.ts +16 -0
- package/templates/backend/nestjs-api-sqlserver/src/common/dto/pagination.dto.ts +31 -0
- package/templates/backend/nestjs-api-sqlserver/src/common/filters/http-exception.filter.ts +53 -0
- package/templates/backend/nestjs-api-sqlserver/src/config/env.validation.ts +41 -0
- package/templates/backend/nestjs-api-sqlserver/src/health/health.controller.ts +35 -0
- package/templates/backend/nestjs-api-sqlserver/src/health/health.module.ts +7 -0
- package/templates/backend/nestjs-api-sqlserver/src/main.ts +87 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/dto/create-post.dto.ts +32 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/dto/post-response.dto.ts +41 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/dto/update-post.dto.ts +31 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/posts.controller.ts +161 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/posts.module.ts +12 -0
- package/templates/backend/nestjs-api-sqlserver/src/posts/posts.service.ts +171 -0
- package/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.module.ts +9 -0
- package/templates/backend/nestjs-api-sqlserver/src/prisma/prisma.service.ts +62 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/constants/settings.constants.ts +9 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/profile-response.dto.ts +39 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/settings-response.dto.ts +18 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/update-profile.dto.ts +48 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/update-settings.dto.ts +40 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/dto/user-response.dto.ts +18 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/profile.service.ts +67 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/settings.service.ts +77 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/users.controller.ts +102 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/users.module.ts +14 -0
- package/templates/backend/nestjs-api-sqlserver/src/users/users.service.ts +27 -0
- package/templates/backend/nestjs-api-sqlserver/test/README.md +412 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/auth.e2e-spec.ts +147 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/health.e2e-spec.ts +62 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/posts.e2e-spec.ts +407 -0
- package/templates/backend/nestjs-api-sqlserver/test/e2e/users.e2e-spec.ts +287 -0
- package/templates/backend/nestjs-api-sqlserver/test/fixtures/test-data.ts +109 -0
- package/templates/backend/nestjs-api-sqlserver/test/helpers/auth.helper.ts +54 -0
- package/templates/backend/nestjs-api-sqlserver/test/helpers/db.helper.ts +68 -0
- package/templates/backend/nestjs-api-sqlserver/test/jest-e2e.json +12 -0
- package/templates/backend/nestjs-api-sqlserver/test/setup-e2e.ts +8 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/app.service.spec.ts +24 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/auth.controller.spec.ts +91 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/auth.service.spec.ts +161 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/health.controller.spec.ts +78 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/http-exception.filter.spec.ts +150 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/jwt-auth.guard.spec.ts +50 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/jwt.strategy.spec.ts +41 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/posts.controller.spec.ts +249 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/posts.service.spec.ts +328 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/profile.service.spec.ts +146 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/settings.service.spec.ts +242 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/users.controller.spec.ts +178 -0
- package/templates/backend/nestjs-api-sqlserver/test/unit/users.service.spec.ts +96 -0
- package/templates/backend/nestjs-api-sqlserver/tsconfig.build.json +4 -0
- package/templates/backend/nestjs-api-sqlserver/tsconfig.json +28 -0
- package/templates/cursor/.cursor/commands/configurar-cursor.md +763 -0
- package/templates/cursor/.cursor/skills/create-huenei-subagent/SKILL.md +223 -0
- package/templates/cursor/.cursor/skills/create-huenei-subagent/examples.md +236 -0
- package/templates/cursor/.cursor/skills/cursor-hooks/SKILL.md +1100 -0
- package/templates/cursor/.cursor/skills/find-skills/SKILL.md +133 -0
- package/templates/frontend/angular-base/.cursor/agents/accessibility-reviewer.md +67 -0
- package/templates/frontend/angular-base/.cursor/agents/angular-code-reviewer.md +60 -0
- package/templates/frontend/angular-base/.cursor/agents/qa-test-expert.md +70 -0
- package/templates/frontend/angular-base/.cursor/agents/security-auditor.md +58 -0
- package/templates/frontend/angular-base/.cursor/hooks/auto-format.ts +70 -0
- package/templates/frontend/angular-base/.cursor/hooks/auto-test-on-stop.ts +113 -0
- package/templates/frontend/angular-base/.cursor/hooks/block-dangerous-commands.ts +160 -0
- package/templates/frontend/angular-base/.cursor/hooks/ensure-tests-exist.ts +363 -0
- package/templates/frontend/angular-base/.cursor/hooks/protect-sensitive-files.ts +118 -0
- package/templates/frontend/angular-base/.cursor/hooks/session-context.ts +110 -0
- package/templates/frontend/angular-base/.cursor/hooks.json +41 -0
- package/templates/frontend/angular-nx/.cursor/agents/angular-code-reviewer.md +64 -0
- package/templates/frontend/angular-nx/.cursor/agents/nx-architecture-guardian.md +69 -0
- package/templates/frontend/angular-nx/.cursor/agents/qa-test-expert.md +75 -0
- package/templates/frontend/angular-nx/.cursor/agents/security-auditor.md +61 -0
- package/templates/frontend/angular-nx/.cursor/hooks/auto-format.ts +70 -0
- package/templates/frontend/angular-nx/.cursor/hooks/auto-test-on-stop.ts +115 -0
- package/templates/frontend/angular-nx/.cursor/hooks/block-dangerous-commands.ts +188 -0
- package/templates/frontend/angular-nx/.cursor/hooks/ensure-tests-exist.ts +399 -0
- package/templates/frontend/angular-nx/.cursor/hooks/protect-sensitive-files.ts +128 -0
- package/templates/frontend/angular-nx/.cursor/hooks/session-context.ts +121 -0
- package/templates/frontend/angular-nx/.cursor/hooks.json +41 -0
- package/templates/frontend/react-vite/.cursor/agents/frontend-senior.agent.md +49 -49
- package/templates/frontend/react-vite/.cursor/agents/qa-test-expert.agent.md +126 -49
- package/templates/frontend/react-vite/.cursor/agents/security-expert.agent.md +39 -39
- package/templates/frontend/react-vite/.cursor/agents/ux-ui-expert.agent.md +45 -45
- package/templates/frontend/react-vite/.cursor/hooks/autoTestOnStop.ts +117 -0
- package/templates/frontend/react-vite/.cursor/hooks/blockDangerous.ts +75 -0
- package/templates/frontend/react-vite/.cursor/hooks/ensureTestsExist.ts +306 -220
- package/templates/frontend/react-vite/.cursor/hooks/formatOnEdit.ts +49 -0
- package/templates/frontend/react-vite/.cursor/hooks/protectSecrets.ts +88 -0
- package/templates/frontend/react-vite/.cursor/hooks/sessionInit.ts +77 -0
- package/templates/frontend/react-vite/.cursor/hooks.json +41 -10
- package/templates/frontend/react-vite/.cursor/settings.json +13 -13
- package/templates/frontend/react-vite/.vscode/settings.json +31 -31
- package/templates/frontend/react-vite/README.md +34 -34
- package/templates/frontend/react-vite/package.json +82 -82
- package/templates/frontend/react-vite/pnpm-lock.yaml +6575 -6575
- package/templates/frontend/react-vite/src/__tests__/components/layout/navbar.test.tsx +63 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/avatar.test.tsx +74 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/badge.test.tsx +55 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/breadcrumb.test.tsx +140 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/button.test.tsx +121 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/card.test.tsx +144 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/dialog.test.tsx +121 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/form.test.tsx +165 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/input.test.tsx +52 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/label.test.tsx +40 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/password-input.test.tsx +59 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/separator.test.tsx +40 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/table.test.tsx +254 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/tabs.test.tsx +82 -0
- package/templates/frontend/react-vite/src/__tests__/components/ui/textarea.test.tsx +47 -0
- package/templates/frontend/react-vite/src/__tests__/helpers/render.tsx +114 -0
- package/templates/frontend/react-vite/src/__tests__/hooks/useLocalStorage.test.ts +95 -0
- package/templates/frontend/react-vite/src/__tests__/lib/queryClient.test.ts +24 -0
- package/templates/frontend/react-vite/src/__tests__/lib/utils.test.ts +43 -0
- package/templates/frontend/react-vite/src/__tests__/routes/index.test.tsx +111 -0
- package/templates/frontend/react-vite/src/__tests__/routes/otra-ruta.test.tsx +126 -0
- package/templates/frontend/react-vite/src/__tests__/routes/root.test.tsx +78 -0
- package/templates/frontend/react-vite/src/__tests__/routes/ui-components.test.tsx +286 -0
- package/templates/frontend/react-vite/src/components/layout/navbar.tsx +38 -38
- package/templates/frontend/react-vite/src/components/ui/avatar.tsx +42 -42
- package/templates/frontend/react-vite/src/components/ui/dialog.tsx +122 -122
- package/templates/frontend/react-vite/src/components/ui/table.tsx +229 -244
- package/templates/frontend/react-vite/src/hooks/useLocalStorage.ts +32 -32
- package/templates/frontend/react-vite/src/routes/__root.tsx +48 -48
- package/templates/frontend/react-vite/src/routes/ui-components.tsx +359 -85
- package/templates/frontend/react-vite/src/test/setup.ts +24 -24
- package/templates/frontend/react-vite/vite.config.ts +2 -2
- package/templates/frontend/react-vite/vitest.config.ts +13 -2
- package/templates/frontend/react-vite-help/.cursor/RECONSTRUCTION-PROMPT.md +738 -0
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
+
import { NotFoundException, ForbiddenException } from '@nestjs/common';
|
|
3
|
+
import { PostsService } from '../../src/posts/posts.service';
|
|
4
|
+
import { PrismaService } from '../../src/prisma/prisma.service';
|
|
5
|
+
|
|
6
|
+
describe('PostsService', () => {
|
|
7
|
+
let service: PostsService;
|
|
8
|
+
let prismaService: PrismaService;
|
|
9
|
+
|
|
10
|
+
const mockAuthor = {
|
|
11
|
+
id: 1,
|
|
12
|
+
email: 'author@example.com',
|
|
13
|
+
name: 'Author User',
|
|
14
|
+
role: 'READER' as const,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const mockPost = {
|
|
18
|
+
id: 1,
|
|
19
|
+
title: 'Test Post',
|
|
20
|
+
content: 'Test content',
|
|
21
|
+
published: false,
|
|
22
|
+
authorId: 1,
|
|
23
|
+
createdAt: new Date(),
|
|
24
|
+
author: mockAuthor,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const mockPrismaService = {
|
|
28
|
+
post: {
|
|
29
|
+
create: jest.fn(),
|
|
30
|
+
findMany: jest.fn(),
|
|
31
|
+
findUnique: jest.fn(),
|
|
32
|
+
update: jest.fn(),
|
|
33
|
+
delete: jest.fn(),
|
|
34
|
+
count: jest.fn(),
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
beforeEach(async () => {
|
|
39
|
+
const module: TestingModule = await Test.createTestingModule({
|
|
40
|
+
providers: [
|
|
41
|
+
PostsService,
|
|
42
|
+
{
|
|
43
|
+
provide: PrismaService,
|
|
44
|
+
useValue: mockPrismaService,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
}).compile();
|
|
48
|
+
|
|
49
|
+
service = module.get<PostsService>(PostsService);
|
|
50
|
+
prismaService = module.get<PrismaService>(PrismaService);
|
|
51
|
+
|
|
52
|
+
// Reset mocks
|
|
53
|
+
jest.clearAllMocks();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should be defined', () => {
|
|
57
|
+
expect(service).toBeDefined();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('create', () => {
|
|
61
|
+
const createPostDto = {
|
|
62
|
+
title: 'New Post',
|
|
63
|
+
content: 'New content',
|
|
64
|
+
published: false,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
it('should create a post successfully', async () => {
|
|
68
|
+
const newPost = {
|
|
69
|
+
id: 2,
|
|
70
|
+
...createPostDto,
|
|
71
|
+
authorId: 1,
|
|
72
|
+
createdAt: new Date(),
|
|
73
|
+
author: mockAuthor,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
mockPrismaService.post.create.mockResolvedValue(newPost);
|
|
77
|
+
|
|
78
|
+
const result = await service.create(createPostDto, 1);
|
|
79
|
+
|
|
80
|
+
expect(result).toEqual(newPost);
|
|
81
|
+
expect(mockPrismaService.post.create).toHaveBeenCalledWith({
|
|
82
|
+
data: {
|
|
83
|
+
...createPostDto,
|
|
84
|
+
authorId: 1,
|
|
85
|
+
},
|
|
86
|
+
include: {
|
|
87
|
+
author: {
|
|
88
|
+
select: {
|
|
89
|
+
id: true,
|
|
90
|
+
email: true,
|
|
91
|
+
name: true,
|
|
92
|
+
role: true,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe('findAll', () => {
|
|
101
|
+
const mockPosts = [
|
|
102
|
+
{ ...mockPost, id: 1, published: true },
|
|
103
|
+
{ ...mockPost, id: 2, published: false },
|
|
104
|
+
{ ...mockPost, id: 3, published: true },
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
it('should return all posts without filter', async () => {
|
|
108
|
+
mockPrismaService.post.findMany.mockResolvedValue(mockPosts);
|
|
109
|
+
mockPrismaService.post.count.mockResolvedValue(3);
|
|
110
|
+
|
|
111
|
+
const result = await service.findAll({ page: 1, limit: 10 });
|
|
112
|
+
|
|
113
|
+
expect(result).toHaveProperty('data');
|
|
114
|
+
expect(result).toHaveProperty('meta');
|
|
115
|
+
expect(result.data).toEqual(mockPosts);
|
|
116
|
+
expect(result.meta.total).toBe(3);
|
|
117
|
+
expect(result.meta.page).toBe(1);
|
|
118
|
+
expect(result.meta.limit).toBe(10);
|
|
119
|
+
expect(mockPrismaService.post.findMany).toHaveBeenCalledWith({
|
|
120
|
+
where: undefined,
|
|
121
|
+
include: {
|
|
122
|
+
author: {
|
|
123
|
+
select: {
|
|
124
|
+
id: true,
|
|
125
|
+
email: true,
|
|
126
|
+
name: true,
|
|
127
|
+
role: true,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
orderBy: {
|
|
132
|
+
createdAt: 'desc',
|
|
133
|
+
},
|
|
134
|
+
skip: 0,
|
|
135
|
+
take: 10,
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('should filter by published=true', async () => {
|
|
140
|
+
const publishedPosts = mockPosts.filter((p) => p.published);
|
|
141
|
+
mockPrismaService.post.findMany.mockResolvedValue(publishedPosts);
|
|
142
|
+
mockPrismaService.post.count.mockResolvedValue(2);
|
|
143
|
+
|
|
144
|
+
const result = await service.findAll({ published: true, page: 1, limit: 10 });
|
|
145
|
+
|
|
146
|
+
expect(result).toHaveProperty('data');
|
|
147
|
+
expect(result).toHaveProperty('meta');
|
|
148
|
+
expect(result.data).toEqual(publishedPosts);
|
|
149
|
+
expect(result.meta.total).toBe(2);
|
|
150
|
+
expect(mockPrismaService.post.findMany).toHaveBeenCalledWith({
|
|
151
|
+
where: { published: true },
|
|
152
|
+
include: {
|
|
153
|
+
author: {
|
|
154
|
+
select: {
|
|
155
|
+
id: true,
|
|
156
|
+
email: true,
|
|
157
|
+
name: true,
|
|
158
|
+
role: true,
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
orderBy: {
|
|
163
|
+
createdAt: 'desc',
|
|
164
|
+
},
|
|
165
|
+
skip: 0,
|
|
166
|
+
take: 10,
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('should filter by published=false', async () => {
|
|
171
|
+
const unpublishedPosts = mockPosts.filter((p) => !p.published);
|
|
172
|
+
mockPrismaService.post.findMany.mockResolvedValue(unpublishedPosts);
|
|
173
|
+
mockPrismaService.post.count.mockResolvedValue(1);
|
|
174
|
+
|
|
175
|
+
const result = await service.findAll({ published: false, page: 1, limit: 10 });
|
|
176
|
+
|
|
177
|
+
expect(result).toHaveProperty('data');
|
|
178
|
+
expect(result).toHaveProperty('meta');
|
|
179
|
+
expect(result.data).toEqual(unpublishedPosts);
|
|
180
|
+
expect(result.meta.total).toBe(1);
|
|
181
|
+
expect(mockPrismaService.post.findMany).toHaveBeenCalledWith({
|
|
182
|
+
where: { published: false },
|
|
183
|
+
include: {
|
|
184
|
+
author: {
|
|
185
|
+
select: {
|
|
186
|
+
id: true,
|
|
187
|
+
email: true,
|
|
188
|
+
name: true,
|
|
189
|
+
role: true,
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
orderBy: {
|
|
194
|
+
createdAt: 'desc',
|
|
195
|
+
},
|
|
196
|
+
skip: 0,
|
|
197
|
+
take: 10,
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe('findOne', () => {
|
|
203
|
+
it('should return post when it exists', async () => {
|
|
204
|
+
mockPrismaService.post.findUnique.mockResolvedValue(mockPost);
|
|
205
|
+
|
|
206
|
+
const result = await service.findOne(1);
|
|
207
|
+
|
|
208
|
+
expect(result).toEqual(mockPost);
|
|
209
|
+
expect(mockPrismaService.post.findUnique).toHaveBeenCalledWith({
|
|
210
|
+
where: { id: 1 },
|
|
211
|
+
include: {
|
|
212
|
+
author: {
|
|
213
|
+
select: {
|
|
214
|
+
id: true,
|
|
215
|
+
email: true,
|
|
216
|
+
name: true,
|
|
217
|
+
role: true,
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('should throw NotFoundException when post does not exist', async () => {
|
|
225
|
+
mockPrismaService.post.findUnique.mockResolvedValue(null);
|
|
226
|
+
|
|
227
|
+
await expect(service.findOne(999)).rejects.toThrow(NotFoundException);
|
|
228
|
+
await expect(service.findOne(999)).rejects.toThrow('Post with ID 999 not found');
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
describe('update', () => {
|
|
233
|
+
const updatePostDto = {
|
|
234
|
+
title: 'Updated Title',
|
|
235
|
+
content: 'Updated content',
|
|
236
|
+
published: true,
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
it('should update post when user is the author', async () => {
|
|
240
|
+
const updatedPost = {
|
|
241
|
+
...mockPost,
|
|
242
|
+
...updatePostDto,
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
mockPrismaService.post.findUnique.mockResolvedValue(mockPost);
|
|
246
|
+
mockPrismaService.post.update.mockResolvedValue(updatedPost);
|
|
247
|
+
|
|
248
|
+
const result = await service.update(1, updatePostDto, 1);
|
|
249
|
+
|
|
250
|
+
expect(result).toEqual(updatedPost);
|
|
251
|
+
expect(mockPrismaService.post.update).toHaveBeenCalledWith({
|
|
252
|
+
where: { id: 1 },
|
|
253
|
+
data: updatePostDto,
|
|
254
|
+
include: {
|
|
255
|
+
author: {
|
|
256
|
+
select: {
|
|
257
|
+
id: true,
|
|
258
|
+
email: true,
|
|
259
|
+
name: true,
|
|
260
|
+
role: true,
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('should throw NotFoundException when post does not exist', async () => {
|
|
268
|
+
mockPrismaService.post.findUnique.mockResolvedValue(null);
|
|
269
|
+
|
|
270
|
+
await expect(service.update(999, updatePostDto, 1)).rejects.toThrow(
|
|
271
|
+
NotFoundException,
|
|
272
|
+
);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it('should throw ForbiddenException when user is not the author', async () => {
|
|
276
|
+
mockPrismaService.post.findUnique.mockResolvedValue(mockPost);
|
|
277
|
+
|
|
278
|
+
await expect(service.update(1, updatePostDto, 2)).rejects.toThrow(
|
|
279
|
+
ForbiddenException,
|
|
280
|
+
);
|
|
281
|
+
await expect(service.update(1, updatePostDto, 2)).rejects.toThrow(
|
|
282
|
+
'You do not have permission to modify this post',
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
expect(mockPrismaService.post.update).not.toHaveBeenCalled();
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
describe('remove', () => {
|
|
290
|
+
it('should delete post when user is the author', async () => {
|
|
291
|
+
const deletedPost = {
|
|
292
|
+
id: 1,
|
|
293
|
+
title: mockPost.title,
|
|
294
|
+
content: mockPost.content,
|
|
295
|
+
published: mockPost.published,
|
|
296
|
+
authorId: mockPost.authorId,
|
|
297
|
+
createdAt: mockPost.createdAt,
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
mockPrismaService.post.findUnique.mockResolvedValue(mockPost);
|
|
301
|
+
mockPrismaService.post.delete.mockResolvedValue(deletedPost);
|
|
302
|
+
|
|
303
|
+
const result = await service.remove(1, 1);
|
|
304
|
+
|
|
305
|
+
expect(result).toEqual(deletedPost);
|
|
306
|
+
expect(mockPrismaService.post.delete).toHaveBeenCalledWith({
|
|
307
|
+
where: { id: 1 },
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('should throw NotFoundException when post does not exist', async () => {
|
|
312
|
+
mockPrismaService.post.findUnique.mockResolvedValue(null);
|
|
313
|
+
|
|
314
|
+
await expect(service.remove(999, 1)).rejects.toThrow(NotFoundException);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it('should throw ForbiddenException when user is not the author', async () => {
|
|
318
|
+
mockPrismaService.post.findUnique.mockResolvedValue(mockPost);
|
|
319
|
+
|
|
320
|
+
await expect(service.remove(1, 2)).rejects.toThrow(ForbiddenException);
|
|
321
|
+
await expect(service.remove(1, 2)).rejects.toThrow(
|
|
322
|
+
'You do not have permission to delete this post',
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
expect(mockPrismaService.post.delete).not.toHaveBeenCalled();
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
+
import { ProfileService } from '../../src/users/profile.service';
|
|
3
|
+
import { PrismaService } from '../../src/prisma/prisma.service';
|
|
4
|
+
|
|
5
|
+
describe('ProfileService', () => {
|
|
6
|
+
let service: ProfileService;
|
|
7
|
+
let prismaService: PrismaService;
|
|
8
|
+
|
|
9
|
+
const mockProfile = {
|
|
10
|
+
id: 1,
|
|
11
|
+
userId: 1,
|
|
12
|
+
avatar: 'https://example.com/avatar.jpg',
|
|
13
|
+
bio: 'Test bio',
|
|
14
|
+
phone: '+1234567890',
|
|
15
|
+
website: 'https://example.com',
|
|
16
|
+
publicName: 'Test Public Name',
|
|
17
|
+
metadata: null,
|
|
18
|
+
createdAt: new Date(),
|
|
19
|
+
updatedAt: new Date(),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const mockPrismaService = {
|
|
23
|
+
userProfile: {
|
|
24
|
+
findUnique: jest.fn(),
|
|
25
|
+
create: jest.fn(),
|
|
26
|
+
update: jest.fn(),
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
beforeEach(async () => {
|
|
31
|
+
const module: TestingModule = await Test.createTestingModule({
|
|
32
|
+
providers: [
|
|
33
|
+
ProfileService,
|
|
34
|
+
{
|
|
35
|
+
provide: PrismaService,
|
|
36
|
+
useValue: mockPrismaService,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
}).compile();
|
|
40
|
+
|
|
41
|
+
service = module.get<ProfileService>(ProfileService);
|
|
42
|
+
prismaService = module.get<PrismaService>(PrismaService);
|
|
43
|
+
|
|
44
|
+
// Reset mocks
|
|
45
|
+
jest.clearAllMocks();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should be defined', () => {
|
|
49
|
+
expect(service).toBeDefined();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('getProfile', () => {
|
|
53
|
+
it('should return existing profile', async () => {
|
|
54
|
+
mockPrismaService.userProfile.findUnique.mockResolvedValue(mockProfile);
|
|
55
|
+
|
|
56
|
+
const result = await service.getProfile(1);
|
|
57
|
+
|
|
58
|
+
expect(result).toEqual(mockProfile);
|
|
59
|
+
expect(mockPrismaService.userProfile.findUnique).toHaveBeenCalledWith({
|
|
60
|
+
where: { userId: 1 },
|
|
61
|
+
});
|
|
62
|
+
expect(mockPrismaService.userProfile.create).not.toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should create profile if it does not exist', async () => {
|
|
66
|
+
const newProfile = {
|
|
67
|
+
id: 2,
|
|
68
|
+
userId: 1,
|
|
69
|
+
avatar: null,
|
|
70
|
+
bio: null,
|
|
71
|
+
phone: null,
|
|
72
|
+
website: null,
|
|
73
|
+
publicName: null,
|
|
74
|
+
metadata: null,
|
|
75
|
+
createdAt: new Date(),
|
|
76
|
+
updatedAt: new Date(),
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
mockPrismaService.userProfile.findUnique.mockResolvedValue(null);
|
|
80
|
+
mockPrismaService.userProfile.create.mockResolvedValue(newProfile);
|
|
81
|
+
|
|
82
|
+
const result = await service.getProfile(1);
|
|
83
|
+
|
|
84
|
+
expect(result).toEqual(newProfile);
|
|
85
|
+
expect(mockPrismaService.userProfile.findUnique).toHaveBeenCalledWith({
|
|
86
|
+
where: { userId: 1 },
|
|
87
|
+
});
|
|
88
|
+
expect(mockPrismaService.userProfile.create).toHaveBeenCalledWith({
|
|
89
|
+
data: { userId: 1 },
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('updateProfile', () => {
|
|
95
|
+
const updateDto = {
|
|
96
|
+
bio: 'Updated bio',
|
|
97
|
+
avatar: 'https://example.com/new-avatar.jpg',
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
it('should update existing profile', async () => {
|
|
101
|
+
const updatedProfile = { ...mockProfile, ...updateDto };
|
|
102
|
+
|
|
103
|
+
mockPrismaService.userProfile.findUnique.mockResolvedValue(mockProfile);
|
|
104
|
+
mockPrismaService.userProfile.update.mockResolvedValue(updatedProfile);
|
|
105
|
+
|
|
106
|
+
const result = await service.updateProfile(1, updateDto);
|
|
107
|
+
|
|
108
|
+
expect(result).toEqual(updatedProfile);
|
|
109
|
+
expect(mockPrismaService.userProfile.findUnique).toHaveBeenCalledWith({
|
|
110
|
+
where: { userId: 1 },
|
|
111
|
+
});
|
|
112
|
+
expect(mockPrismaService.userProfile.update).toHaveBeenCalledWith({
|
|
113
|
+
where: { userId: 1 },
|
|
114
|
+
data: updateDto,
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should create profile if it does not exist', async () => {
|
|
119
|
+
const newProfile = {
|
|
120
|
+
id: 3,
|
|
121
|
+
userId: 1,
|
|
122
|
+
...updateDto,
|
|
123
|
+
phone: null,
|
|
124
|
+
website: null,
|
|
125
|
+
publicName: null,
|
|
126
|
+
metadata: null,
|
|
127
|
+
createdAt: new Date(),
|
|
128
|
+
updatedAt: new Date(),
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
mockPrismaService.userProfile.findUnique.mockResolvedValue(null);
|
|
132
|
+
mockPrismaService.userProfile.create.mockResolvedValue(newProfile);
|
|
133
|
+
|
|
134
|
+
const result = await service.updateProfile(1, updateDto);
|
|
135
|
+
|
|
136
|
+
expect(result).toEqual(newProfile);
|
|
137
|
+
expect(mockPrismaService.userProfile.findUnique).toHaveBeenCalledWith({
|
|
138
|
+
where: { userId: 1 },
|
|
139
|
+
});
|
|
140
|
+
expect(mockPrismaService.userProfile.create).toHaveBeenCalledWith({
|
|
141
|
+
data: { userId: 1, ...updateDto },
|
|
142
|
+
});
|
|
143
|
+
expect(mockPrismaService.userProfile.update).not.toHaveBeenCalled();
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
+
import { SettingsService } from '../../src/users/settings.service';
|
|
3
|
+
import { PrismaService } from '../../src/prisma/prisma.service';
|
|
4
|
+
import { Prisma } from '@prisma/client';
|
|
5
|
+
|
|
6
|
+
describe('SettingsService', () => {
|
|
7
|
+
let service: SettingsService;
|
|
8
|
+
let prismaService: PrismaService;
|
|
9
|
+
|
|
10
|
+
const defaultPreferences = {
|
|
11
|
+
language: 'es',
|
|
12
|
+
theme: 'light',
|
|
13
|
+
emailNotifications: true,
|
|
14
|
+
pushNotifications: false,
|
|
15
|
+
privacy: 'private',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const mockSettings = {
|
|
19
|
+
id: 1,
|
|
20
|
+
userId: 1,
|
|
21
|
+
preferences: defaultPreferences as Prisma.JsonValue,
|
|
22
|
+
createdAt: new Date(),
|
|
23
|
+
updatedAt: new Date(),
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const mockPrismaService = {
|
|
27
|
+
userSettings: {
|
|
28
|
+
findUnique: jest.fn(),
|
|
29
|
+
create: jest.fn(),
|
|
30
|
+
update: jest.fn(),
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
beforeEach(async () => {
|
|
35
|
+
const module: TestingModule = await Test.createTestingModule({
|
|
36
|
+
providers: [
|
|
37
|
+
SettingsService,
|
|
38
|
+
{
|
|
39
|
+
provide: PrismaService,
|
|
40
|
+
useValue: mockPrismaService,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
}).compile();
|
|
44
|
+
|
|
45
|
+
service = module.get<SettingsService>(SettingsService);
|
|
46
|
+
prismaService = module.get<PrismaService>(PrismaService);
|
|
47
|
+
|
|
48
|
+
// Reset mocks
|
|
49
|
+
jest.clearAllMocks();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should be defined', () => {
|
|
53
|
+
expect(service).toBeDefined();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('getSettings', () => {
|
|
57
|
+
it('should return existing settings', async () => {
|
|
58
|
+
mockPrismaService.userSettings.findUnique.mockResolvedValue(mockSettings);
|
|
59
|
+
|
|
60
|
+
const result = await service.getSettings(1);
|
|
61
|
+
|
|
62
|
+
expect(result).toEqual(defaultPreferences);
|
|
63
|
+
expect(mockPrismaService.userSettings.findUnique).toHaveBeenCalledWith({
|
|
64
|
+
where: { userId: 1 },
|
|
65
|
+
});
|
|
66
|
+
expect(mockPrismaService.userSettings.create).not.toHaveBeenCalled();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should create settings with defaults if they do not exist', async () => {
|
|
70
|
+
const newSettings = {
|
|
71
|
+
id: 2,
|
|
72
|
+
userId: 1,
|
|
73
|
+
preferences: defaultPreferences as Prisma.JsonValue,
|
|
74
|
+
createdAt: new Date(),
|
|
75
|
+
updatedAt: new Date(),
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
mockPrismaService.userSettings.findUnique.mockResolvedValue(null);
|
|
79
|
+
mockPrismaService.userSettings.create.mockResolvedValue(newSettings);
|
|
80
|
+
|
|
81
|
+
const result = await service.getSettings(1);
|
|
82
|
+
|
|
83
|
+
expect(result).toEqual(defaultPreferences);
|
|
84
|
+
expect(mockPrismaService.userSettings.findUnique).toHaveBeenCalledWith({
|
|
85
|
+
where: { userId: 1 },
|
|
86
|
+
});
|
|
87
|
+
expect(mockPrismaService.userSettings.create).toHaveBeenCalledWith({
|
|
88
|
+
data: {
|
|
89
|
+
userId: 1,
|
|
90
|
+
preferences: defaultPreferences as Prisma.InputJsonValue,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe('updateSettings', () => {
|
|
97
|
+
it('should update existing settings', async () => {
|
|
98
|
+
const updateDto = {
|
|
99
|
+
theme: 'dark',
|
|
100
|
+
language: 'en',
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const updatedPreferences = {
|
|
104
|
+
...defaultPreferences,
|
|
105
|
+
...updateDto,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const updatedSettings = {
|
|
109
|
+
...mockSettings,
|
|
110
|
+
preferences: updatedPreferences as Prisma.JsonValue,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
mockPrismaService.userSettings.findUnique.mockResolvedValue(mockSettings);
|
|
114
|
+
mockPrismaService.userSettings.update.mockResolvedValue(updatedSettings);
|
|
115
|
+
|
|
116
|
+
const result = await service.updateSettings(1, updateDto);
|
|
117
|
+
|
|
118
|
+
expect(result).toEqual(updatedPreferences);
|
|
119
|
+
expect(mockPrismaService.userSettings.findUnique).toHaveBeenCalledWith({
|
|
120
|
+
where: { userId: 1 },
|
|
121
|
+
});
|
|
122
|
+
expect(mockPrismaService.userSettings.update).toHaveBeenCalledWith({
|
|
123
|
+
where: { userId: 1 },
|
|
124
|
+
data: {
|
|
125
|
+
preferences: updatedPreferences as Prisma.InputJsonValue,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('should merge with existing settings', async () => {
|
|
131
|
+
const existingPreferences = {
|
|
132
|
+
language: 'en',
|
|
133
|
+
theme: 'dark',
|
|
134
|
+
emailNotifications: false,
|
|
135
|
+
pushNotifications: true,
|
|
136
|
+
privacy: 'public',
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const existingSettings = {
|
|
140
|
+
...mockSettings,
|
|
141
|
+
preferences: existingPreferences as Prisma.JsonValue,
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const updateDto = {
|
|
145
|
+
theme: 'light',
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const mergedPreferences = {
|
|
149
|
+
...existingPreferences,
|
|
150
|
+
theme: 'light',
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const updatedSettings = {
|
|
154
|
+
...mockSettings,
|
|
155
|
+
preferences: mergedPreferences as Prisma.JsonValue,
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
mockPrismaService.userSettings.findUnique.mockResolvedValue(existingSettings);
|
|
159
|
+
mockPrismaService.userSettings.update.mockResolvedValue(updatedSettings);
|
|
160
|
+
|
|
161
|
+
const result = await service.updateSettings(1, updateDto);
|
|
162
|
+
|
|
163
|
+
expect(result).toEqual(mergedPreferences);
|
|
164
|
+
expect(mockPrismaService.userSettings.update).toHaveBeenCalledWith({
|
|
165
|
+
where: { userId: 1 },
|
|
166
|
+
data: {
|
|
167
|
+
preferences: mergedPreferences as Prisma.InputJsonValue,
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('should create settings with defaults and updates if they do not exist', async () => {
|
|
173
|
+
const updateDto = {
|
|
174
|
+
theme: 'dark',
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const newPreferences = {
|
|
178
|
+
...defaultPreferences,
|
|
179
|
+
...updateDto,
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const newSettings = {
|
|
183
|
+
id: 3,
|
|
184
|
+
userId: 1,
|
|
185
|
+
preferences: newPreferences as Prisma.JsonValue,
|
|
186
|
+
createdAt: new Date(),
|
|
187
|
+
updatedAt: new Date(),
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
mockPrismaService.userSettings.findUnique.mockResolvedValue(null);
|
|
191
|
+
mockPrismaService.userSettings.create.mockResolvedValue(newSettings);
|
|
192
|
+
|
|
193
|
+
const result = await service.updateSettings(1, updateDto);
|
|
194
|
+
|
|
195
|
+
expect(result).toEqual(newPreferences);
|
|
196
|
+
expect(mockPrismaService.userSettings.findUnique).toHaveBeenCalledWith({
|
|
197
|
+
where: { userId: 1 },
|
|
198
|
+
});
|
|
199
|
+
expect(mockPrismaService.userSettings.create).toHaveBeenCalledWith({
|
|
200
|
+
data: {
|
|
201
|
+
userId: 1,
|
|
202
|
+
preferences: newPreferences as Prisma.InputJsonValue,
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
expect(mockPrismaService.userSettings.update).not.toHaveBeenCalled();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('should filter out undefined values from DTO', async () => {
|
|
209
|
+
const updateDto = {
|
|
210
|
+
theme: 'dark',
|
|
211
|
+
language: undefined,
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const cleanedDto = {
|
|
215
|
+
theme: 'dark',
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const updatedPreferences = {
|
|
219
|
+
...defaultPreferences,
|
|
220
|
+
...cleanedDto,
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const updatedSettings = {
|
|
224
|
+
...mockSettings,
|
|
225
|
+
preferences: updatedPreferences as Prisma.JsonValue,
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
mockPrismaService.userSettings.findUnique.mockResolvedValue(mockSettings);
|
|
229
|
+
mockPrismaService.userSettings.update.mockResolvedValue(updatedSettings);
|
|
230
|
+
|
|
231
|
+
const result = await service.updateSettings(1, updateDto);
|
|
232
|
+
|
|
233
|
+
expect(result).toEqual(updatedPreferences);
|
|
234
|
+
expect(mockPrismaService.userSettings.update).toHaveBeenCalledWith({
|
|
235
|
+
where: { userId: 1 },
|
|
236
|
+
data: {
|
|
237
|
+
preferences: updatedPreferences as Prisma.InputJsonValue,
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
});
|