kybernus 3.0.1 → 3.2.0
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/README.md +1 -1
- package/dist/cli/commands/ecommerce.d.ts +3 -0
- package/dist/cli/commands/ecommerce.d.ts.map +1 -0
- package/dist/cli/commands/ecommerce.js +164 -0
- package/dist/cli/commands/ecommerce.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/ecommerce/.env.example +10 -0
- package/templates/ecommerce/.github/workflows/ci.yml +102 -0
- package/templates/ecommerce/.github/workflows/deploy.yml +31 -0
- package/templates/ecommerce/.prettierrc +9 -0
- package/templates/ecommerce/Dockerfile +54 -0
- package/templates/ecommerce/README.md +295 -0
- package/templates/ecommerce/apps/api/.env.example +59 -0
- package/templates/ecommerce/apps/api/jest.config.ts +50 -0
- package/templates/ecommerce/apps/api/jest.integration.config.ts +45 -0
- package/templates/ecommerce/apps/api/package.json +59 -0
- package/templates/ecommerce/apps/api/prisma/migrations/20260306000137_init/migration.sql +184 -0
- package/templates/ecommerce/apps/api/prisma/migrations/migration_lock.toml +3 -0
- package/templates/ecommerce/apps/api/prisma/schema.prisma +181 -0
- package/templates/ecommerce/apps/api/prisma/seed.ts +159 -0
- package/templates/ecommerce/apps/api/src/__tests__/app.test.ts +39 -0
- package/templates/ecommerce/apps/api/src/__tests__/globalSetup.ts +34 -0
- package/templates/ecommerce/apps/api/src/__tests__/globalTeardown.ts +16 -0
- package/templates/ecommerce/apps/api/src/__tests__/setup.db.ts +18 -0
- package/templates/ecommerce/apps/api/src/__tests__/setup.env.ts +14 -0
- package/templates/ecommerce/apps/api/src/app.ts +133 -0
- package/templates/ecommerce/apps/api/src/application/admin/admin-user.service.ts +24 -0
- package/templates/ecommerce/apps/api/src/application/admin/dashboard.service.ts +102 -0
- package/templates/ecommerce/apps/api/src/application/auth/auth.service.ts +185 -0
- package/templates/ecommerce/apps/api/src/application/cart/cart.service.ts +151 -0
- package/templates/ecommerce/apps/api/src/application/cart/coupon.service.ts +51 -0
- package/templates/ecommerce/apps/api/src/application/catalog/catalog.service.ts +168 -0
- package/templates/ecommerce/apps/api/src/application/checkout/checkout.service.ts +114 -0
- package/templates/ecommerce/apps/api/src/application/orders/order.service.ts +93 -0
- package/templates/ecommerce/apps/api/src/application/ports/email.port.ts +3 -0
- package/templates/ecommerce/apps/api/src/application/ports/payment.port.ts +24 -0
- package/templates/ecommerce/apps/api/src/application/ports/shipping.port.ts +9 -0
- package/templates/ecommerce/apps/api/src/application/ports/storage.port.ts +3 -0
- package/templates/ecommerce/apps/api/src/application/ports/token-blacklist.port.ts +4 -0
- package/templates/ecommerce/apps/api/src/application/ports/token.port.ts +18 -0
- package/templates/ecommerce/apps/api/src/application/profile/profile.service.ts +76 -0
- package/templates/ecommerce/apps/api/src/domain/auth/user.entity.ts +109 -0
- package/templates/ecommerce/apps/api/src/domain/auth/user.repository.ts +11 -0
- package/templates/ecommerce/apps/api/src/domain/cart/cart.entity.ts +136 -0
- package/templates/ecommerce/apps/api/src/domain/cart/cart.repository.ts +8 -0
- package/templates/ecommerce/apps/api/src/domain/cart/coupon.entity.ts +58 -0
- package/templates/ecommerce/apps/api/src/domain/cart/coupon.repository.ts +10 -0
- package/templates/ecommerce/apps/api/src/domain/catalog/category.entity.ts +51 -0
- package/templates/ecommerce/apps/api/src/domain/catalog/category.repository.ts +10 -0
- package/templates/ecommerce/apps/api/src/domain/catalog/product.entity.ts +130 -0
- package/templates/ecommerce/apps/api/src/domain/catalog/product.repository.ts +28 -0
- package/templates/ecommerce/apps/api/src/domain/checkout/order.entity.ts +121 -0
- package/templates/ecommerce/apps/api/src/domain/checkout/order.repository.ts +11 -0
- package/templates/ecommerce/apps/api/src/domain/shared/AppError.ts +12 -0
- package/templates/ecommerce/apps/api/src/infrastructure/cache/redis.ts +16 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/admin.registry.ts +13 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/auth.registry.ts +34 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/cart.registry.ts +49 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/catalog.registry.ts +24 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/checkout.registry.ts +47 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/orders.registry.ts +6 -0
- package/templates/ecommerce/apps/api/src/infrastructure/config/registry/profile.registry.ts +4 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/cart.memory.repository.ts +33 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/category.memory.repository.ts +41 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/coupon.memory.repository.ts +55 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/order.memory.repository.ts +75 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/product.memory.repository.ts +100 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/user.memory.repository.ts +54 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma/auth/user.prisma.repository.ts +83 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma/catalog/category.prisma.repository.ts +69 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma/catalog/product.prisma.repository.ts +185 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma/checkout/order.prisma.repository.ts +149 -0
- package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma-client.ts +17 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/email/email.registry.ts +18 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/email/ethereal.email.service.ts +38 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/email/noop.email.service.ts +12 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/email/smtp.email.service.ts +36 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/payment/stripe-webhook.handler.ts +83 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/payment/stripe.adapter.ts +39 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/shipping/mock.shipping.service.ts +17 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/storage/in-memory.storage.service.ts +11 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/storage/local-disk.storage.service.ts +27 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/storage/s3.storage.service.ts +52 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/storage/storage.registry.ts +19 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/token/redis.token.blacklist.ts +23 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/token/token.blacklist.ts +30 -0
- package/templates/ecommerce/apps/api/src/infrastructure/services/token/token.service.ts +136 -0
- package/templates/ecommerce/apps/api/src/modules/admin/__tests__/admin.routes.integration.test.ts +250 -0
- package/templates/ecommerce/apps/api/src/modules/admin/admin.controller.ts +116 -0
- package/templates/ecommerce/apps/api/src/modules/admin/admin.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/admin/admin.routes.ts +21 -0
- package/templates/ecommerce/apps/api/src/modules/admin/admin.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/admin/admin.user.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/auth.logout.redis.test.ts +104 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/auth.routes.integration.test.ts +211 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/auth.service.unit.test.ts +260 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/email.service.unit.test.ts +94 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/token.blacklist.redis.test.ts +65 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/user.entity.unit.test.ts +79 -0
- package/templates/ecommerce/apps/api/src/modules/auth/__tests__/user.prisma.repository.test.ts +138 -0
- package/templates/ecommerce/apps/api/src/modules/auth/auth.controller.ts +148 -0
- package/templates/ecommerce/apps/api/src/modules/auth/auth.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/auth.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/modules/auth/auth.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/redis.token.blacklist.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/token.blacklist.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/auth/token.service.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/auth/user.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/user.prisma.repository.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/auth/user.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/cart/__tests__/cart.entity.unit.test.ts +144 -0
- package/templates/ecommerce/apps/api/src/modules/cart/__tests__/cart.routes.integration.test.ts +242 -0
- package/templates/ecommerce/apps/api/src/modules/cart/__tests__/cart.service.unit.test.ts +151 -0
- package/templates/ecommerce/apps/api/src/modules/cart/__tests__/coupon.admin.integration.test.ts +136 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.controller.ts +94 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/modules/cart/cart.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/cart/coupon.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/cart/coupon.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/cart/coupon.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/cart/shipping.service.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/__tests__/catalog.routes.integration.test.ts +275 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/__tests__/catalog.service.unit.test.ts +223 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/__tests__/product.image.integration.test.ts +130 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/__tests__/product.prisma.repository.test.ts +174 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/catalog.controller.ts +176 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/catalog.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/catalog.routes.ts +38 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/catalog.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/category.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/category.prisma.repository.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/category.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/product.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/product.prisma.repository.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/catalog/product.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/__tests__/checkout.routes.integration.test.ts +163 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/__tests__/checkout.service.unit.test.ts +191 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/__tests__/order.prisma.repository.test.ts +150 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/checkout.controller.ts +59 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/checkout.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/checkout.routes.ts +18 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/checkout.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/order.entity.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/order.prisma.repository.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/order.repository.ts +2 -0
- package/templates/ecommerce/apps/api/src/modules/checkout/tax.service.ts +9 -0
- package/templates/ecommerce/apps/api/src/modules/orders/__tests__/order.entity.unit.test.ts +68 -0
- package/templates/ecommerce/apps/api/src/modules/orders/__tests__/order.routes.integration.test.ts +254 -0
- package/templates/ecommerce/apps/api/src/modules/orders/__tests__/order.service.email.unit.test.ts +142 -0
- package/templates/ecommerce/apps/api/src/modules/orders/order.controller.ts +96 -0
- package/templates/ecommerce/apps/api/src/modules/orders/order.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/orders/order.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/modules/orders/order.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/payment/__tests__/stripe-webhook.unit.test.ts +330 -0
- package/templates/ecommerce/apps/api/src/modules/payment/__tests__/stripe.adapter.unit.test.ts +84 -0
- package/templates/ecommerce/apps/api/src/modules/payment/adapters/stripe.adapter.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/payment/payment.port.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/payment/stripe-webhook.handler.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/profile/__tests__/profile.routes.integration.test.ts +180 -0
- package/templates/ecommerce/apps/api/src/modules/profile/__tests__/profile.service.unit.test.ts +187 -0
- package/templates/ecommerce/apps/api/src/modules/profile/profile.controller.ts +92 -0
- package/templates/ecommerce/apps/api/src/modules/profile/profile.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/modules/profile/profile.routes.ts +14 -0
- package/templates/ecommerce/apps/api/src/modules/profile/profile.service.ts +1 -0
- package/templates/ecommerce/apps/api/src/presentation/middlewares/authenticate.ts +37 -0
- package/templates/ecommerce/apps/api/src/presentation/middlewares/authorize.ts +23 -0
- package/templates/ecommerce/apps/api/src/presentation/middlewares/errorHandler.ts +48 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/admin/admin.controller.ts +116 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/admin/admin.routes.ts +21 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/auth/auth.controller.ts +147 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/auth/auth.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/cart/cart.controller.ts +94 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/cart/cart.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/catalog/catalog.controller.ts +176 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/catalog/catalog.routes.ts +38 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/checkout/checkout.controller.ts +59 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/checkout/checkout.routes.ts +18 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/orders/order.controller.ts +96 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/orders/order.routes.ts +17 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/profile/profile.controller.ts +92 -0
- package/templates/ecommerce/apps/api/src/presentation/modules/profile/profile.routes.ts +14 -0
- package/templates/ecommerce/apps/api/src/presentation/validators/uuidParam.ts +20 -0
- package/templates/ecommerce/apps/api/src/server.ts +47 -0
- package/templates/ecommerce/apps/api/src/shared/__tests__/uuid.validation.test.ts +111 -0
- package/templates/ecommerce/apps/api/src/shared/errors/AppError.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/EtherealEmailService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/IEmailService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/NoopEmailService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/SmtpEmailService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/__tests__/ethereal.email.integration.test.ts +32 -0
- package/templates/ecommerce/apps/api/src/shared/infra/email/email.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/prisma.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/redis.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/IStorageService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/InMemoryStorageService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/LocalDiskStorageService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/S3StorageService.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/__tests__/s3.storage.unit.test.ts +73 -0
- package/templates/ecommerce/apps/api/src/shared/infra/storage/storage.registry.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/middlewares/authenticate.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/middlewares/authorize.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/middlewares/errorHandler.ts +1 -0
- package/templates/ecommerce/apps/api/src/shared/validators/uuidParam.ts +1 -0
- package/templates/ecommerce/apps/api/tsconfig.json +15 -0
- package/templates/ecommerce/apps/web/.env.example +8 -0
- package/templates/ecommerce/apps/web/index.html +19 -0
- package/templates/ecommerce/apps/web/jest.config.ts +45 -0
- package/templates/ecommerce/apps/web/package.json +38 -0
- package/templates/ecommerce/apps/web/src/App.tsx +133 -0
- package/templates/ecommerce/apps/web/src/__mocks__/fileMock.ts +1 -0
- package/templates/ecommerce/apps/web/src/__mocks__/styleMock.ts +1 -0
- package/templates/ecommerce/apps/web/src/index.css +159 -0
- package/templates/ecommerce/apps/web/src/main.tsx +13 -0
- package/templates/ecommerce/apps/web/src/modules/admin/__tests__/CouponsAdminPage.test.tsx +134 -0
- package/templates/ecommerce/apps/web/src/modules/admin/__tests__/DashboardPage.test.tsx +65 -0
- package/templates/ecommerce/apps/web/src/modules/admin/__tests__/OrdersAdminPage.test.tsx +79 -0
- package/templates/ecommerce/apps/web/src/modules/admin/__tests__/ProductsAdminPage.test.tsx +84 -0
- package/templates/ecommerce/apps/web/src/modules/admin/__tests__/UsersAdminPage.test.tsx +85 -0
- package/templates/ecommerce/apps/web/src/modules/admin/pages/CouponsAdminPage.tsx +179 -0
- package/templates/ecommerce/apps/web/src/modules/admin/pages/DashboardPage.tsx +58 -0
- package/templates/ecommerce/apps/web/src/modules/admin/pages/OrdersAdminPage.tsx +178 -0
- package/templates/ecommerce/apps/web/src/modules/admin/pages/ProductsAdminPage.tsx +444 -0
- package/templates/ecommerce/apps/web/src/modules/admin/pages/UsersAdminPage.tsx +87 -0
- package/templates/ecommerce/apps/web/src/modules/auth/LoginForm.tsx +91 -0
- package/templates/ecommerce/apps/web/src/modules/auth/RegisterForm.tsx +109 -0
- package/templates/ecommerce/apps/web/src/modules/auth/__tests__/ForgotPasswordPage.test.tsx +42 -0
- package/templates/ecommerce/apps/web/src/modules/auth/__tests__/LoginForm.test.tsx +76 -0
- package/templates/ecommerce/apps/web/src/modules/auth/__tests__/RegisterForm.test.tsx +62 -0
- package/templates/ecommerce/apps/web/src/modules/auth/__tests__/ResetPasswordPage.test.tsx +66 -0
- package/templates/ecommerce/apps/web/src/modules/auth/pages/ForgotPasswordPage.tsx +100 -0
- package/templates/ecommerce/apps/web/src/modules/auth/pages/LoginPage.tsx +39 -0
- package/templates/ecommerce/apps/web/src/modules/auth/pages/RegisterPage.tsx +39 -0
- package/templates/ecommerce/apps/web/src/modules/auth/pages/ResetPasswordPage.tsx +110 -0
- package/templates/ecommerce/apps/web/src/modules/auth/useAuthStore.ts +141 -0
- package/templates/ecommerce/apps/web/src/modules/cart/__tests__/CartPage.test.tsx +111 -0
- package/templates/ecommerce/apps/web/src/modules/cart/pages/CartPage.tsx +313 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/__tests__/ProductCard.test.tsx +59 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/__tests__/ProductFilters.test.tsx +56 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/components/ProductCard.tsx +78 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/components/ProductFilters.tsx +104 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/pages/ProductDetailPage.tsx +179 -0
- package/templates/ecommerce/apps/web/src/modules/catalog/pages/ProductListPage.tsx +100 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/__tests__/CheckoutPage.test.tsx +159 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/__tests__/StripePaymentForm.test.tsx +79 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/components/StripePaymentForm.tsx +55 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/hooks/useCheckout.ts +56 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/pages/CheckoutPage.tsx +344 -0
- package/templates/ecommerce/apps/web/src/modules/checkout/pages/CheckoutSuccessPage.tsx +12 -0
- package/templates/ecommerce/apps/web/src/modules/legal/pages/PrivacyPolicyPage.tsx +207 -0
- package/templates/ecommerce/apps/web/src/modules/legal/pages/TermsOfServicePage.tsx +175 -0
- package/templates/ecommerce/apps/web/src/modules/orders/__tests__/OrderDetailPage.test.tsx +75 -0
- package/templates/ecommerce/apps/web/src/modules/orders/__tests__/OrderHistoryPage.test.tsx +87 -0
- package/templates/ecommerce/apps/web/src/modules/orders/pages/OrderDetailPage.tsx +73 -0
- package/templates/ecommerce/apps/web/src/modules/orders/pages/OrderHistoryPage.tsx +97 -0
- package/templates/ecommerce/apps/web/src/modules/profile/__tests__/ProfilePage.test.tsx +150 -0
- package/templates/ecommerce/apps/web/src/modules/profile/pages/ProfilePage.tsx +275 -0
- package/templates/ecommerce/apps/web/src/setupTests.ts +10 -0
- package/templates/ecommerce/apps/web/src/shared/components/CookieConsent.tsx +108 -0
- package/templates/ecommerce/apps/web/src/shared/components/ErrorBoundary.tsx +112 -0
- package/templates/ecommerce/apps/web/src/shared/components/Layout.tsx +143 -0
- package/templates/ecommerce/apps/web/src/shared/components/ProtectedRoute.tsx +21 -0
- package/templates/ecommerce/apps/web/src/shared/config/siteConfig.ts +57 -0
- package/templates/ecommerce/apps/web/src/shared/hooks/usePageTitle.ts +16 -0
- package/templates/ecommerce/apps/web/src/shared/lib/apiFetch.ts +16 -0
- package/templates/ecommerce/apps/web/src/shared/pages/NotFoundPage.tsx +42 -0
- package/templates/ecommerce/apps/web/src/shared/theme/ThemeProvider.tsx +45 -0
- package/templates/ecommerce/apps/web/src/shared/theme/__tests__/ThemeProvider.test.tsx +78 -0
- package/templates/ecommerce/apps/web/src/shared/theme/createTheme.ts +58 -0
- package/templates/ecommerce/apps/web/src/shared/theme/tokens.ts +81 -0
- package/templates/ecommerce/apps/web/src/vite-env.d.ts +1 -0
- package/templates/ecommerce/apps/web/tsconfig.jest.json +12 -0
- package/templates/ecommerce/apps/web/tsconfig.json +25 -0
- package/templates/ecommerce/apps/web/tsconfig.node.json +11 -0
- package/templates/ecommerce/apps/web/vite.config.ts +30 -0
- package/templates/ecommerce/docker-compose.yml +85 -0
- package/templates/ecommerce/package-lock.json +11255 -0
- package/templates/ecommerce/package.json +27 -0
- package/templates/ecommerce/packages/shared-types/package.json +13 -0
- package/templates/ecommerce/packages/shared-types/src/index.ts +3 -0
- package/templates/ecommerce/packages/shared-types/src/theme.ts +44 -0
- package/templates/ecommerce/packages/shared-types/tsconfig.json +11 -0
- package/templates/ecommerce/scripts/customize.sh +201 -0
- package/templates/ecommerce/tsconfig.json +14 -0
- package/templates/java-spring/clean/.gitignore.hbs +72 -0
- package/templates/java-spring/clean/docker-compose.yml.hbs +6 -3
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/application/usecase/PaymentUseCase.java.hbs +21 -17
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/infrastructure/persistence/entity/UserEntity.java.hbs +52 -0
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/infrastructure/persistence/repository/JpaUserRepository.java.hbs +12 -0
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/infrastructure/security/JwtAuthenticationFilter.java.hbs +64 -0
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/infrastructure/security/SecurityConfig.java.hbs +36 -0
- package/templates/java-spring/clean/src/main/java/{{packagePath}}/infrastructure/stripe/StripeGateway.java.hbs +63 -0
- package/templates/java-spring/clean/src/main/resources/application.properties.hbs +6 -7
- package/templates/java-spring/hexagonal/.gitignore.hbs +72 -0
- package/templates/java-spring/hexagonal/docker-compose.yml.hbs +6 -3
- package/templates/java-spring/hexagonal/src/main/java/{{packagePath}}/adapters/outbound/security/JwtFilter.java.hbs +71 -0
- package/templates/java-spring/hexagonal/src/main/java/{{packagePath}}/adapters/outbound/security/SecurityConfig.java.hbs +35 -0
- package/templates/java-spring/hexagonal/src/main/java/{{packagePath}}/core/service/PaymentService.java.hbs +3 -3
- package/templates/java-spring/hexagonal/src/main/resources/application.properties.hbs +4 -4
- package/templates/java-spring/mvc/.gitignore.hbs +72 -0
- package/templates/java-spring/mvc/docker-compose.yml.hbs +6 -3
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/config/SecurityConfig.java.hbs +13 -12
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/controller/AuthController.java.hbs +9 -8
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/controller/PaymentsController.java.hbs +5 -6
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/service/StripeService.java.hbs +3 -3
- package/templates/java-spring/mvc/src/main/resources/application.yml.hbs +29 -26
- package/templates/nestjs/clean/.gitignore.hbs +42 -0
- package/templates/nestjs/clean/Dockerfile.hbs +6 -3
- package/templates/nestjs/clean/docker-compose.yml.hbs +1 -11
- package/templates/nestjs/clean/src/app.module.ts.hbs +2 -1
- package/templates/nestjs/clean/src/application/payment.service.ts.hbs +72 -72
- package/templates/nestjs/clean/src/domain/entities/user.entity.ts.hbs +2 -2
- package/templates/nestjs/clean/src/domain/repositories/user.repository.ts.hbs +2 -2
- package/templates/nestjs/clean/src/infrastructure/database/repositories/prisma.user.repository.ts.hbs +18 -18
- package/templates/nestjs/clean/src/infrastructure/http/health.controller.ts.hbs +9 -0
- package/templates/nestjs/clean/src/main.ts.hbs +1 -4
- package/templates/nestjs/clean/src/payment.module.ts.hbs +12 -12
- package/templates/nestjs/hexagonal/.gitignore.hbs +42 -0
- package/templates/nestjs/hexagonal/Dockerfile.hbs +6 -3
- package/templates/nestjs/hexagonal/docker-compose.yml.hbs +1 -11
- package/templates/nestjs/hexagonal/src/adapters/inbound/health.controller.ts.hbs +9 -0
- package/templates/nestjs/hexagonal/src/app.module.ts.hbs +2 -1
- package/templates/nestjs/hexagonal/src/core/domain/user.entity.ts.hbs +6 -6
- package/templates/nestjs/hexagonal/src/core/ports/ports.ts.hbs +4 -4
- package/templates/nestjs/hexagonal/src/main.ts.hbs +1 -4
- package/templates/nestjs/mvc/.gitignore.hbs +42 -0
- package/templates/nestjs/mvc/Dockerfile.hbs +6 -3
- package/templates/nestjs/mvc/docker-compose.yml.hbs +1 -11
- package/templates/nestjs/mvc/src/auth/auth.controller.ts.hbs +11 -1
- package/templates/nestjs/mvc/src/auth/auth.service.ts.hbs +3 -1
- package/templates/nestjs/mvc/src/controllers/health.controller.ts.hbs +6 -6
- package/templates/nestjs/mvc/src/main.ts.hbs +1 -4
- package/templates/nestjs/mvc/src/models/create-item.dto.ts.hbs +5 -2
- package/templates/nestjs/mvc/src/prisma/prisma.service.ts.hbs +1 -0
- package/templates/nextjs/mvc/.gitignore.hbs +42 -0
- package/templates/nextjs/mvc/Dockerfile.hbs +23 -8
- package/templates/nextjs/mvc/docker-compose.yml.hbs +1 -1
- package/templates/nodejs-express/clean/.gitignore.hbs +42 -0
- package/templates/nodejs-express/clean/Dockerfile.hbs +6 -1
- package/templates/nodejs-express/clean/docker-compose.yml.hbs +2 -2
- package/templates/nodejs-express/clean/package.json.hbs +69 -69
- package/templates/nodejs-express/clean/src/config.ts.hbs +11 -0
- package/templates/nodejs-express/clean/src/domain/entities/User.ts.hbs +46 -8
- package/templates/nodejs-express/hexagonal/.gitignore.hbs +42 -0
- package/templates/nodejs-express/hexagonal/Dockerfile.hbs +1 -1
- package/templates/nodejs-express/hexagonal/docker-compose.yml.hbs +2 -2
- package/templates/nodejs-express/hexagonal/package.json.hbs +69 -69
- package/templates/nodejs-express/hexagonal/src/adapters/inbound/http/PaymentController.ts.hbs +21 -38
- package/templates/nodejs-express/hexagonal/src/adapters/outbound/persistence/prisma.ts.hbs +2 -0
- package/templates/nodejs-express/hexagonal/src/config.ts.hbs +9 -0
- package/templates/nodejs-express/hexagonal/src/core/AuthService.ts.hbs +5 -5
- package/templates/nodejs-express/hexagonal/src/core/PaymentService.ts.hbs +7 -22
- package/templates/nodejs-express/hexagonal/src/core/domain/entities/User.ts.hbs +24 -4
- package/templates/nodejs-express/mvc/.gitignore.hbs +42 -0
- package/templates/nodejs-express/mvc/package.json.hbs +67 -67
- package/templates/python-fastapi/clean/.gitignore.hbs +76 -0
- package/templates/python-fastapi/clean/app/application/services/payment_service.py.hbs +3 -3
- package/templates/python-fastapi/clean/app/config.py.hbs +6 -7
- package/templates/python-fastapi/clean/app/domain/usecases/login_user.py.hbs +15 -0
- package/templates/python-fastapi/clean/app/infrastructure/http/auth_controller.py.hbs +40 -6
- package/templates/python-fastapi/clean/app/infrastructure/http/payment_controller.py.hbs +5 -4
- package/templates/python-fastapi/clean/app/infrastructure/security/jwt.py.hbs +23 -0
- package/templates/python-fastapi/clean/app/main.py.hbs +3 -0
- package/templates/python-fastapi/clean/docker-compose.yml.hbs +5 -12
- package/templates/python-fastapi/clean/requirements.txt.hbs +3 -0
- package/templates/python-fastapi/hexagonal/.gitignore.hbs +76 -0
- package/templates/python-fastapi/hexagonal/app/adapters/inbound/http_adapter.py.hbs +6 -9
- package/templates/python-fastapi/hexagonal/app/adapters/inbound/payment_http_adapter.py.hbs +4 -3
- package/templates/python-fastapi/hexagonal/app/adapters/outbound/stripe_adapter.py.hbs +30 -19
- package/templates/python-fastapi/hexagonal/app/config.py.hbs +14 -4
- package/templates/python-fastapi/hexagonal/app/core/domain/user.py.hbs +3 -1
- package/templates/python-fastapi/hexagonal/app/core/payment_service.py.hbs +28 -18
- package/templates/python-fastapi/hexagonal/app/core/ports/__init__.py.hbs +3 -0
- package/templates/python-fastapi/hexagonal/app/core/ports/user_repository.py.hbs +15 -0
- package/templates/python-fastapi/hexagonal/app/infrastructure/database/session.py.hbs +7 -0
- package/templates/python-fastapi/hexagonal/app/infrastructure/database/user_repository.py.hbs +53 -0
- package/templates/python-fastapi/hexagonal/app/infrastructure/security/__init__.py.hbs +0 -0
- package/templates/python-fastapi/hexagonal/app/infrastructure/security/adapters.py.hbs +23 -0
- package/templates/python-fastapi/hexagonal/app/infrastructure/security/jwt.py.hbs +23 -0
- package/templates/python-fastapi/hexagonal/docker-compose.yml.hbs +5 -12
- package/templates/python-fastapi/hexagonal/requirements.txt.hbs +4 -0
- package/templates/python-fastapi/mvc/.gitignore.hbs +76 -0
- package/templates/python-fastapi/mvc/app/controllers/payments.py.hbs +3 -17
- package/templates/python-fastapi/mvc/app/middleware/security.py.hbs +24 -3
- package/templates/python-fastapi/mvc/app/schemas/item.py.hbs +3 -1
- package/templates/python-fastapi/mvc/docker-compose.yml.hbs +5 -12
- package/templates/python-fastapi/mvc/requirements.txt.hbs +3 -1
- package/templates/nodejs-express/hexagonal/src/adapters/outbound/persistence/prisma.ts +0 -5
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { UserEntity } from '../user.entity';
|
|
2
|
+
|
|
3
|
+
describe('UserEntity — Unit', () => {
|
|
4
|
+
describe('create()', () => {
|
|
5
|
+
it('deve criar um usuário com role CUSTOMER por padrão', () => {
|
|
6
|
+
const user = UserEntity.create({
|
|
7
|
+
name: 'João Silva',
|
|
8
|
+
email: 'joao@email.com',
|
|
9
|
+
passwordHash: 'hashed_password',
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
expect(user.role).toBe('CUSTOMER');
|
|
13
|
+
expect(user.email).toBe('joao@email.com');
|
|
14
|
+
expect(user.name).toBe('João Silva');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('deve aceitar role ADMIN explicitamente', () => {
|
|
18
|
+
const user = UserEntity.create({
|
|
19
|
+
name: 'Admin User',
|
|
20
|
+
email: 'admin@email.com',
|
|
21
|
+
passwordHash: 'hashed_password',
|
|
22
|
+
role: 'ADMIN',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
expect(user.role).toBe('ADMIN');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('deve gerar um id único para cada usuário criado', () => {
|
|
29
|
+
const user1 = UserEntity.create({ name: 'A', email: 'a@a.com', passwordHash: 'h' });
|
|
30
|
+
const user2 = UserEntity.create({ name: 'B', email: 'b@b.com', passwordHash: 'h' });
|
|
31
|
+
|
|
32
|
+
expect(user1.id).not.toBe(user2.id);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('deve lançar erro se email for inválido', () => {
|
|
36
|
+
expect(() =>
|
|
37
|
+
UserEntity.create({ name: 'A', email: 'not-an-email', passwordHash: 'h' }),
|
|
38
|
+
).toThrow();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('deve lançar erro se name for vazio', () => {
|
|
42
|
+
expect(() =>
|
|
43
|
+
UserEntity.create({ name: ' ', email: 'a@a.com', passwordHash: 'h' }),
|
|
44
|
+
).toThrow();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('reconstitute()', () => {
|
|
49
|
+
it('deve reconstituir um usuário existente a partir de dados persistidos', () => {
|
|
50
|
+
const user = UserEntity.reconstitute({
|
|
51
|
+
id: 'existing-id',
|
|
52
|
+
name: 'João',
|
|
53
|
+
email: 'joao@email.com',
|
|
54
|
+
passwordHash: 'hashed',
|
|
55
|
+
role: 'CUSTOMER',
|
|
56
|
+
createdAt: new Date(),
|
|
57
|
+
updatedAt: new Date(),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
expect(user.id).toBe('existing-id');
|
|
61
|
+
expect(user.role).toBe('CUSTOMER');
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('toPublic()', () => {
|
|
66
|
+
it('NÃO deve expor passwordHash no retorno público', () => {
|
|
67
|
+
const user = UserEntity.create({
|
|
68
|
+
name: 'João',
|
|
69
|
+
email: 'joao@email.com',
|
|
70
|
+
passwordHash: 'secret_hash',
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const pub = user.toPublic();
|
|
74
|
+
|
|
75
|
+
expect((pub as Record<string, unknown>)['passwordHash']).toBeUndefined();
|
|
76
|
+
expect(pub.email).toBe('joao@email.com');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
package/templates/ecommerce/apps/api/src/modules/auth/__tests__/user.prisma.repository.test.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { PrismaClient } from '@prisma/client';
|
|
2
|
+
import { PrismaUserRepository } from '../user.prisma.repository';
|
|
3
|
+
import { UserEntity } from '../user.entity';
|
|
4
|
+
|
|
5
|
+
// DATABASE_URL is set to ecommerce_test by setup.db.ts (setupFiles)
|
|
6
|
+
const db = new PrismaClient();
|
|
7
|
+
const repo = new PrismaUserRepository(db);
|
|
8
|
+
|
|
9
|
+
async function cleanDb() {
|
|
10
|
+
await db.$executeRaw`TRUNCATE TABLE password_reset_tokens, users RESTART IDENTITY CASCADE`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
beforeAll(async () => {
|
|
14
|
+
await db.$connect();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterAll(async () => {
|
|
18
|
+
await cleanDb();
|
|
19
|
+
await db.$disconnect();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
beforeEach(async () => {
|
|
23
|
+
await cleanDb();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('PrismaUserRepository', () => {
|
|
27
|
+
it('create: deve persistir e reconstituir UserEntity', async () => {
|
|
28
|
+
const user = UserEntity.create({
|
|
29
|
+
name: 'Alice',
|
|
30
|
+
email: 'alice@example.com',
|
|
31
|
+
passwordHash: '$2b$10$hashedpw',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const saved = await repo.create(user);
|
|
35
|
+
|
|
36
|
+
expect(saved.id).toBe(user.id);
|
|
37
|
+
expect(saved.name).toBe('Alice');
|
|
38
|
+
expect(saved.email).toBe('alice@example.com');
|
|
39
|
+
expect(saved.role).toBe('CUSTOMER');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('findByEmail: deve retornar null para email inexistente', async () => {
|
|
43
|
+
const result = await repo.findByEmail('ghost@example.com');
|
|
44
|
+
expect(result).toBeNull();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('findByEmail: deve retornar entidade para email existente', async () => {
|
|
48
|
+
const user = UserEntity.create({
|
|
49
|
+
name: 'Bob',
|
|
50
|
+
email: 'bob@example.com',
|
|
51
|
+
passwordHash: '$2b$10$hashedpw',
|
|
52
|
+
});
|
|
53
|
+
await repo.create(user);
|
|
54
|
+
|
|
55
|
+
const found = await repo.findByEmail('bob@example.com');
|
|
56
|
+
|
|
57
|
+
expect(found).not.toBeNull();
|
|
58
|
+
expect(found!.email).toBe('bob@example.com');
|
|
59
|
+
expect(found!.id).toBe(user.id);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('findById: deve retornar null para id inexistente', async () => {
|
|
63
|
+
const result = await repo.findById('00000000-0000-0000-0000-000000000000');
|
|
64
|
+
expect(result).toBeNull();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('findById: deve retornar entidade para id existente', async () => {
|
|
68
|
+
const user = UserEntity.create({
|
|
69
|
+
name: 'Carol',
|
|
70
|
+
email: 'carol@example.com',
|
|
71
|
+
passwordHash: '$2b$10$hashedpw',
|
|
72
|
+
});
|
|
73
|
+
await repo.create(user);
|
|
74
|
+
|
|
75
|
+
const found = await repo.findById(user.id);
|
|
76
|
+
|
|
77
|
+
expect(found).not.toBeNull();
|
|
78
|
+
expect(found!.id).toBe(user.id);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('update: deve persistir alterações de role', async () => {
|
|
82
|
+
const user = UserEntity.create({
|
|
83
|
+
name: 'Dave',
|
|
84
|
+
email: 'dave@example.com',
|
|
85
|
+
passwordHash: '$2b$10$hashedpw',
|
|
86
|
+
});
|
|
87
|
+
await repo.create(user);
|
|
88
|
+
|
|
89
|
+
const promoted = user.withRole('ADMIN');
|
|
90
|
+
const updated = await repo.update(promoted);
|
|
91
|
+
|
|
92
|
+
expect(updated.role).toBe('ADMIN');
|
|
93
|
+
|
|
94
|
+
const fetched = await repo.findById(user.id);
|
|
95
|
+
expect(fetched!.role).toBe('ADMIN');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('findAll: deve paginar com cursor', async () => {
|
|
99
|
+
const users = await Promise.all(
|
|
100
|
+
['u1@test.com', 'u2@test.com', 'u3@test.com'].map((email) =>
|
|
101
|
+
repo.create(
|
|
102
|
+
UserEntity.create({ name: email, email, passwordHash: 'pw' }),
|
|
103
|
+
),
|
|
104
|
+
),
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const page1 = await repo.findAll({ limit: 2 });
|
|
108
|
+
expect(page1.items).toHaveLength(2);
|
|
109
|
+
expect(page1.nextCursor).not.toBeNull();
|
|
110
|
+
|
|
111
|
+
const page2 = await repo.findAll({ cursor: page1.nextCursor!, limit: 2 });
|
|
112
|
+
expect(page2.items).toHaveLength(1);
|
|
113
|
+
expect(page2.nextCursor).toBeNull();
|
|
114
|
+
|
|
115
|
+
const allIds = [...page1.items, ...page2.items].map((u) => u.id);
|
|
116
|
+
expect(allIds).toEqual(expect.arrayContaining(users.map((u) => u.id)));
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('findAll: deve filtrar por role', async () => {
|
|
120
|
+
const customer = UserEntity.create({
|
|
121
|
+
name: 'Cust',
|
|
122
|
+
email: 'cust@test.com',
|
|
123
|
+
passwordHash: 'pw',
|
|
124
|
+
});
|
|
125
|
+
const admin = UserEntity.create({
|
|
126
|
+
name: 'Adm',
|
|
127
|
+
email: 'adm@test.com',
|
|
128
|
+
passwordHash: 'pw',
|
|
129
|
+
}).withRole('ADMIN');
|
|
130
|
+
|
|
131
|
+
await repo.create(customer);
|
|
132
|
+
await repo.create(admin);
|
|
133
|
+
|
|
134
|
+
const { items } = await repo.findAll({ role: 'ADMIN' });
|
|
135
|
+
expect(items).toHaveLength(1);
|
|
136
|
+
expect(items[0]!.role).toBe('ADMIN');
|
|
137
|
+
});
|
|
138
|
+
});
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { authService } from './auth.registry';
|
|
4
|
+
|
|
5
|
+
// ── Validation schemas ────────────────────────────────────────────────────────
|
|
6
|
+
const registerSchema = z.object({
|
|
7
|
+
name: z.string().min(1, 'Nome é obrigatório'),
|
|
8
|
+
email: z.string().email('Email inválido'),
|
|
9
|
+
password: z.string().min(8, 'Senha deve ter pelo menos 8 caracteres'),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const loginSchema = z.object({
|
|
13
|
+
email: z.string().email('Email inválido'),
|
|
14
|
+
password: z.string().min(1, 'Senha é obrigatória'),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// ── Cookie helpers ────────────────────────────────────────────────────────────
|
|
18
|
+
const REFRESH_COOKIE = 'refreshToken';
|
|
19
|
+
const COOKIE_OPTIONS = {
|
|
20
|
+
httpOnly: true,
|
|
21
|
+
secure: process.env['NODE_ENV'] === 'production',
|
|
22
|
+
sameSite: 'strict' as const,
|
|
23
|
+
maxAge: 7 * 24 * 60 * 60 * 1000, // 7 days in ms
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// ── Controllers ───────────────────────────────────────────────────────────────
|
|
27
|
+
export async function register(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
28
|
+
const parsed = registerSchema.safeParse(req.body);
|
|
29
|
+
if (!parsed.success) {
|
|
30
|
+
res.status(422).json({ errors: parsed.error.flatten().fieldErrors });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
const user = await authService.register(parsed.data);
|
|
36
|
+
|
|
37
|
+
// Generate tokens right away so the client is logged in after registration
|
|
38
|
+
const loginResult = await authService.login({
|
|
39
|
+
email: parsed.data.email,
|
|
40
|
+
password: parsed.data.password,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
res.cookie(REFRESH_COOKIE, loginResult.refreshToken, COOKIE_OPTIONS);
|
|
44
|
+
res.status(201).json({ user, accessToken: loginResult.accessToken });
|
|
45
|
+
} catch (err) {
|
|
46
|
+
next(err);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function login(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
51
|
+
const parsed = loginSchema.safeParse(req.body);
|
|
52
|
+
if (!parsed.success) {
|
|
53
|
+
res.status(422).json({ errors: parsed.error.flatten().fieldErrors });
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
const { accessToken, refreshToken, user } = await authService.login(parsed.data);
|
|
59
|
+
|
|
60
|
+
res.cookie(REFRESH_COOKIE, refreshToken, COOKIE_OPTIONS);
|
|
61
|
+
res.status(200).json({ accessToken, user });
|
|
62
|
+
} catch (err) {
|
|
63
|
+
next(err);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function refresh(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
68
|
+
const token = (req.cookies as Record<string, string | undefined>)[REFRESH_COOKIE];
|
|
69
|
+
if (!token) {
|
|
70
|
+
res.status(401).json({ error: 'Refresh token não encontrado' });
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const { accessToken } = await authService.refreshToken(token);
|
|
76
|
+
res.status(200).json({ accessToken });
|
|
77
|
+
} catch (err) {
|
|
78
|
+
next(err);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function logout(req: Request, res: Response, next: NextFunction): Promise<void> {
|
|
83
|
+
const token = (req.cookies as Record<string, string | undefined>)[REFRESH_COOKIE];
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
if (token) {
|
|
87
|
+
await authService.logout(token);
|
|
88
|
+
}
|
|
89
|
+
res.clearCookie(REFRESH_COOKIE);
|
|
90
|
+
res.status(204).send();
|
|
91
|
+
} catch (err) {
|
|
92
|
+
next(err);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function me(req: Request, res: Response): void {
|
|
97
|
+
res.status(200).json(req.user);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function adminTest(_req: Request, res: Response): void {
|
|
101
|
+
res.status(200).json({ message: 'Admin access granted' });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function forgotPassword(
|
|
105
|
+
req: Request,
|
|
106
|
+
res: Response,
|
|
107
|
+
next: NextFunction,
|
|
108
|
+
): Promise<void> {
|
|
109
|
+
const parsed = z
|
|
110
|
+
.object({ email: z.string().email('Email inválido') })
|
|
111
|
+
.safeParse(req.body);
|
|
112
|
+
if (!parsed.success) {
|
|
113
|
+
res.status(422).json({ errors: parsed.error.flatten().fieldErrors });
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
await authService.forgotPassword({ email: parsed.data.email });
|
|
118
|
+
// Always respond with the same message to prevent user enumeration
|
|
119
|
+
res
|
|
120
|
+
.status(200)
|
|
121
|
+
.json({ message: 'Se o email existir, você receberá as instruções em breve.' });
|
|
122
|
+
} catch (err) {
|
|
123
|
+
next(err);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export async function resetPassword(
|
|
128
|
+
req: Request,
|
|
129
|
+
res: Response,
|
|
130
|
+
next: NextFunction,
|
|
131
|
+
): Promise<void> {
|
|
132
|
+
const parsed = z
|
|
133
|
+
.object({
|
|
134
|
+
token: z.string().min(1, 'Token é obrigatório'),
|
|
135
|
+
newPassword: z.string().min(6, 'A senha deve ter pelo menos 6 caracteres'),
|
|
136
|
+
})
|
|
137
|
+
.safeParse(req.body);
|
|
138
|
+
if (!parsed.success) {
|
|
139
|
+
res.status(422).json({ errors: parsed.error.flatten().fieldErrors });
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
await authService.resetPassword(parsed.data);
|
|
144
|
+
res.status(200).json({ message: 'Senha redefinida com sucesso.' });
|
|
145
|
+
} catch (err) {
|
|
146
|
+
next(err);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../infrastructure/config/registry/auth.registry';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import { authenticate } from '../../shared/middlewares/authenticate';
|
|
3
|
+
import { authorize } from '../../shared/middlewares/authorize';
|
|
4
|
+
import * as authController from './auth.controller';
|
|
5
|
+
|
|
6
|
+
const router = Router();
|
|
7
|
+
|
|
8
|
+
router.post('/register', authController.register);
|
|
9
|
+
router.post('/login', authController.login);
|
|
10
|
+
router.post('/refresh', authController.refresh);
|
|
11
|
+
router.post('/logout', authController.logout);
|
|
12
|
+
router.get('/me', authenticate, authController.me);
|
|
13
|
+
router.get('/admin-test', authenticate, authorize('ADMIN'), authController.adminTest);
|
|
14
|
+
router.post('/forgot-password', authController.forgotPassword);
|
|
15
|
+
router.post('/reset-password', authController.resetPassword);
|
|
16
|
+
|
|
17
|
+
export default router;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../application/auth/auth.service';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../infrastructure/services/token/redis.token.blacklist';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../domain/auth/user.entity';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../infrastructure/persistence/prisma/auth/user.prisma.repository';
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { CartEntity } from '../cart.entity';
|
|
2
|
+
import { CouponEntity } from '../coupon.entity';
|
|
3
|
+
|
|
4
|
+
// ── Helpers ───────────────────────────────────────────────────────────────────
|
|
5
|
+
function makeItem(overrides: Partial<{
|
|
6
|
+
variantId: string;
|
|
7
|
+
productId: string;
|
|
8
|
+
name: string;
|
|
9
|
+
sku: string;
|
|
10
|
+
price: number;
|
|
11
|
+
qty: number;
|
|
12
|
+
image: string | null;
|
|
13
|
+
}> = {}) {
|
|
14
|
+
return {
|
|
15
|
+
variantId: overrides.variantId ?? 'var-1',
|
|
16
|
+
productId: overrides.productId ?? 'prod-1',
|
|
17
|
+
name: overrides.name ?? 'Camiseta Básica',
|
|
18
|
+
sku: overrides.sku ?? 'CAM-P',
|
|
19
|
+
price: overrides.price ?? 100,
|
|
20
|
+
qty: overrides.qty ?? 1,
|
|
21
|
+
image: overrides.image ?? null,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Coupon helpers
|
|
26
|
+
const percentCoupon = CouponEntity.reconstitute({
|
|
27
|
+
id: 'coup-1',
|
|
28
|
+
code: 'PROMO10',
|
|
29
|
+
discountType: 'percent',
|
|
30
|
+
discountValue: 10, // 10%
|
|
31
|
+
minOrderValue: 0,
|
|
32
|
+
usageLimit: null,
|
|
33
|
+
usageCount: 0,
|
|
34
|
+
expiresAt: null,
|
|
35
|
+
createdAt: new Date(),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const fixedCoupon = CouponEntity.reconstitute({
|
|
39
|
+
id: 'coup-2',
|
|
40
|
+
code: 'FIXO20',
|
|
41
|
+
discountType: 'fixed',
|
|
42
|
+
discountValue: 20,
|
|
43
|
+
minOrderValue: 0,
|
|
44
|
+
usageLimit: null,
|
|
45
|
+
usageCount: 0,
|
|
46
|
+
expiresAt: null,
|
|
47
|
+
createdAt: new Date(),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const expiredCoupon = CouponEntity.reconstitute({
|
|
51
|
+
id: 'coup-3',
|
|
52
|
+
code: 'OLD',
|
|
53
|
+
discountType: 'percent',
|
|
54
|
+
discountValue: 5,
|
|
55
|
+
minOrderValue: 0,
|
|
56
|
+
usageLimit: null,
|
|
57
|
+
usageCount: 0,
|
|
58
|
+
expiresAt: new Date('2020-01-01'), // past
|
|
59
|
+
createdAt: new Date(),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const highMinCoupon = CouponEntity.reconstitute({
|
|
63
|
+
id: 'coup-4',
|
|
64
|
+
code: 'BIG500',
|
|
65
|
+
discountType: 'percent',
|
|
66
|
+
discountValue: 20,
|
|
67
|
+
minOrderValue: 500,
|
|
68
|
+
usageLimit: null,
|
|
69
|
+
usageCount: 0,
|
|
70
|
+
expiresAt: null,
|
|
71
|
+
createdAt: new Date(),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('CartEntity — Unit (pure domain)', () => {
|
|
75
|
+
let emptyCart: CartEntity;
|
|
76
|
+
|
|
77
|
+
beforeEach(() => {
|
|
78
|
+
emptyCart = CartEntity.create('user-1');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('deve adicionar item ao carrinho', () => {
|
|
82
|
+
const cart = emptyCart.addItem(makeItem());
|
|
83
|
+
expect(cart.items).toHaveLength(1);
|
|
84
|
+
expect(cart.items[0]!.variantId).toBe('var-1');
|
|
85
|
+
expect(cart.items[0]!.qty).toBe(1);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('deve incrementar quantidade se produto já existir', () => {
|
|
89
|
+
const cart = emptyCart.addItem(makeItem({ qty: 2 })).addItem(makeItem({ qty: 3 }));
|
|
90
|
+
expect(cart.items).toHaveLength(1);
|
|
91
|
+
expect(cart.items[0]!.qty).toBe(5);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('deve remover item pelo variantId', () => {
|
|
95
|
+
const cart = emptyCart
|
|
96
|
+
.addItem(makeItem({ variantId: 'var-1' }))
|
|
97
|
+
.addItem(makeItem({ variantId: 'var-2', sku: 'CAM-G' }))
|
|
98
|
+
.removeItem('var-1');
|
|
99
|
+
expect(cart.items).toHaveLength(1);
|
|
100
|
+
expect(cart.items[0]!.variantId).toBe('var-2');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('deve calcular subtotal corretamente', () => {
|
|
104
|
+
const cart = emptyCart
|
|
105
|
+
.addItem(makeItem({ price: 100, qty: 2 }))
|
|
106
|
+
.addItem(makeItem({ variantId: 'var-2', sku: 'CALCA-M', price: 150, qty: 1 }));
|
|
107
|
+
expect(cart.subtotal).toBe(350);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('deve calcular total com desconto de cupom percentual', () => {
|
|
111
|
+
const cart = emptyCart
|
|
112
|
+
.addItem(makeItem({ price: 200, qty: 1 }))
|
|
113
|
+
.applyCoupon(percentCoupon); // 10% de 200 = 20
|
|
114
|
+
expect(cart.discount).toBe(20);
|
|
115
|
+
expect(cart.total).toBe(180);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('deve calcular total com desconto de cupom de valor fixo', () => {
|
|
119
|
+
const cart = emptyCart
|
|
120
|
+
.addItem(makeItem({ price: 200, qty: 1 }))
|
|
121
|
+
.applyCoupon(fixedCoupon); // R$20 fixo
|
|
122
|
+
expect(cart.discount).toBe(20);
|
|
123
|
+
expect(cart.total).toBe(180);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('deve rejeitar cupom expirado', () => {
|
|
127
|
+
expect(() => emptyCart.addItem(makeItem({ price: 100 })).applyCoupon(expiredCoupon))
|
|
128
|
+
.toThrow('Cupom expirado');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('deve rejeitar cupom com valor mínimo não atingido', () => {
|
|
132
|
+
expect(() => emptyCart.addItem(makeItem({ price: 100 })).applyCoupon(highMinCoupon))
|
|
133
|
+
.toThrow('Valor mínimo');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('deve ser imutável — cada operação retorna novo Cart', () => {
|
|
137
|
+
const cart1 = emptyCart.addItem(makeItem());
|
|
138
|
+
const cart2 = cart1.addItem(makeItem({ variantId: 'var-2', sku: 'X' }));
|
|
139
|
+
expect(cart1.items).toHaveLength(1);
|
|
140
|
+
expect(cart2.items).toHaveLength(2);
|
|
141
|
+
// original not mutated
|
|
142
|
+
expect(emptyCart.items).toHaveLength(0);
|
|
143
|
+
});
|
|
144
|
+
});
|