ProductVisibleFranchiseeTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Tests\Unit;
  3. use App\Http\Requests\ProductRequest;
  4. use App\Models\Product;
  5. use App\Services\ProductService;
  6. use Illuminate\Foundation\Testing\RefreshDatabase;
  7. use Illuminate\Support\Facades\Validator;
  8. use Tests\TestCase;
  9. /**
  10. * Regressão: produtos não apareciam pra franqueada porque visible_franchisee
  11. * nunca estava nas rules() do ProductRequest — o toggle "Visível para
  12. * Franqueado" do cadastro de produto era descartado antes de chegar no
  13. * banco, então todo produto ficava com visible_franchisee=false (default da
  14. * coluna), e o filtro `visible_franchisee=true` usado na tela de Proposta
  15. * Comercial da franqueada nunca retornava nada.
  16. */
  17. class ProductVisibleFranchiseeTest extends TestCase
  18. {
  19. use RefreshDatabase;
  20. public function test_request_accepts_visible_franchisee(): void
  21. {
  22. $request = ProductRequest::create('/product', 'POST', [
  23. 'name' => 'Produto Teste',
  24. 'price_sale' => 10,
  25. 'quantity' => 1,
  26. 'visible_franchisee' => true,
  27. ]);
  28. $validator = Validator::make($request->all(), $request->rules());
  29. $this->assertFalse($validator->fails());
  30. }
  31. public function test_service_persists_visible_franchisee_and_select_filter_finds_it(): void
  32. {
  33. $service = new ProductService();
  34. $service->create([
  35. 'name' => 'Visível pro Franqueado',
  36. 'price_sale' => 10,
  37. 'quantity' => 1,
  38. 'visible_franchisee' => true,
  39. ]);
  40. $service->create([
  41. 'name' => 'Só Franqueadora',
  42. 'price_sale' => 10,
  43. 'quantity' => 1,
  44. 'visible_franchisee' => false,
  45. ]);
  46. $visibleForFranchisee = Product::query()->where('visible_franchisee', true)->pluck('name');
  47. $this->assertSame(['Visível pro Franqueado'], $visibleForFranchisee->all());
  48. }
  49. }