kybernus 3.1.0 → 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.
Files changed (287) hide show
  1. package/dist/cli/commands/ecommerce.d.ts +3 -0
  2. package/dist/cli/commands/ecommerce.d.ts.map +1 -0
  3. package/dist/cli/commands/ecommerce.js +164 -0
  4. package/dist/cli/commands/ecommerce.js.map +1 -0
  5. package/dist/index.js +2 -0
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/templates/ecommerce/.env.example +10 -0
  9. package/templates/ecommerce/.github/workflows/ci.yml +102 -0
  10. package/templates/ecommerce/.github/workflows/deploy.yml +31 -0
  11. package/templates/ecommerce/.prettierrc +9 -0
  12. package/templates/ecommerce/Dockerfile +54 -0
  13. package/templates/ecommerce/README.md +295 -0
  14. package/templates/ecommerce/apps/api/.env.example +59 -0
  15. package/templates/ecommerce/apps/api/jest.config.ts +50 -0
  16. package/templates/ecommerce/apps/api/jest.integration.config.ts +45 -0
  17. package/templates/ecommerce/apps/api/package.json +59 -0
  18. package/templates/ecommerce/apps/api/prisma/migrations/20260306000137_init/migration.sql +184 -0
  19. package/templates/ecommerce/apps/api/prisma/migrations/migration_lock.toml +3 -0
  20. package/templates/ecommerce/apps/api/prisma/schema.prisma +181 -0
  21. package/templates/ecommerce/apps/api/prisma/seed.ts +159 -0
  22. package/templates/ecommerce/apps/api/src/__tests__/app.test.ts +39 -0
  23. package/templates/ecommerce/apps/api/src/__tests__/globalSetup.ts +34 -0
  24. package/templates/ecommerce/apps/api/src/__tests__/globalTeardown.ts +16 -0
  25. package/templates/ecommerce/apps/api/src/__tests__/setup.db.ts +18 -0
  26. package/templates/ecommerce/apps/api/src/__tests__/setup.env.ts +14 -0
  27. package/templates/ecommerce/apps/api/src/app.ts +133 -0
  28. package/templates/ecommerce/apps/api/src/application/admin/admin-user.service.ts +24 -0
  29. package/templates/ecommerce/apps/api/src/application/admin/dashboard.service.ts +102 -0
  30. package/templates/ecommerce/apps/api/src/application/auth/auth.service.ts +185 -0
  31. package/templates/ecommerce/apps/api/src/application/cart/cart.service.ts +151 -0
  32. package/templates/ecommerce/apps/api/src/application/cart/coupon.service.ts +51 -0
  33. package/templates/ecommerce/apps/api/src/application/catalog/catalog.service.ts +168 -0
  34. package/templates/ecommerce/apps/api/src/application/checkout/checkout.service.ts +114 -0
  35. package/templates/ecommerce/apps/api/src/application/orders/order.service.ts +93 -0
  36. package/templates/ecommerce/apps/api/src/application/ports/email.port.ts +3 -0
  37. package/templates/ecommerce/apps/api/src/application/ports/payment.port.ts +24 -0
  38. package/templates/ecommerce/apps/api/src/application/ports/shipping.port.ts +9 -0
  39. package/templates/ecommerce/apps/api/src/application/ports/storage.port.ts +3 -0
  40. package/templates/ecommerce/apps/api/src/application/ports/token-blacklist.port.ts +4 -0
  41. package/templates/ecommerce/apps/api/src/application/ports/token.port.ts +18 -0
  42. package/templates/ecommerce/apps/api/src/application/profile/profile.service.ts +76 -0
  43. package/templates/ecommerce/apps/api/src/domain/auth/user.entity.ts +109 -0
  44. package/templates/ecommerce/apps/api/src/domain/auth/user.repository.ts +11 -0
  45. package/templates/ecommerce/apps/api/src/domain/cart/cart.entity.ts +136 -0
  46. package/templates/ecommerce/apps/api/src/domain/cart/cart.repository.ts +8 -0
  47. package/templates/ecommerce/apps/api/src/domain/cart/coupon.entity.ts +58 -0
  48. package/templates/ecommerce/apps/api/src/domain/cart/coupon.repository.ts +10 -0
  49. package/templates/ecommerce/apps/api/src/domain/catalog/category.entity.ts +51 -0
  50. package/templates/ecommerce/apps/api/src/domain/catalog/category.repository.ts +10 -0
  51. package/templates/ecommerce/apps/api/src/domain/catalog/product.entity.ts +130 -0
  52. package/templates/ecommerce/apps/api/src/domain/catalog/product.repository.ts +28 -0
  53. package/templates/ecommerce/apps/api/src/domain/checkout/order.entity.ts +121 -0
  54. package/templates/ecommerce/apps/api/src/domain/checkout/order.repository.ts +11 -0
  55. package/templates/ecommerce/apps/api/src/domain/shared/AppError.ts +12 -0
  56. package/templates/ecommerce/apps/api/src/infrastructure/cache/redis.ts +16 -0
  57. package/templates/ecommerce/apps/api/src/infrastructure/config/registry/admin.registry.ts +13 -0
  58. package/templates/ecommerce/apps/api/src/infrastructure/config/registry/auth.registry.ts +34 -0
  59. package/templates/ecommerce/apps/api/src/infrastructure/config/registry/cart.registry.ts +49 -0
  60. package/templates/ecommerce/apps/api/src/infrastructure/config/registry/catalog.registry.ts +24 -0
  61. package/templates/ecommerce/apps/api/src/infrastructure/config/registry/checkout.registry.ts +47 -0
  62. package/templates/ecommerce/apps/api/src/infrastructure/config/registry/orders.registry.ts +6 -0
  63. package/templates/ecommerce/apps/api/src/infrastructure/config/registry/profile.registry.ts +4 -0
  64. package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/cart.memory.repository.ts +33 -0
  65. package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/category.memory.repository.ts +41 -0
  66. package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/coupon.memory.repository.ts +55 -0
  67. package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/order.memory.repository.ts +75 -0
  68. package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/product.memory.repository.ts +100 -0
  69. package/templates/ecommerce/apps/api/src/infrastructure/persistence/in-memory/user.memory.repository.ts +54 -0
  70. package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma/auth/user.prisma.repository.ts +83 -0
  71. package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma/catalog/category.prisma.repository.ts +69 -0
  72. package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma/catalog/product.prisma.repository.ts +185 -0
  73. package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma/checkout/order.prisma.repository.ts +149 -0
  74. package/templates/ecommerce/apps/api/src/infrastructure/persistence/prisma-client.ts +17 -0
  75. package/templates/ecommerce/apps/api/src/infrastructure/services/email/email.registry.ts +18 -0
  76. package/templates/ecommerce/apps/api/src/infrastructure/services/email/ethereal.email.service.ts +38 -0
  77. package/templates/ecommerce/apps/api/src/infrastructure/services/email/noop.email.service.ts +12 -0
  78. package/templates/ecommerce/apps/api/src/infrastructure/services/email/smtp.email.service.ts +36 -0
  79. package/templates/ecommerce/apps/api/src/infrastructure/services/payment/stripe-webhook.handler.ts +83 -0
  80. package/templates/ecommerce/apps/api/src/infrastructure/services/payment/stripe.adapter.ts +39 -0
  81. package/templates/ecommerce/apps/api/src/infrastructure/services/shipping/mock.shipping.service.ts +17 -0
  82. package/templates/ecommerce/apps/api/src/infrastructure/services/storage/in-memory.storage.service.ts +11 -0
  83. package/templates/ecommerce/apps/api/src/infrastructure/services/storage/local-disk.storage.service.ts +27 -0
  84. package/templates/ecommerce/apps/api/src/infrastructure/services/storage/s3.storage.service.ts +52 -0
  85. package/templates/ecommerce/apps/api/src/infrastructure/services/storage/storage.registry.ts +19 -0
  86. package/templates/ecommerce/apps/api/src/infrastructure/services/token/redis.token.blacklist.ts +23 -0
  87. package/templates/ecommerce/apps/api/src/infrastructure/services/token/token.blacklist.ts +30 -0
  88. package/templates/ecommerce/apps/api/src/infrastructure/services/token/token.service.ts +136 -0
  89. package/templates/ecommerce/apps/api/src/modules/admin/__tests__/admin.routes.integration.test.ts +250 -0
  90. package/templates/ecommerce/apps/api/src/modules/admin/admin.controller.ts +116 -0
  91. package/templates/ecommerce/apps/api/src/modules/admin/admin.registry.ts +1 -0
  92. package/templates/ecommerce/apps/api/src/modules/admin/admin.routes.ts +21 -0
  93. package/templates/ecommerce/apps/api/src/modules/admin/admin.service.ts +1 -0
  94. package/templates/ecommerce/apps/api/src/modules/admin/admin.user.service.ts +1 -0
  95. package/templates/ecommerce/apps/api/src/modules/auth/__tests__/auth.logout.redis.test.ts +104 -0
  96. package/templates/ecommerce/apps/api/src/modules/auth/__tests__/auth.routes.integration.test.ts +211 -0
  97. package/templates/ecommerce/apps/api/src/modules/auth/__tests__/auth.service.unit.test.ts +260 -0
  98. package/templates/ecommerce/apps/api/src/modules/auth/__tests__/email.service.unit.test.ts +94 -0
  99. package/templates/ecommerce/apps/api/src/modules/auth/__tests__/token.blacklist.redis.test.ts +65 -0
  100. package/templates/ecommerce/apps/api/src/modules/auth/__tests__/user.entity.unit.test.ts +79 -0
  101. package/templates/ecommerce/apps/api/src/modules/auth/__tests__/user.prisma.repository.test.ts +138 -0
  102. package/templates/ecommerce/apps/api/src/modules/auth/auth.controller.ts +148 -0
  103. package/templates/ecommerce/apps/api/src/modules/auth/auth.registry.ts +1 -0
  104. package/templates/ecommerce/apps/api/src/modules/auth/auth.routes.ts +17 -0
  105. package/templates/ecommerce/apps/api/src/modules/auth/auth.service.ts +1 -0
  106. package/templates/ecommerce/apps/api/src/modules/auth/redis.token.blacklist.ts +1 -0
  107. package/templates/ecommerce/apps/api/src/modules/auth/token.blacklist.ts +2 -0
  108. package/templates/ecommerce/apps/api/src/modules/auth/token.service.ts +2 -0
  109. package/templates/ecommerce/apps/api/src/modules/auth/user.entity.ts +1 -0
  110. package/templates/ecommerce/apps/api/src/modules/auth/user.prisma.repository.ts +1 -0
  111. package/templates/ecommerce/apps/api/src/modules/auth/user.repository.ts +2 -0
  112. package/templates/ecommerce/apps/api/src/modules/cart/__tests__/cart.entity.unit.test.ts +144 -0
  113. package/templates/ecommerce/apps/api/src/modules/cart/__tests__/cart.routes.integration.test.ts +242 -0
  114. package/templates/ecommerce/apps/api/src/modules/cart/__tests__/cart.service.unit.test.ts +151 -0
  115. package/templates/ecommerce/apps/api/src/modules/cart/__tests__/coupon.admin.integration.test.ts +136 -0
  116. package/templates/ecommerce/apps/api/src/modules/cart/cart.controller.ts +94 -0
  117. package/templates/ecommerce/apps/api/src/modules/cart/cart.entity.ts +1 -0
  118. package/templates/ecommerce/apps/api/src/modules/cart/cart.registry.ts +1 -0
  119. package/templates/ecommerce/apps/api/src/modules/cart/cart.repository.ts +2 -0
  120. package/templates/ecommerce/apps/api/src/modules/cart/cart.routes.ts +17 -0
  121. package/templates/ecommerce/apps/api/src/modules/cart/cart.service.ts +1 -0
  122. package/templates/ecommerce/apps/api/src/modules/cart/coupon.entity.ts +1 -0
  123. package/templates/ecommerce/apps/api/src/modules/cart/coupon.repository.ts +2 -0
  124. package/templates/ecommerce/apps/api/src/modules/cart/coupon.service.ts +1 -0
  125. package/templates/ecommerce/apps/api/src/modules/cart/shipping.service.ts +2 -0
  126. package/templates/ecommerce/apps/api/src/modules/catalog/__tests__/catalog.routes.integration.test.ts +275 -0
  127. package/templates/ecommerce/apps/api/src/modules/catalog/__tests__/catalog.service.unit.test.ts +223 -0
  128. package/templates/ecommerce/apps/api/src/modules/catalog/__tests__/product.image.integration.test.ts +130 -0
  129. package/templates/ecommerce/apps/api/src/modules/catalog/__tests__/product.prisma.repository.test.ts +174 -0
  130. package/templates/ecommerce/apps/api/src/modules/catalog/catalog.controller.ts +176 -0
  131. package/templates/ecommerce/apps/api/src/modules/catalog/catalog.registry.ts +1 -0
  132. package/templates/ecommerce/apps/api/src/modules/catalog/catalog.routes.ts +38 -0
  133. package/templates/ecommerce/apps/api/src/modules/catalog/catalog.service.ts +1 -0
  134. package/templates/ecommerce/apps/api/src/modules/catalog/category.entity.ts +1 -0
  135. package/templates/ecommerce/apps/api/src/modules/catalog/category.prisma.repository.ts +1 -0
  136. package/templates/ecommerce/apps/api/src/modules/catalog/category.repository.ts +2 -0
  137. package/templates/ecommerce/apps/api/src/modules/catalog/product.entity.ts +1 -0
  138. package/templates/ecommerce/apps/api/src/modules/catalog/product.prisma.repository.ts +1 -0
  139. package/templates/ecommerce/apps/api/src/modules/catalog/product.repository.ts +2 -0
  140. package/templates/ecommerce/apps/api/src/modules/checkout/__tests__/checkout.routes.integration.test.ts +163 -0
  141. package/templates/ecommerce/apps/api/src/modules/checkout/__tests__/checkout.service.unit.test.ts +191 -0
  142. package/templates/ecommerce/apps/api/src/modules/checkout/__tests__/order.prisma.repository.test.ts +150 -0
  143. package/templates/ecommerce/apps/api/src/modules/checkout/checkout.controller.ts +59 -0
  144. package/templates/ecommerce/apps/api/src/modules/checkout/checkout.registry.ts +1 -0
  145. package/templates/ecommerce/apps/api/src/modules/checkout/checkout.routes.ts +18 -0
  146. package/templates/ecommerce/apps/api/src/modules/checkout/checkout.service.ts +1 -0
  147. package/templates/ecommerce/apps/api/src/modules/checkout/order.entity.ts +1 -0
  148. package/templates/ecommerce/apps/api/src/modules/checkout/order.prisma.repository.ts +1 -0
  149. package/templates/ecommerce/apps/api/src/modules/checkout/order.repository.ts +2 -0
  150. package/templates/ecommerce/apps/api/src/modules/checkout/tax.service.ts +9 -0
  151. package/templates/ecommerce/apps/api/src/modules/orders/__tests__/order.entity.unit.test.ts +68 -0
  152. package/templates/ecommerce/apps/api/src/modules/orders/__tests__/order.routes.integration.test.ts +254 -0
  153. package/templates/ecommerce/apps/api/src/modules/orders/__tests__/order.service.email.unit.test.ts +142 -0
  154. package/templates/ecommerce/apps/api/src/modules/orders/order.controller.ts +96 -0
  155. package/templates/ecommerce/apps/api/src/modules/orders/order.registry.ts +1 -0
  156. package/templates/ecommerce/apps/api/src/modules/orders/order.routes.ts +17 -0
  157. package/templates/ecommerce/apps/api/src/modules/orders/order.service.ts +1 -0
  158. package/templates/ecommerce/apps/api/src/modules/payment/__tests__/stripe-webhook.unit.test.ts +330 -0
  159. package/templates/ecommerce/apps/api/src/modules/payment/__tests__/stripe.adapter.unit.test.ts +84 -0
  160. package/templates/ecommerce/apps/api/src/modules/payment/adapters/stripe.adapter.ts +1 -0
  161. package/templates/ecommerce/apps/api/src/modules/payment/payment.port.ts +1 -0
  162. package/templates/ecommerce/apps/api/src/modules/payment/stripe-webhook.handler.ts +1 -0
  163. package/templates/ecommerce/apps/api/src/modules/profile/__tests__/profile.routes.integration.test.ts +180 -0
  164. package/templates/ecommerce/apps/api/src/modules/profile/__tests__/profile.service.unit.test.ts +187 -0
  165. package/templates/ecommerce/apps/api/src/modules/profile/profile.controller.ts +92 -0
  166. package/templates/ecommerce/apps/api/src/modules/profile/profile.registry.ts +1 -0
  167. package/templates/ecommerce/apps/api/src/modules/profile/profile.routes.ts +14 -0
  168. package/templates/ecommerce/apps/api/src/modules/profile/profile.service.ts +1 -0
  169. package/templates/ecommerce/apps/api/src/presentation/middlewares/authenticate.ts +37 -0
  170. package/templates/ecommerce/apps/api/src/presentation/middlewares/authorize.ts +23 -0
  171. package/templates/ecommerce/apps/api/src/presentation/middlewares/errorHandler.ts +48 -0
  172. package/templates/ecommerce/apps/api/src/presentation/modules/admin/admin.controller.ts +116 -0
  173. package/templates/ecommerce/apps/api/src/presentation/modules/admin/admin.routes.ts +21 -0
  174. package/templates/ecommerce/apps/api/src/presentation/modules/auth/auth.controller.ts +147 -0
  175. package/templates/ecommerce/apps/api/src/presentation/modules/auth/auth.routes.ts +17 -0
  176. package/templates/ecommerce/apps/api/src/presentation/modules/cart/cart.controller.ts +94 -0
  177. package/templates/ecommerce/apps/api/src/presentation/modules/cart/cart.routes.ts +17 -0
  178. package/templates/ecommerce/apps/api/src/presentation/modules/catalog/catalog.controller.ts +176 -0
  179. package/templates/ecommerce/apps/api/src/presentation/modules/catalog/catalog.routes.ts +38 -0
  180. package/templates/ecommerce/apps/api/src/presentation/modules/checkout/checkout.controller.ts +59 -0
  181. package/templates/ecommerce/apps/api/src/presentation/modules/checkout/checkout.routes.ts +18 -0
  182. package/templates/ecommerce/apps/api/src/presentation/modules/orders/order.controller.ts +96 -0
  183. package/templates/ecommerce/apps/api/src/presentation/modules/orders/order.routes.ts +17 -0
  184. package/templates/ecommerce/apps/api/src/presentation/modules/profile/profile.controller.ts +92 -0
  185. package/templates/ecommerce/apps/api/src/presentation/modules/profile/profile.routes.ts +14 -0
  186. package/templates/ecommerce/apps/api/src/presentation/validators/uuidParam.ts +20 -0
  187. package/templates/ecommerce/apps/api/src/server.ts +47 -0
  188. package/templates/ecommerce/apps/api/src/shared/__tests__/uuid.validation.test.ts +111 -0
  189. package/templates/ecommerce/apps/api/src/shared/errors/AppError.ts +1 -0
  190. package/templates/ecommerce/apps/api/src/shared/infra/email/EtherealEmailService.ts +1 -0
  191. package/templates/ecommerce/apps/api/src/shared/infra/email/IEmailService.ts +1 -0
  192. package/templates/ecommerce/apps/api/src/shared/infra/email/NoopEmailService.ts +1 -0
  193. package/templates/ecommerce/apps/api/src/shared/infra/email/SmtpEmailService.ts +1 -0
  194. package/templates/ecommerce/apps/api/src/shared/infra/email/__tests__/ethereal.email.integration.test.ts +32 -0
  195. package/templates/ecommerce/apps/api/src/shared/infra/email/email.registry.ts +1 -0
  196. package/templates/ecommerce/apps/api/src/shared/infra/prisma.ts +1 -0
  197. package/templates/ecommerce/apps/api/src/shared/infra/redis.ts +1 -0
  198. package/templates/ecommerce/apps/api/src/shared/infra/storage/IStorageService.ts +1 -0
  199. package/templates/ecommerce/apps/api/src/shared/infra/storage/InMemoryStorageService.ts +1 -0
  200. package/templates/ecommerce/apps/api/src/shared/infra/storage/LocalDiskStorageService.ts +1 -0
  201. package/templates/ecommerce/apps/api/src/shared/infra/storage/S3StorageService.ts +1 -0
  202. package/templates/ecommerce/apps/api/src/shared/infra/storage/__tests__/s3.storage.unit.test.ts +73 -0
  203. package/templates/ecommerce/apps/api/src/shared/infra/storage/storage.registry.ts +1 -0
  204. package/templates/ecommerce/apps/api/src/shared/middlewares/authenticate.ts +1 -0
  205. package/templates/ecommerce/apps/api/src/shared/middlewares/authorize.ts +1 -0
  206. package/templates/ecommerce/apps/api/src/shared/middlewares/errorHandler.ts +1 -0
  207. package/templates/ecommerce/apps/api/src/shared/validators/uuidParam.ts +1 -0
  208. package/templates/ecommerce/apps/api/tsconfig.json +15 -0
  209. package/templates/ecommerce/apps/web/.env.example +8 -0
  210. package/templates/ecommerce/apps/web/index.html +19 -0
  211. package/templates/ecommerce/apps/web/jest.config.ts +45 -0
  212. package/templates/ecommerce/apps/web/package.json +38 -0
  213. package/templates/ecommerce/apps/web/src/App.tsx +133 -0
  214. package/templates/ecommerce/apps/web/src/__mocks__/fileMock.ts +1 -0
  215. package/templates/ecommerce/apps/web/src/__mocks__/styleMock.ts +1 -0
  216. package/templates/ecommerce/apps/web/src/index.css +159 -0
  217. package/templates/ecommerce/apps/web/src/main.tsx +13 -0
  218. package/templates/ecommerce/apps/web/src/modules/admin/__tests__/CouponsAdminPage.test.tsx +134 -0
  219. package/templates/ecommerce/apps/web/src/modules/admin/__tests__/DashboardPage.test.tsx +65 -0
  220. package/templates/ecommerce/apps/web/src/modules/admin/__tests__/OrdersAdminPage.test.tsx +79 -0
  221. package/templates/ecommerce/apps/web/src/modules/admin/__tests__/ProductsAdminPage.test.tsx +84 -0
  222. package/templates/ecommerce/apps/web/src/modules/admin/__tests__/UsersAdminPage.test.tsx +85 -0
  223. package/templates/ecommerce/apps/web/src/modules/admin/pages/CouponsAdminPage.tsx +179 -0
  224. package/templates/ecommerce/apps/web/src/modules/admin/pages/DashboardPage.tsx +58 -0
  225. package/templates/ecommerce/apps/web/src/modules/admin/pages/OrdersAdminPage.tsx +178 -0
  226. package/templates/ecommerce/apps/web/src/modules/admin/pages/ProductsAdminPage.tsx +444 -0
  227. package/templates/ecommerce/apps/web/src/modules/admin/pages/UsersAdminPage.tsx +87 -0
  228. package/templates/ecommerce/apps/web/src/modules/auth/LoginForm.tsx +91 -0
  229. package/templates/ecommerce/apps/web/src/modules/auth/RegisterForm.tsx +109 -0
  230. package/templates/ecommerce/apps/web/src/modules/auth/__tests__/ForgotPasswordPage.test.tsx +42 -0
  231. package/templates/ecommerce/apps/web/src/modules/auth/__tests__/LoginForm.test.tsx +76 -0
  232. package/templates/ecommerce/apps/web/src/modules/auth/__tests__/RegisterForm.test.tsx +62 -0
  233. package/templates/ecommerce/apps/web/src/modules/auth/__tests__/ResetPasswordPage.test.tsx +66 -0
  234. package/templates/ecommerce/apps/web/src/modules/auth/pages/ForgotPasswordPage.tsx +100 -0
  235. package/templates/ecommerce/apps/web/src/modules/auth/pages/LoginPage.tsx +39 -0
  236. package/templates/ecommerce/apps/web/src/modules/auth/pages/RegisterPage.tsx +39 -0
  237. package/templates/ecommerce/apps/web/src/modules/auth/pages/ResetPasswordPage.tsx +110 -0
  238. package/templates/ecommerce/apps/web/src/modules/auth/useAuthStore.ts +141 -0
  239. package/templates/ecommerce/apps/web/src/modules/cart/__tests__/CartPage.test.tsx +111 -0
  240. package/templates/ecommerce/apps/web/src/modules/cart/pages/CartPage.tsx +313 -0
  241. package/templates/ecommerce/apps/web/src/modules/catalog/__tests__/ProductCard.test.tsx +59 -0
  242. package/templates/ecommerce/apps/web/src/modules/catalog/__tests__/ProductFilters.test.tsx +56 -0
  243. package/templates/ecommerce/apps/web/src/modules/catalog/components/ProductCard.tsx +78 -0
  244. package/templates/ecommerce/apps/web/src/modules/catalog/components/ProductFilters.tsx +104 -0
  245. package/templates/ecommerce/apps/web/src/modules/catalog/pages/ProductDetailPage.tsx +179 -0
  246. package/templates/ecommerce/apps/web/src/modules/catalog/pages/ProductListPage.tsx +100 -0
  247. package/templates/ecommerce/apps/web/src/modules/checkout/__tests__/CheckoutPage.test.tsx +159 -0
  248. package/templates/ecommerce/apps/web/src/modules/checkout/__tests__/StripePaymentForm.test.tsx +79 -0
  249. package/templates/ecommerce/apps/web/src/modules/checkout/components/StripePaymentForm.tsx +55 -0
  250. package/templates/ecommerce/apps/web/src/modules/checkout/hooks/useCheckout.ts +56 -0
  251. package/templates/ecommerce/apps/web/src/modules/checkout/pages/CheckoutPage.tsx +344 -0
  252. package/templates/ecommerce/apps/web/src/modules/checkout/pages/CheckoutSuccessPage.tsx +12 -0
  253. package/templates/ecommerce/apps/web/src/modules/legal/pages/PrivacyPolicyPage.tsx +207 -0
  254. package/templates/ecommerce/apps/web/src/modules/legal/pages/TermsOfServicePage.tsx +175 -0
  255. package/templates/ecommerce/apps/web/src/modules/orders/__tests__/OrderDetailPage.test.tsx +75 -0
  256. package/templates/ecommerce/apps/web/src/modules/orders/__tests__/OrderHistoryPage.test.tsx +87 -0
  257. package/templates/ecommerce/apps/web/src/modules/orders/pages/OrderDetailPage.tsx +73 -0
  258. package/templates/ecommerce/apps/web/src/modules/orders/pages/OrderHistoryPage.tsx +97 -0
  259. package/templates/ecommerce/apps/web/src/modules/profile/__tests__/ProfilePage.test.tsx +150 -0
  260. package/templates/ecommerce/apps/web/src/modules/profile/pages/ProfilePage.tsx +275 -0
  261. package/templates/ecommerce/apps/web/src/setupTests.ts +10 -0
  262. package/templates/ecommerce/apps/web/src/shared/components/CookieConsent.tsx +108 -0
  263. package/templates/ecommerce/apps/web/src/shared/components/ErrorBoundary.tsx +112 -0
  264. package/templates/ecommerce/apps/web/src/shared/components/Layout.tsx +143 -0
  265. package/templates/ecommerce/apps/web/src/shared/components/ProtectedRoute.tsx +21 -0
  266. package/templates/ecommerce/apps/web/src/shared/config/siteConfig.ts +57 -0
  267. package/templates/ecommerce/apps/web/src/shared/hooks/usePageTitle.ts +16 -0
  268. package/templates/ecommerce/apps/web/src/shared/lib/apiFetch.ts +16 -0
  269. package/templates/ecommerce/apps/web/src/shared/pages/NotFoundPage.tsx +42 -0
  270. package/templates/ecommerce/apps/web/src/shared/theme/ThemeProvider.tsx +45 -0
  271. package/templates/ecommerce/apps/web/src/shared/theme/__tests__/ThemeProvider.test.tsx +78 -0
  272. package/templates/ecommerce/apps/web/src/shared/theme/createTheme.ts +58 -0
  273. package/templates/ecommerce/apps/web/src/shared/theme/tokens.ts +81 -0
  274. package/templates/ecommerce/apps/web/src/vite-env.d.ts +1 -0
  275. package/templates/ecommerce/apps/web/tsconfig.jest.json +12 -0
  276. package/templates/ecommerce/apps/web/tsconfig.json +25 -0
  277. package/templates/ecommerce/apps/web/tsconfig.node.json +11 -0
  278. package/templates/ecommerce/apps/web/vite.config.ts +30 -0
  279. package/templates/ecommerce/docker-compose.yml +85 -0
  280. package/templates/ecommerce/package-lock.json +11255 -0
  281. package/templates/ecommerce/package.json +27 -0
  282. package/templates/ecommerce/packages/shared-types/package.json +13 -0
  283. package/templates/ecommerce/packages/shared-types/src/index.ts +3 -0
  284. package/templates/ecommerce/packages/shared-types/src/theme.ts +44 -0
  285. package/templates/ecommerce/packages/shared-types/tsconfig.json +11 -0
  286. package/templates/ecommerce/scripts/customize.sh +201 -0
  287. package/templates/ecommerce/tsconfig.json +14 -0
@@ -0,0 +1,275 @@
1
+ import request from 'supertest';
2
+ import app from '../../../app';
3
+
4
+ /**
5
+ * Integration tests for Catalog routes.
6
+ * Uses in-memory repositories via the catalog.registry module.
7
+ * An ADMIN JWT is generated with the shared tokenService.
8
+ */
9
+
10
+ // ── Helpers ──────────────────────────────────────────────────────────────────
11
+ let adminToken: string;
12
+ let customerToken: string;
13
+
14
+ const ADMIN_USER = {
15
+ name: 'Admin User',
16
+ email: 'admin@ecommerce.com',
17
+ password: 'admin1234',
18
+ };
19
+
20
+ const CUSTOMER_USER = {
21
+ name: 'João Cliente',
22
+ email: 'joao@ecommerce.com',
23
+ password: 'cliente1234',
24
+ };
25
+
26
+ const VALID_PRODUCT = {
27
+ name: 'Camiseta Básica',
28
+ description: 'Camiseta de algodão',
29
+ price: 49.9,
30
+ categorySlug: 'camisetas',
31
+ images: [],
32
+ variants: [
33
+ { sku: 'CAM-P', size: 'P', color: 'Branco', stock: 5 },
34
+ { sku: 'CAM-M', size: 'M', color: 'Branco', stock: 10 },
35
+ ],
36
+ };
37
+
38
+ // ── Setup ─────────────────────────────────────────────────────────────────────
39
+ beforeAll(async () => {
40
+ // Register both users
41
+ await request(app).post('/api/auth/register').send(CUSTOMER_USER);
42
+
43
+ // Promote admin via internal registry (since we have no admin-creation endpoint yet)
44
+ const { catalogRegistry } = await import('../catalog.registry');
45
+ const { userRepository } = await import('../../auth/auth.registry');
46
+
47
+ // Create category for tests
48
+ await catalogRegistry.categoryRepository.create(
49
+ (await import('../category.entity')).CategoryEntity.create({
50
+ name: 'Camisetas',
51
+ slug: 'camisetas',
52
+ description: null,
53
+ parentId: null,
54
+ }),
55
+ );
56
+
57
+ // Create an admin user directly via the repository
58
+ const { UserEntity } = await import('../../auth/user.entity');
59
+ const { hash } = await import('bcryptjs');
60
+ const adminHash = await hash(ADMIN_USER.password, 10);
61
+ const adminEntity = UserEntity.create({
62
+ name: ADMIN_USER.name,
63
+ email: ADMIN_USER.email,
64
+ passwordHash: adminHash,
65
+ role: 'ADMIN',
66
+ });
67
+ await userRepository.create(adminEntity);
68
+
69
+ // Login both
70
+ const adminRes = await request(app).post('/api/auth/login').send({
71
+ email: ADMIN_USER.email,
72
+ password: ADMIN_USER.password,
73
+ });
74
+ adminToken = (adminRes.body as { accessToken: string }).accessToken;
75
+
76
+ const customerRes = await request(app).post('/api/auth/login').send({
77
+ email: CUSTOMER_USER.email,
78
+ password: CUSTOMER_USER.password,
79
+ });
80
+ customerToken = (customerRes.body as { accessToken: string }).accessToken;
81
+ });
82
+
83
+ // ── Tests ────────────────────────────────────────────────────────────────────
84
+ describe('Catalog Routes — Integration', () => {
85
+ // ── GET /api/products ─────────────────────────────────────────────────────
86
+ describe('GET /api/products', () => {
87
+ it('200: deve listar produtos paginados (público, sem autenticação)', async () => {
88
+ const res = await request(app).get('/api/products');
89
+
90
+ expect(res.status).toBe(200);
91
+ expect(res.body).toHaveProperty('items');
92
+ expect(Array.isArray(res.body.items)).toBe(true);
93
+ });
94
+
95
+ it('deve aceitar query params: category, minPrice, maxPrice, q, sortBy', async () => {
96
+ const res = await request(app)
97
+ .get('/api/products')
98
+ .query({ categorySlug: 'camisetas', minPrice: 10, maxPrice: 200, q: 'camiseta', sortBy: 'price_asc' });
99
+
100
+ expect(res.status).toBe(200);
101
+ expect(res.body).toHaveProperty('items');
102
+ });
103
+
104
+ it('deve retornar nextCursor na resposta paginada', async () => {
105
+ const res = await request(app).get('/api/products').query({ limit: 100 });
106
+
107
+ expect(res.status).toBe(200);
108
+ expect(res.body).toHaveProperty('nextCursor');
109
+ });
110
+ });
111
+
112
+ // ── POST /api/products ────────────────────────────────────────────────────
113
+ describe('POST /api/products', () => {
114
+ it('401: deve rejeitar sem token', async () => {
115
+ const res = await request(app).post('/api/products').send(VALID_PRODUCT);
116
+
117
+ expect(res.status).toBe(401);
118
+ });
119
+
120
+ it('403: deve rejeitar token de CUSTOMER', async () => {
121
+ const res = await request(app)
122
+ .post('/api/products')
123
+ .set('Authorization', `Bearer ${customerToken}`)
124
+ .send(VALID_PRODUCT);
125
+
126
+ expect(res.status).toBe(403);
127
+ });
128
+
129
+ it('201: deve criar produto como ADMIN', async () => {
130
+ const res = await request(app)
131
+ .post('/api/products')
132
+ .set('Authorization', `Bearer ${adminToken}`)
133
+ .send(VALID_PRODUCT);
134
+
135
+ expect(res.status).toBe(201);
136
+ expect(res.body.name).toBe(VALID_PRODUCT.name);
137
+ expect(res.body.slug).toBe('camiseta-basica');
138
+ expect(res.body.variants).toHaveLength(2);
139
+ });
140
+
141
+ it('422: deve validar campos obrigatórios (preço negativo)', async () => {
142
+ const res = await request(app)
143
+ .post('/api/products')
144
+ .set('Authorization', `Bearer ${adminToken}`)
145
+ .send({ ...VALID_PRODUCT, price: -10 });
146
+
147
+ expect(res.status).toBe(422);
148
+ });
149
+
150
+ it('422: deve rejeitar produto sem nome', async () => {
151
+ const res = await request(app)
152
+ .post('/api/products')
153
+ .set('Authorization', `Bearer ${adminToken}`)
154
+ .send({ ...VALID_PRODUCT, name: '' });
155
+
156
+ expect(res.status).toBe(422);
157
+ });
158
+ });
159
+
160
+ // ── GET /api/products/:slug ───────────────────────────────────────────────
161
+ describe('GET /api/products/:slug', () => {
162
+ beforeAll(async () => {
163
+ // Ensure product exists
164
+ await request(app)
165
+ .post('/api/products')
166
+ .set('Authorization', `Bearer ${adminToken}`)
167
+ .send({ ...VALID_PRODUCT, name: 'Produto Detalhe', variants: [{ sku: 'DET-U', size: 'U', color: 'Preto', stock: 3 }] });
168
+ });
169
+
170
+ it('200: deve retornar produto com variações', async () => {
171
+ const res = await request(app).get('/api/products/produto-detalhe');
172
+
173
+ expect(res.status).toBe(200);
174
+ expect(res.body.slug).toBe('produto-detalhe');
175
+ expect(Array.isArray(res.body.variants)).toBe(true);
176
+ });
177
+
178
+ it('404: deve retornar 404 para slug inexistente', async () => {
179
+ const res = await request(app).get('/api/products/slug-que-nao-existe');
180
+
181
+ expect(res.status).toBe(404);
182
+ });
183
+ });
184
+
185
+ // ── PUT /api/products/:id ─────────────────────────────────────────────────
186
+ describe('PUT /api/products/:id', () => {
187
+ it('200: deve atualizar produto como ADMIN', async () => {
188
+ // Create a product first
189
+ const createRes = await request(app)
190
+ .post('/api/products')
191
+ .set('Authorization', `Bearer ${adminToken}`)
192
+ .send({ ...VALID_PRODUCT, name: 'Produto Para Atualizar', variants: [{ sku: 'UPD-U', size: 'U', color: 'Rosa', stock: 1 }] });
193
+
194
+ const productId = (createRes.body as { id: string }).id;
195
+
196
+ const res = await request(app)
197
+ .put(`/api/products/${productId}`)
198
+ .set('Authorization', `Bearer ${adminToken}`)
199
+ .send({ name: 'Produto Atualizado', price: 59.9 });
200
+
201
+ expect(res.status).toBe(200);
202
+ expect(res.body.name).toBe('Produto Atualizado');
203
+ });
204
+
205
+ it('404: produto inexistente', async () => {
206
+ const res = await request(app)
207
+ .put('/api/products/00000000-0000-4000-8000-000000000099')
208
+ .set('Authorization', `Bearer ${adminToken}`)
209
+ .send({ name: 'X' });
210
+
211
+ expect(res.status).toBe(404);
212
+ });
213
+ });
214
+
215
+ // ── DELETE /api/products/:id ──────────────────────────────────────────────
216
+ describe('DELETE /api/products/:id', () => {
217
+ it('204: deve soft-delete o produto', async () => {
218
+ const createRes = await request(app)
219
+ .post('/api/products')
220
+ .set('Authorization', `Bearer ${adminToken}`)
221
+ .send({ ...VALID_PRODUCT, name: 'Produto Para Deletar', variants: [{ sku: 'DEL-U', size: 'U', color: 'Cinza', stock: 1 }] });
222
+
223
+ const productId = (createRes.body as { id: string }).id;
224
+ const slug = (createRes.body as { slug: string }).slug;
225
+
226
+ const deleteRes = await request(app)
227
+ .delete(`/api/products/${productId}`)
228
+ .set('Authorization', `Bearer ${adminToken}`);
229
+
230
+ expect(deleteRes.status).toBe(204);
231
+
232
+ // Deve ocultar produto deletado das listagens públicas
233
+ const getRes = await request(app).get(`/api/products/${slug}`);
234
+ expect(getRes.status).toBe(404);
235
+ });
236
+ });
237
+
238
+ // ── PATCH /api/products/:id/stock ────────────────────────────────────────
239
+ describe('PATCH /api/products/:id/stock', () => {
240
+ it('200: deve ajustar estoque por variação', async () => {
241
+ const createRes = await request(app)
242
+ .post('/api/products')
243
+ .set('Authorization', `Bearer ${adminToken}`)
244
+ .send({ ...VALID_PRODUCT, name: 'Produto Estoque', variants: [{ sku: 'STK-U', size: 'U', color: 'Azul', stock: 5 }] });
245
+
246
+ const productId = (createRes.body as { id: string }).id;
247
+ const variantId = (createRes.body as { variants: { id: string }[] }).variants[0]!.id;
248
+
249
+ const res = await request(app)
250
+ .patch(`/api/products/${productId}/stock`)
251
+ .set('Authorization', `Bearer ${adminToken}`)
252
+ .send({ variantId, delta: -2 });
253
+
254
+ expect(res.status).toBe(200);
255
+ expect(res.body.stock).toBe(3);
256
+ });
257
+
258
+ it('409: deve rejeitar quando estoque insuficiente', async () => {
259
+ const createRes = await request(app)
260
+ .post('/api/products')
261
+ .set('Authorization', `Bearer ${adminToken}`)
262
+ .send({ ...VALID_PRODUCT, name: 'Produto Estoque Zero', variants: [{ sku: 'STK0-U', size: 'U', color: 'Verde', stock: 2 }] });
263
+
264
+ const productId = (createRes.body as { id: string }).id;
265
+ const variantId = (createRes.body as { variants: { id: string }[] }).variants[0]!.id;
266
+
267
+ const res = await request(app)
268
+ .patch(`/api/products/${productId}/stock`)
269
+ .set('Authorization', `Bearer ${adminToken}`)
270
+ .send({ variantId, delta: -999 });
271
+
272
+ expect(res.status).toBe(409);
273
+ });
274
+ });
275
+ });
@@ -0,0 +1,223 @@
1
+ import { CatalogService } from '../catalog.service';
2
+ import { ICategoryRepository } from '../category.repository';
3
+ import { IProductRepository } from '../product.repository';
4
+ import { CategoryEntity } from '../category.entity';
5
+ import { ProductEntity, ProductStatus } from '../product.entity';
6
+
7
+ // ── Helpers ──────────────────────────────────────────────────────────────────
8
+ const makeCategory = (overrides: Partial<{ id: string; name: string; slug: string }> = {}) =>
9
+ CategoryEntity.reconstitute({
10
+ id: overrides.id ?? 'cat-1',
11
+ name: overrides.name ?? 'Camisetas',
12
+ slug: overrides.slug ?? 'camisetas',
13
+ description: null,
14
+ parentId: null,
15
+ createdAt: new Date(),
16
+ updatedAt: new Date(),
17
+ });
18
+
19
+ const makeProduct = (overrides: Partial<ReturnType<typeof ProductEntity.create>> = {}) =>
20
+ ProductEntity.reconstitute({
21
+ id: 'prod-1',
22
+ name: 'Camiseta Básica',
23
+ slug: 'camiseta-basica',
24
+ description: 'Uma camiseta simples',
25
+ price: 49.9,
26
+ categoryId: 'cat-1',
27
+ status: ProductStatus.ACTIVE,
28
+ images: [],
29
+ createdAt: new Date(),
30
+ updatedAt: new Date(),
31
+ variants: [
32
+ {
33
+ id: 'var-1',
34
+ sku: 'CAM-P',
35
+ size: 'P',
36
+ color: 'Branco',
37
+ stock: 10,
38
+ price: null,
39
+ productId: 'prod-1',
40
+ },
41
+ ],
42
+ });
43
+
44
+ // ── Mocks ────────────────────────────────────────────────────────────────────
45
+ const makeCategoryRepo = (): jest.Mocked<ICategoryRepository> => ({
46
+ findById: jest.fn(),
47
+ findBySlug: jest.fn(),
48
+ findAll: jest.fn(),
49
+ create: jest.fn(),
50
+ update: jest.fn(),
51
+ delete: jest.fn(),
52
+ });
53
+
54
+ const makeProductRepo = (): jest.Mocked<IProductRepository> => ({
55
+ findById: jest.fn(),
56
+ findBySlug: jest.fn(),
57
+ findAll: jest.fn(),
58
+ search: jest.fn(),
59
+ create: jest.fn(),
60
+ update: jest.fn(),
61
+ softDelete: jest.fn(),
62
+ updateVariantStock: jest.fn(),
63
+ slugExists: jest.fn(),
64
+ });
65
+
66
+ // ── Tests ────────────────────────────────────────────────────────────────────
67
+ describe('CatalogService — Unit', () => {
68
+ let service: CatalogService;
69
+ let categoryRepo: jest.Mocked<ICategoryRepository>;
70
+ let productRepo: jest.Mocked<IProductRepository>;
71
+
72
+ beforeEach(() => {
73
+ categoryRepo = makeCategoryRepo();
74
+ productRepo = makeProductRepo();
75
+ service = new CatalogService(categoryRepo, productRepo);
76
+ });
77
+
78
+ // ── createProduct ─────────────────────────────────────────────────────────
79
+ describe('createProduct()', () => {
80
+ const validInput = {
81
+ name: 'Camiseta Básica',
82
+ description: 'Desc',
83
+ price: 49.9,
84
+ categoryId: 'cat-1',
85
+ images: [],
86
+ variants: [{ sku: 'CAM-P', size: 'P', color: 'Branco', stock: 10 }],
87
+ };
88
+
89
+ it('deve criar produto com variações e estoque iniciais', async () => {
90
+ categoryRepo.findById.mockResolvedValue(makeCategory());
91
+ productRepo.slugExists.mockResolvedValue(false);
92
+ productRepo.create.mockImplementation(async (p) => p);
93
+
94
+ const result = await service.createProduct(validInput);
95
+
96
+ expect(result.name).toBe('Camiseta Básica');
97
+ expect(result.variants).toHaveLength(1);
98
+ expect(result.variants[0]?.stock).toBe(10);
99
+ expect(productRepo.create).toHaveBeenCalledTimes(1);
100
+ });
101
+
102
+ it('deve lançar erro se categoria não existir', async () => {
103
+ categoryRepo.findById.mockResolvedValue(null);
104
+
105
+ await expect(service.createProduct(validInput)).rejects.toMatchObject({
106
+ statusCode: 404,
107
+ });
108
+ });
109
+
110
+ it('deve garantir slug único a partir do nome', async () => {
111
+ categoryRepo.findById.mockResolvedValue(makeCategory());
112
+ // First slug attempt exists, second doesn't
113
+ productRepo.slugExists.mockResolvedValueOnce(true).mockResolvedValueOnce(false);
114
+ productRepo.create.mockImplementation(async (p) => p);
115
+
116
+ const result = await service.createProduct(validInput);
117
+
118
+ // Should have a slug derived from name + suffix to avoid collision
119
+ expect(result.slug).toMatch(/^camiseta-basica/);
120
+ expect(result.slug).not.toBe('camiseta-basica'); // original was taken
121
+ });
122
+
123
+ it('deve rejeitar preço negativo', async () => {
124
+ categoryRepo.findById.mockResolvedValue(makeCategory());
125
+
126
+ await expect(
127
+ service.createProduct({ ...validInput, price: -1 }),
128
+ ).rejects.toMatchObject({ statusCode: 422 });
129
+ });
130
+ });
131
+
132
+ // ── updateStock ──────────────────────────────────────────────────────────
133
+ describe('updateStock()', () => {
134
+ it('deve decrementar estoque de uma variação', async () => {
135
+ productRepo.findById.mockResolvedValue(makeProduct());
136
+ productRepo.updateVariantStock.mockResolvedValue(undefined);
137
+
138
+ await service.updateStock({ productId: 'prod-1', variantId: 'var-1', delta: -3 });
139
+
140
+ expect(productRepo.updateVariantStock).toHaveBeenCalledWith('prod-1', 'var-1', 7);
141
+ });
142
+
143
+ it('deve lançar InsufficientStockError se quantidade > estoque', async () => {
144
+ productRepo.findById.mockResolvedValue(makeProduct());
145
+
146
+ await expect(
147
+ service.updateStock({ productId: 'prod-1', variantId: 'var-1', delta: -999 }),
148
+ ).rejects.toMatchObject({ statusCode: 409 });
149
+ });
150
+
151
+ it('deve lançar erro 404 quando produto não existir', async () => {
152
+ productRepo.findById.mockResolvedValue(null);
153
+
154
+ await expect(
155
+ service.updateStock({ productId: 'nope', variantId: 'var-1', delta: -1 }),
156
+ ).rejects.toMatchObject({ statusCode: 404 });
157
+ });
158
+ });
159
+
160
+ // ── searchProducts ────────────────────────────────────────────────────────
161
+ describe('searchProducts()', () => {
162
+ const products = [makeProduct()];
163
+
164
+ it('deve filtrar por categoria', async () => {
165
+ productRepo.search.mockResolvedValue({ items: products, nextCursor: null });
166
+
167
+ const result = await service.searchProducts({ categoryId: 'cat-1' });
168
+
169
+ expect(productRepo.search).toHaveBeenCalledWith(
170
+ expect.objectContaining({ categoryId: 'cat-1' }),
171
+ );
172
+ expect(result.items).toHaveLength(1);
173
+ });
174
+
175
+ it('deve filtrar por faixa de preço', async () => {
176
+ productRepo.search.mockResolvedValue({ items: products, nextCursor: null });
177
+
178
+ const result = await service.searchProducts({ minPrice: 10, maxPrice: 100 });
179
+
180
+ expect(productRepo.search).toHaveBeenCalledWith(
181
+ expect.objectContaining({ minPrice: 10, maxPrice: 100 }),
182
+ );
183
+ expect(result.items).toBeDefined();
184
+ });
185
+
186
+ it('deve buscar por nome (full-text via q)', async () => {
187
+ productRepo.search.mockResolvedValue({ items: products, nextCursor: null });
188
+
189
+ await service.searchProducts({ q: 'camiseta' });
190
+
191
+ expect(productRepo.search).toHaveBeenCalledWith(
192
+ expect.objectContaining({ q: 'camiseta' }),
193
+ );
194
+ });
195
+
196
+ it('deve paginar corretamente com cursor', async () => {
197
+ productRepo.search.mockResolvedValue({ items: products, nextCursor: 'abc123' });
198
+
199
+ const result = await service.searchProducts({ cursor: 'prev-cursor', limit: 10 });
200
+
201
+ expect(result.nextCursor).toBe('abc123');
202
+ });
203
+
204
+ it('deve ordenar por preço asc/desc e por mais recente', async () => {
205
+ productRepo.search.mockResolvedValue({ items: [], nextCursor: null });
206
+
207
+ await service.searchProducts({ sortBy: 'price_asc' });
208
+ expect(productRepo.search).toHaveBeenCalledWith(
209
+ expect.objectContaining({ sortBy: 'price_asc' }),
210
+ );
211
+
212
+ await service.searchProducts({ sortBy: 'price_desc' });
213
+ expect(productRepo.search).toHaveBeenCalledWith(
214
+ expect.objectContaining({ sortBy: 'price_desc' }),
215
+ );
216
+
217
+ await service.searchProducts({ sortBy: 'newest' });
218
+ expect(productRepo.search).toHaveBeenCalledWith(
219
+ expect.objectContaining({ sortBy: 'newest' }),
220
+ );
221
+ });
222
+ });
223
+ });
@@ -0,0 +1,130 @@
1
+ import request from 'supertest';
2
+ import app from '../../../app';
3
+ import { UserEntity } from '../../auth/user.entity';
4
+ import { hash } from 'bcryptjs';
5
+
6
+ /**
7
+ * Integration tests for POST /api/products/:id/image
8
+ * Uses in-memory repos + in-memory storage (no S3 needed)
9
+ */
10
+
11
+ let adminToken: string;
12
+ let productId: string;
13
+
14
+ const ADMIN_USER = {
15
+ name: 'Admin Image',
16
+ email: 'admin.image@test.com',
17
+ password: 'admin1234',
18
+ };
19
+
20
+ const VALID_PRODUCT = {
21
+ name: 'Tênis de Upload',
22
+ description: 'Para testar upload',
23
+ price: 199.9,
24
+ categorySlug: 'calcados',
25
+ images: [],
26
+ variants: [{ sku: 'TEI-40', size: '40', color: 'Preto', stock: 5 }],
27
+ };
28
+
29
+ beforeAll(async () => {
30
+ const { catalogRegistry } = await import('../catalog.registry');
31
+ const { userRepository } = await import('../../auth/auth.registry');
32
+
33
+ // Seed category
34
+ const { CategoryEntity } = await import('../category.entity');
35
+ await catalogRegistry.categoryRepository.create(
36
+ CategoryEntity.create({ name: 'Calçados', slug: 'calcados', description: null, parentId: null }),
37
+ );
38
+
39
+ // Create admin directly
40
+ const adminHash = await hash(ADMIN_USER.password, 10);
41
+ await userRepository.create(
42
+ UserEntity.create({ name: ADMIN_USER.name, email: ADMIN_USER.email, passwordHash: adminHash, role: 'ADMIN' }),
43
+ );
44
+
45
+ // Login
46
+ const loginRes = await request(app).post('/api/auth/login').send({
47
+ email: ADMIN_USER.email,
48
+ password: ADMIN_USER.password,
49
+ });
50
+ adminToken = (loginRes.body as { accessToken: string }).accessToken;
51
+
52
+ // Create a product to upload to
53
+ const productRes = await request(app)
54
+ .post('/api/products')
55
+ .set('Authorization', `Bearer ${adminToken}`)
56
+ .send(VALID_PRODUCT);
57
+ productId = (productRes.body as { id: string }).id;
58
+ });
59
+
60
+ describe('POST /api/products/:id/image', () => {
61
+ it('401: deve rejeitar sem autenticação', async () => {
62
+ await request(app)
63
+ .post(`/api/products/${productId}/image`)
64
+ .attach('image', Buffer.from('fake'), { filename: 'foto.jpg', contentType: 'image/jpeg' })
65
+ .expect(401);
66
+ });
67
+
68
+ it('403: deve rejeitar se não for ADMIN', async () => {
69
+ // Register a customer
70
+ await request(app).post('/api/auth/register').send({
71
+ name: 'Cliente',
72
+ email: 'cliente.img@test.com',
73
+ password: 'cliente1234',
74
+ });
75
+ const loginRes = await request(app).post('/api/auth/login').send({
76
+ email: 'cliente.img@test.com',
77
+ password: 'cliente1234',
78
+ });
79
+ const customerToken = (loginRes.body as { accessToken: string }).accessToken;
80
+
81
+ await request(app)
82
+ .post(`/api/products/${productId}/image`)
83
+ .set('Authorization', `Bearer ${customerToken}`)
84
+ .attach('image', Buffer.from('fake'), { filename: 'foto.jpg', contentType: 'image/jpeg' })
85
+ .expect(403);
86
+ });
87
+
88
+ it('400: deve rejeitar arquivo não-imagem', async () => {
89
+ await request(app)
90
+ .post(`/api/products/${productId}/image`)
91
+ .set('Authorization', `Bearer ${adminToken}`)
92
+ .attach('image', Buffer.from('text content'), { filename: 'doc.txt', contentType: 'text/plain' })
93
+ .expect(400);
94
+ });
95
+
96
+ it('400: deve rejeitar arquivo maior que 5MB', async () => {
97
+ const bigBuffer = Buffer.alloc(6 * 1024 * 1024);
98
+ await request(app)
99
+ .post(`/api/products/${productId}/image`)
100
+ .set('Authorization', `Bearer ${adminToken}`)
101
+ .attach('image', bigBuffer, { filename: 'big.jpg', contentType: 'image/jpeg' })
102
+ .expect(400);
103
+ });
104
+
105
+ it('200: deve fazer upload e retornar URL pública da imagem', async () => {
106
+ const res = await request(app)
107
+ .post(`/api/products/${productId}/image`)
108
+ .set('Authorization', `Bearer ${adminToken}`)
109
+ .attach('image', Buffer.from('fake-image-data'), { filename: 'foto.jpg', contentType: 'image/jpeg' })
110
+ .expect(200);
111
+
112
+ const body = res.body as { images: string[] };
113
+ expect(body.images).toBeDefined();
114
+ expect(body.images.length).toBeGreaterThan(0);
115
+ expect(typeof body.images[0]).toBe('string');
116
+ });
117
+
118
+ it('deve atualizar campo images no produto após upload', async () => {
119
+ // Upload
120
+ await request(app)
121
+ .post(`/api/products/${productId}/image`)
122
+ .set('Authorization', `Bearer ${adminToken}`)
123
+ .attach('image', Buffer.from('image-bytes'), { filename: 'produto.png', contentType: 'image/png' });
124
+
125
+ // Fetch product and check images
126
+ const getRes = await request(app).get(`/api/products/tenis-de-upload`).expect(200);
127
+ const product = getRes.body as { images: string[] };
128
+ expect(product.images.length).toBeGreaterThanOrEqual(1);
129
+ });
130
+ });