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
package/templates/ecommerce/apps/api/src/modules/payment/__tests__/stripe-webhook.unit.test.ts
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StripeWebhookHandler — Unit Tests
|
|
3
|
+
* Stripe SDK mocked; IOrderRepository mocked; ICouponRepository mocked.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
jest.mock('stripe');
|
|
7
|
+
|
|
8
|
+
import Stripe from 'stripe';
|
|
9
|
+
import { StripeWebhookHandler } from '../stripe-webhook.handler';
|
|
10
|
+
import { IOrderRepository } from '../../checkout/order.repository';
|
|
11
|
+
import { ICouponRepository } from '../../cart/coupon.repository';
|
|
12
|
+
|
|
13
|
+
const mockConstructEvent = jest.fn();
|
|
14
|
+
|
|
15
|
+
(Stripe as jest.MockedClass<typeof Stripe>).mockImplementation(() => ({
|
|
16
|
+
webhooks: {
|
|
17
|
+
constructEvent: mockConstructEvent,
|
|
18
|
+
},
|
|
19
|
+
} as unknown as Stripe));
|
|
20
|
+
|
|
21
|
+
function makeOrderRepo(): jest.Mocked<IOrderRepository> {
|
|
22
|
+
return {
|
|
23
|
+
findById: jest.fn(),
|
|
24
|
+
findByPaymentIntentId: jest.fn(),
|
|
25
|
+
findByUserId: jest.fn(),
|
|
26
|
+
findAll: jest.fn(),
|
|
27
|
+
create: jest.fn(),
|
|
28
|
+
update: jest.fn(),
|
|
29
|
+
} as jest.Mocked<IOrderRepository>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function makeCouponRepo(): jest.Mocked<ICouponRepository> {
|
|
33
|
+
return {
|
|
34
|
+
findByCode: jest.fn(),
|
|
35
|
+
findById: jest.fn(),
|
|
36
|
+
save: jest.fn(),
|
|
37
|
+
findAll: jest.fn(),
|
|
38
|
+
deleteById: jest.fn(),
|
|
39
|
+
incrementUsage: jest.fn(),
|
|
40
|
+
} as jest.Mocked<ICouponRepository>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function makeSucceededEvent(piId = 'pi_123') {
|
|
44
|
+
return {
|
|
45
|
+
id: `evt_${piId}`,
|
|
46
|
+
type: 'payment_intent.succeeded',
|
|
47
|
+
data: { object: { id: piId } as Stripe.PaymentIntent },
|
|
48
|
+
} as Stripe.Event;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function makeFailedEvent(piId = 'pi_456') {
|
|
52
|
+
return {
|
|
53
|
+
id: `evt_${piId}`,
|
|
54
|
+
type: 'payment_intent.payment_failed',
|
|
55
|
+
data: { object: { id: piId } as Stripe.PaymentIntent },
|
|
56
|
+
} as Stripe.Event;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
describe('StripeWebhookHandler — Unit', () => {
|
|
60
|
+
let orderRepo: jest.Mocked<IOrderRepository>;
|
|
61
|
+
let couponRepo: jest.Mocked<ICouponRepository>;
|
|
62
|
+
let handler: StripeWebhookHandler;
|
|
63
|
+
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
jest.clearAllMocks();
|
|
66
|
+
orderRepo = makeOrderRepo();
|
|
67
|
+
couponRepo = makeCouponRepo();
|
|
68
|
+
handler = new StripeWebhookHandler('sk_test_fake', 'whsec_fake', orderRepo, couponRepo);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('deve processar evento payment_intent.succeeded e atualizar pedido para PAID', async () => {
|
|
72
|
+
const event = makeSucceededEvent('pi_123');
|
|
73
|
+
mockConstructEvent.mockReturnValue(event);
|
|
74
|
+
|
|
75
|
+
const { OrderEntity } = await import('../../checkout/order.entity');
|
|
76
|
+
const order = OrderEntity.create({
|
|
77
|
+
userId: 'user-1',
|
|
78
|
+
items: [{ id: 'item-1', variantId: 'v1', productId: 'p1', name: 'T-shirt', sku: 'TS-P', price: 99.9, qty: 1, image: null }],
|
|
79
|
+
subtotal: 99.9,
|
|
80
|
+
discount: 0,
|
|
81
|
+
shippingCost: 18.5,
|
|
82
|
+
tax: 0,
|
|
83
|
+
total: 118.4,
|
|
84
|
+
couponCode: null,
|
|
85
|
+
paymentIntentId: 'pi_123',
|
|
86
|
+
shippingAddress: null,
|
|
87
|
+
});
|
|
88
|
+
orderRepo.findByPaymentIntentId.mockResolvedValue(order);
|
|
89
|
+
orderRepo.update.mockImplementation(async (o) => o);
|
|
90
|
+
|
|
91
|
+
await handler.handleEvent(JSON.stringify({}), 'sig');
|
|
92
|
+
|
|
93
|
+
expect(orderRepo.update).toHaveBeenCalled();
|
|
94
|
+
const updated = orderRepo.update.mock.calls[0]![0];
|
|
95
|
+
expect(updated.status).toBe('PAID');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('deve processar evento payment_intent.payment_failed e atualizar pedido para FAILED', async () => {
|
|
99
|
+
const event = makeFailedEvent('pi_456');
|
|
100
|
+
mockConstructEvent.mockReturnValue(event);
|
|
101
|
+
|
|
102
|
+
const { OrderEntity } = await import('../../checkout/order.entity');
|
|
103
|
+
const order = OrderEntity.create({
|
|
104
|
+
userId: 'user-1',
|
|
105
|
+
items: [],
|
|
106
|
+
subtotal: 50,
|
|
107
|
+
discount: 0,
|
|
108
|
+
shippingCost: 0,
|
|
109
|
+
tax: 0,
|
|
110
|
+
total: 50,
|
|
111
|
+
couponCode: null,
|
|
112
|
+
paymentIntentId: 'pi_456',
|
|
113
|
+
shippingAddress: null,
|
|
114
|
+
});
|
|
115
|
+
orderRepo.findByPaymentIntentId.mockResolvedValue(order);
|
|
116
|
+
orderRepo.update.mockImplementation(async (o) => o);
|
|
117
|
+
|
|
118
|
+
await handler.handleEvent(JSON.stringify({}), 'sig');
|
|
119
|
+
|
|
120
|
+
const updated = orderRepo.update.mock.calls[0]![0];
|
|
121
|
+
expect(updated.status).toBe('FAILED');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('deve rejeitar webhook com assinatura inválida (400)', async () => {
|
|
125
|
+
mockConstructEvent.mockImplementation(() => {
|
|
126
|
+
const err = new Error('No signatures found matching the expected signature');
|
|
127
|
+
Object.assign(err, { type: 'StripeSignatureVerificationError' });
|
|
128
|
+
throw err;
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
await expect(handler.handleEvent('{}', 'bad-sig')).rejects.toThrow('assinatura');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('deve ser idempotente — processar o mesmo evento duas vezes não duplica ação', async () => {
|
|
135
|
+
const event = makeSucceededEvent('pi_789');
|
|
136
|
+
mockConstructEvent.mockReturnValue(event);
|
|
137
|
+
|
|
138
|
+
const { OrderEntity } = await import('../../checkout/order.entity');
|
|
139
|
+
const paid = OrderEntity.create({
|
|
140
|
+
userId: 'u1', items: [], subtotal: 10, discount: 0, shippingCost: 0, tax: 0, total: 10,
|
|
141
|
+
couponCode: null, paymentIntentId: 'pi_789', shippingAddress: null,
|
|
142
|
+
}).pay();
|
|
143
|
+
orderRepo.findByPaymentIntentId.mockResolvedValue(paid);
|
|
144
|
+
|
|
145
|
+
await handler.handleEvent(JSON.stringify({}), 'sig');
|
|
146
|
+
|
|
147
|
+
// Already PAID → update should NOT have been called again
|
|
148
|
+
expect(orderRepo.update).not.toHaveBeenCalled();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('deve ignorar eventos desconhecidos sem lançar erro', async () => {
|
|
152
|
+
const event = { id: 'evt_x', type: 'customer.created', data: { object: {} } } as Stripe.Event;
|
|
153
|
+
mockConstructEvent.mockReturnValue(event);
|
|
154
|
+
|
|
155
|
+
await expect(handler.handleEvent(JSON.stringify({}), 'sig')).resolves.toBeUndefined();
|
|
156
|
+
expect(orderRepo.update).not.toHaveBeenCalled();
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe('StripeWebhookHandler — usageCount', () => {
|
|
161
|
+
let orderRepo: jest.Mocked<IOrderRepository>;
|
|
162
|
+
let couponRepo: jest.Mocked<ICouponRepository>;
|
|
163
|
+
let handler: StripeWebhookHandler;
|
|
164
|
+
|
|
165
|
+
beforeEach(() => {
|
|
166
|
+
jest.clearAllMocks();
|
|
167
|
+
orderRepo = makeOrderRepo();
|
|
168
|
+
couponRepo = makeCouponRepo();
|
|
169
|
+
handler = new StripeWebhookHandler('sk_test_fake', 'whsec_fake', orderRepo, couponRepo);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('incrementa usageCount do cupom quando payment_intent.succeeded e pedido tem couponCode', async () => {
|
|
173
|
+
const event = makeSucceededEvent('pi_coupon1');
|
|
174
|
+
mockConstructEvent.mockReturnValue(event);
|
|
175
|
+
|
|
176
|
+
const { OrderEntity } = await import('../../checkout/order.entity');
|
|
177
|
+
const order = OrderEntity.create({
|
|
178
|
+
userId: 'u1',
|
|
179
|
+
items: [],
|
|
180
|
+
subtotal: 100,
|
|
181
|
+
discount: 10,
|
|
182
|
+
shippingCost: 0,
|
|
183
|
+
tax: 0,
|
|
184
|
+
total: 90,
|
|
185
|
+
couponCode: 'PROMO10',
|
|
186
|
+
paymentIntentId: 'pi_coupon1',
|
|
187
|
+
shippingAddress: null,
|
|
188
|
+
});
|
|
189
|
+
orderRepo.findByPaymentIntentId.mockResolvedValue(order);
|
|
190
|
+
orderRepo.update.mockImplementation(async (o) => o);
|
|
191
|
+
couponRepo.incrementUsage.mockResolvedValue(undefined);
|
|
192
|
+
|
|
193
|
+
await handler.handleEvent(JSON.stringify({}), 'sig');
|
|
194
|
+
|
|
195
|
+
expect(couponRepo.incrementUsage).toHaveBeenCalledWith('PROMO10');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('não falha se pedido não tiver cupom (couponCode null)', async () => {
|
|
199
|
+
const event = makeSucceededEvent('pi_nocoupon');
|
|
200
|
+
mockConstructEvent.mockReturnValue(event);
|
|
201
|
+
|
|
202
|
+
const { OrderEntity } = await import('../../checkout/order.entity');
|
|
203
|
+
const order = OrderEntity.create({
|
|
204
|
+
userId: 'u1',
|
|
205
|
+
items: [],
|
|
206
|
+
subtotal: 50,
|
|
207
|
+
discount: 0,
|
|
208
|
+
shippingCost: 0,
|
|
209
|
+
tax: 0,
|
|
210
|
+
total: 50,
|
|
211
|
+
couponCode: null,
|
|
212
|
+
paymentIntentId: 'pi_nocoupon',
|
|
213
|
+
shippingAddress: null,
|
|
214
|
+
});
|
|
215
|
+
orderRepo.findByPaymentIntentId.mockResolvedValue(order);
|
|
216
|
+
orderRepo.update.mockImplementation(async (o) => o);
|
|
217
|
+
|
|
218
|
+
await expect(handler.handleEvent(JSON.stringify({}), 'sig')).resolves.toBeUndefined();
|
|
219
|
+
expect(couponRepo.incrementUsage).not.toHaveBeenCalled();
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// ── Phase 14 — Email transacional no webhook ─────────────────────────────────
|
|
224
|
+
import { IEmailService } from '../../../shared/infra/email/IEmailService';
|
|
225
|
+
import { IUserRepository } from '../../auth/user.repository';
|
|
226
|
+
|
|
227
|
+
function makeEmailService(): jest.Mocked<IEmailService> {
|
|
228
|
+
return { send: jest.fn().mockResolvedValue(undefined) };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function makeUserRepo(): jest.Mocked<IUserRepository> {
|
|
232
|
+
return {
|
|
233
|
+
findByEmail: jest.fn(),
|
|
234
|
+
findById: jest.fn(),
|
|
235
|
+
create: jest.fn(),
|
|
236
|
+
update: jest.fn(),
|
|
237
|
+
delete: jest.fn(),
|
|
238
|
+
findAll: jest.fn(),
|
|
239
|
+
} as jest.Mocked<IUserRepository>;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
describe('StripeWebhookHandler — emails (Phase 14)', () => {
|
|
243
|
+
let orderRepo: jest.Mocked<IOrderRepository>;
|
|
244
|
+
let couponRepo: jest.Mocked<ICouponRepository>;
|
|
245
|
+
let emailService: jest.Mocked<IEmailService>;
|
|
246
|
+
let userRepo: jest.Mocked<IUserRepository>;
|
|
247
|
+
let handler: StripeWebhookHandler;
|
|
248
|
+
|
|
249
|
+
beforeEach(async () => {
|
|
250
|
+
jest.clearAllMocks();
|
|
251
|
+
orderRepo = makeOrderRepo();
|
|
252
|
+
couponRepo = makeCouponRepo();
|
|
253
|
+
emailService = makeEmailService();
|
|
254
|
+
userRepo = makeUserRepo();
|
|
255
|
+
handler = new StripeWebhookHandler(
|
|
256
|
+
'sk_test_fake',
|
|
257
|
+
'whsec_fake',
|
|
258
|
+
orderRepo,
|
|
259
|
+
couponRepo,
|
|
260
|
+
emailService,
|
|
261
|
+
userRepo,
|
|
262
|
+
);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('chama emailService.send() com subject "Pedido confirmado" em payment_intent.succeeded', async () => {
|
|
266
|
+
const event = makeSucceededEvent('pi_email1');
|
|
267
|
+
mockConstructEvent.mockReturnValue(event);
|
|
268
|
+
|
|
269
|
+
const { OrderEntity } = await import('../../checkout/order.entity');
|
|
270
|
+
const order = OrderEntity.create({
|
|
271
|
+
userId: 'user-email-1',
|
|
272
|
+
items: [{ id: 'i1', variantId: 'v1', productId: 'p1', name: 'Camiseta', sku: 'CAM-P', price: 99.9, qty: 2, image: null }],
|
|
273
|
+
subtotal: 199.8,
|
|
274
|
+
discount: 0,
|
|
275
|
+
shippingCost: 15,
|
|
276
|
+
tax: 0,
|
|
277
|
+
total: 214.8,
|
|
278
|
+
couponCode: null,
|
|
279
|
+
paymentIntentId: 'pi_email1',
|
|
280
|
+
shippingAddress: null,
|
|
281
|
+
});
|
|
282
|
+
orderRepo.findByPaymentIntentId.mockResolvedValue(order);
|
|
283
|
+
orderRepo.update.mockImplementation(async (o) => o);
|
|
284
|
+
|
|
285
|
+
const { UserEntity } = await import('../../auth/user.entity');
|
|
286
|
+
const user = UserEntity.create({ name: 'Cliente', email: 'cliente@test.com', passwordHash: 'h', role: 'CUSTOMER' });
|
|
287
|
+
userRepo.findById.mockResolvedValue(user);
|
|
288
|
+
|
|
289
|
+
await handler.handleEvent(JSON.stringify({}), 'sig');
|
|
290
|
+
|
|
291
|
+
expect(emailService.send).toHaveBeenCalledWith(
|
|
292
|
+
'cliente@test.com',
|
|
293
|
+
expect.stringContaining('confirmado'),
|
|
294
|
+
expect.any(String),
|
|
295
|
+
);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('não falha se emailService.send() lançar (erro silencioso para não bloquear webhook)', async () => {
|
|
299
|
+
const event = makeSucceededEvent('pi_email_err');
|
|
300
|
+
mockConstructEvent.mockReturnValue(event);
|
|
301
|
+
|
|
302
|
+
const { OrderEntity } = await import('../../checkout/order.entity');
|
|
303
|
+
const order = OrderEntity.create({
|
|
304
|
+
userId: 'user-email-2',
|
|
305
|
+
items: [],
|
|
306
|
+
subtotal: 50,
|
|
307
|
+
discount: 0,
|
|
308
|
+
shippingCost: 0,
|
|
309
|
+
tax: 0,
|
|
310
|
+
total: 50,
|
|
311
|
+
couponCode: null,
|
|
312
|
+
paymentIntentId: 'pi_email_err',
|
|
313
|
+
shippingAddress: null,
|
|
314
|
+
});
|
|
315
|
+
orderRepo.findByPaymentIntentId.mockResolvedValue(order);
|
|
316
|
+
orderRepo.update.mockImplementation(async (o) => o);
|
|
317
|
+
|
|
318
|
+
const { UserEntity } = await import('../../auth/user.entity');
|
|
319
|
+
const user = UserEntity.create({ name: 'Cliente', email: 'err@test.com', passwordHash: 'h', role: 'CUSTOMER' });
|
|
320
|
+
userRepo.findById.mockResolvedValue(user);
|
|
321
|
+
|
|
322
|
+
// email throws
|
|
323
|
+
emailService.send.mockRejectedValue(new Error('SMTP down'));
|
|
324
|
+
|
|
325
|
+
// handler must NOT throw
|
|
326
|
+
await expect(handler.handleEvent(JSON.stringify({}), 'sig')).resolves.toBeUndefined();
|
|
327
|
+
// order must still have been updated
|
|
328
|
+
expect(orderRepo.update).toHaveBeenCalled();
|
|
329
|
+
});
|
|
330
|
+
});
|
package/templates/ecommerce/apps/api/src/modules/payment/__tests__/stripe.adapter.unit.test.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StripeAdapter — Unit Tests
|
|
3
|
+
* Stripe SDK is mocked so these tests run without any network access.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Mock must be hoisted before import
|
|
7
|
+
jest.mock('stripe');
|
|
8
|
+
|
|
9
|
+
import Stripe from 'stripe';
|
|
10
|
+
import { StripeAdapter } from '../adapters/stripe.adapter';
|
|
11
|
+
import { PaymentError } from '../payment.port';
|
|
12
|
+
|
|
13
|
+
const mockCreate = jest.fn();
|
|
14
|
+
const mockConfirm = jest.fn();
|
|
15
|
+
|
|
16
|
+
// Mock the Stripe constructor to return a controlled instance
|
|
17
|
+
(Stripe as jest.MockedClass<typeof Stripe>).mockImplementation(() => ({
|
|
18
|
+
paymentIntents: {
|
|
19
|
+
create: mockCreate,
|
|
20
|
+
confirm: mockConfirm,
|
|
21
|
+
},
|
|
22
|
+
} as unknown as Stripe));
|
|
23
|
+
|
|
24
|
+
describe('StripeAdapter — Unit', () => {
|
|
25
|
+
let adapter: StripeAdapter;
|
|
26
|
+
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
jest.clearAllMocks();
|
|
29
|
+
adapter = new StripeAdapter('sk_test_fake');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('deve criar PaymentIntent com amount e currency corretos', async () => {
|
|
33
|
+
mockCreate.mockResolvedValue({ id: 'pi_1', client_secret: 'pi_1_secret_abc' });
|
|
34
|
+
|
|
35
|
+
await adapter.createPaymentIntent(199.9, 'brl', { orderId: 'ord-1' });
|
|
36
|
+
|
|
37
|
+
expect(mockCreate).toHaveBeenCalledWith(
|
|
38
|
+
expect.objectContaining({ amount: 19990, currency: 'brl' }),
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('deve retornar clientSecret do PaymentIntent criado', async () => {
|
|
43
|
+
mockCreate.mockResolvedValue({ id: 'pi_1', client_secret: 'pi_1_secret_abc' });
|
|
44
|
+
|
|
45
|
+
const result = await adapter.createPaymentIntent(100, 'brl', {});
|
|
46
|
+
|
|
47
|
+
expect(result.clientSecret).toBe('pi_1_secret_abc');
|
|
48
|
+
expect(result.id).toBe('pi_1');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('deve converter valor de reais para centavos (R$10,00 → 1000)', async () => {
|
|
52
|
+
mockCreate.mockResolvedValue({ id: 'pi_2', client_secret: 'secret' });
|
|
53
|
+
|
|
54
|
+
await adapter.createPaymentIntent(10, 'brl', {});
|
|
55
|
+
|
|
56
|
+
expect(mockCreate).toHaveBeenCalledWith(
|
|
57
|
+
expect.objectContaining({ amount: 1000 }),
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('deve lançar PaymentError se Stripe retornar erro de cartão recusado', async () => {
|
|
62
|
+
const stripeErr = Object.assign(new Error('Your card was declined.'), {
|
|
63
|
+
type: 'StripeCardError',
|
|
64
|
+
code: 'card_declined',
|
|
65
|
+
});
|
|
66
|
+
mockCreate.mockRejectedValue(stripeErr);
|
|
67
|
+
|
|
68
|
+
await expect(adapter.createPaymentIntent(100, 'brl', {})).rejects.toThrow(PaymentError);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('deve lançar PaymentError se Stripe retornar erro de autenticação', async () => {
|
|
72
|
+
const stripeErr = Object.assign(new Error('No such API key.'), {
|
|
73
|
+
type: 'StripeAuthenticationError',
|
|
74
|
+
});
|
|
75
|
+
mockCreate.mockRejectedValue(stripeErr);
|
|
76
|
+
|
|
77
|
+
await expect(adapter.createPaymentIntent(100, 'brl', {})).rejects.toThrow(PaymentError);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('deve construir instância com secretKey fornecida', () => {
|
|
81
|
+
const adapterWithKey = new StripeAdapter('sk_test_mykey');
|
|
82
|
+
expect(adapterWithKey).toBeInstanceOf(StripeAdapter);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../infrastructure/services/payment/stripe.adapter';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../application/ports/payment.port';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../infrastructure/services/payment/stripe-webhook.handler';
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import request from 'supertest';
|
|
2
|
+
import app from '../../../app';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Integration tests for Profile routes (/api/me).
|
|
6
|
+
* Uses the full Express app with in-memory repositories (NODE_ENV=test-inmemory).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
10
|
+
const VALID_USER = {
|
|
11
|
+
name: 'Profile User',
|
|
12
|
+
email: 'profile@email.com',
|
|
13
|
+
password: 'senha1234',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
async function registerAndLogin(user = VALID_USER) {
|
|
17
|
+
await request(app).post('/api/auth/register').send(user);
|
|
18
|
+
const res = await request(app).post('/api/auth/login').send({
|
|
19
|
+
email: user.email,
|
|
20
|
+
password: user.password,
|
|
21
|
+
});
|
|
22
|
+
return (res.body as { accessToken: string }).accessToken;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// ── Tests ────────────────────────────────────────────────────────────────────
|
|
26
|
+
describe('Profile Routes — Integration', () => {
|
|
27
|
+
// ── GET /api/me ───────────────────────────────────────────────────────────
|
|
28
|
+
describe('GET /api/me', () => {
|
|
29
|
+
it('200: deve retornar perfil do usuário autenticado', async () => {
|
|
30
|
+
const token = await registerAndLogin();
|
|
31
|
+
|
|
32
|
+
const res = await request(app)
|
|
33
|
+
.get('/api/me')
|
|
34
|
+
.set('Authorization', `Bearer ${token}`);
|
|
35
|
+
|
|
36
|
+
expect(res.status).toBe(200);
|
|
37
|
+
expect(res.body).toMatchObject({ email: VALID_USER.email, name: VALID_USER.name });
|
|
38
|
+
expect((res.body as Record<string, unknown>)['passwordHash']).toBeUndefined();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('401: deve rejeitar requisição sem token', async () => {
|
|
42
|
+
const res = await request(app).get('/api/me');
|
|
43
|
+
expect(res.status).toBe(401);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// ── PATCH /api/me ─────────────────────────────────────────────────────────
|
|
48
|
+
describe('PATCH /api/me', () => {
|
|
49
|
+
it('200: deve atualizar o nome', async () => {
|
|
50
|
+
const token = await registerAndLogin({
|
|
51
|
+
name: 'Old Name',
|
|
52
|
+
email: 'patchname@email.com',
|
|
53
|
+
password: 'senha1234',
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const res = await request(app)
|
|
57
|
+
.patch('/api/me')
|
|
58
|
+
.set('Authorization', `Bearer ${token}`)
|
|
59
|
+
.send({ name: 'New Name' });
|
|
60
|
+
|
|
61
|
+
expect(res.status).toBe(200);
|
|
62
|
+
expect(res.body).toMatchObject({ name: 'New Name' });
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('400: deve rejeitar body sem campos', async () => {
|
|
66
|
+
const token = await registerAndLogin({
|
|
67
|
+
name: 'Someone',
|
|
68
|
+
email: 'patchnobody@email.com',
|
|
69
|
+
password: 'senha1234',
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const res = await request(app)
|
|
73
|
+
.patch('/api/me')
|
|
74
|
+
.set('Authorization', `Bearer ${token}`)
|
|
75
|
+
.send({});
|
|
76
|
+
|
|
77
|
+
expect(res.status).toBe(400);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('401: deve rejeitar requisição sem token', async () => {
|
|
81
|
+
const res = await request(app).patch('/api/me').send({ name: 'New Name' });
|
|
82
|
+
expect(res.status).toBe(401);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// ── PATCH /api/me/password ────────────────────────────────────────────────
|
|
87
|
+
describe('PATCH /api/me/password', () => {
|
|
88
|
+
it('204: deve trocar a senha com credenciais corretas', async () => {
|
|
89
|
+
const token = await registerAndLogin({
|
|
90
|
+
name: 'Pass User',
|
|
91
|
+
email: 'passchange@email.com',
|
|
92
|
+
password: 'senha1234',
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const res = await request(app)
|
|
96
|
+
.patch('/api/me/password')
|
|
97
|
+
.set('Authorization', `Bearer ${token}`)
|
|
98
|
+
.send({ currentPassword: 'senha1234', newPassword: 'novasenha5678' });
|
|
99
|
+
|
|
100
|
+
expect(res.status).toBe(204);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('401: deve rejeitar senha atual incorreta', async () => {
|
|
104
|
+
const token = await registerAndLogin({
|
|
105
|
+
name: 'Pass User 2',
|
|
106
|
+
email: 'passchange2@email.com',
|
|
107
|
+
password: 'senha1234',
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const res = await request(app)
|
|
111
|
+
.patch('/api/me/password')
|
|
112
|
+
.set('Authorization', `Bearer ${token}`)
|
|
113
|
+
.send({ currentPassword: 'wrongpass', newPassword: 'novasenha5678' });
|
|
114
|
+
|
|
115
|
+
expect(res.status).toBe(401);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('400: deve rejeitar nova senha muito curta', async () => {
|
|
119
|
+
const token = await registerAndLogin({
|
|
120
|
+
name: 'Pass User 3',
|
|
121
|
+
email: 'passchange3@email.com',
|
|
122
|
+
password: 'senha1234',
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const res = await request(app)
|
|
126
|
+
.patch('/api/me/password')
|
|
127
|
+
.set('Authorization', `Bearer ${token}`)
|
|
128
|
+
.send({ currentPassword: 'senha1234', newPassword: '123' });
|
|
129
|
+
|
|
130
|
+
expect(res.status).toBe(400);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('401: deve rejeitar requisição sem token', async () => {
|
|
134
|
+
const res = await request(app)
|
|
135
|
+
.patch('/api/me/password')
|
|
136
|
+
.send({ currentPassword: 'senha1234', newPassword: 'novasenha5678' });
|
|
137
|
+
expect(res.status).toBe(401);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// ── DELETE /api/me ────────────────────────────────────────────────────────
|
|
142
|
+
describe('DELETE /api/me', () => {
|
|
143
|
+
it('204: deve deletar a conta com senha correta', async () => {
|
|
144
|
+
const token = await registerAndLogin({
|
|
145
|
+
name: 'Delete Me',
|
|
146
|
+
email: 'deleteme@email.com',
|
|
147
|
+
password: 'senha1234',
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const res = await request(app)
|
|
151
|
+
.delete('/api/me')
|
|
152
|
+
.set('Authorization', `Bearer ${token}`)
|
|
153
|
+
.send({ password: 'senha1234' });
|
|
154
|
+
|
|
155
|
+
expect(res.status).toBe(204);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('401: deve rejeitar senha incorreta', async () => {
|
|
159
|
+
const token = await registerAndLogin({
|
|
160
|
+
name: 'No Delete',
|
|
161
|
+
email: 'nodelete@email.com',
|
|
162
|
+
password: 'senha1234',
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const res = await request(app)
|
|
166
|
+
.delete('/api/me')
|
|
167
|
+
.set('Authorization', `Bearer ${token}`)
|
|
168
|
+
.send({ password: 'wrongpassword' });
|
|
169
|
+
|
|
170
|
+
expect(res.status).toBe(401);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('401: deve rejeitar requisição sem token', async () => {
|
|
174
|
+
const res = await request(app)
|
|
175
|
+
.delete('/api/me')
|
|
176
|
+
.send({ password: 'senha1234' });
|
|
177
|
+
expect(res.status).toBe(401);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
});
|