|
|
@@ -2,12 +2,15 @@
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
+use App\Jobs\ExportReclamationsJob;
|
|
|
+use App\Jobs\GenerateReclamationPaymentPack;
|
|
|
use App\Models\File;
|
|
|
use App\Models\Order;
|
|
|
use App\Models\Product;
|
|
|
use App\Models\ProductSKU;
|
|
|
use App\Models\Reclamation;
|
|
|
use App\Models\ReclamationDetail;
|
|
|
+use App\Models\ReclamationType;
|
|
|
use App\Models\Reservation;
|
|
|
use App\Models\Role;
|
|
|
use App\Models\SparePart;
|
|
|
@@ -15,7 +18,9 @@ use App\Models\SparePartOrder;
|
|
|
use App\Models\User;
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
use Illuminate\Http\UploadedFile;
|
|
|
+use Illuminate\Support\Facades\Bus;
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
+use ReflectionProperty;
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
class ReclamationControllerTest extends TestCase
|
|
|
@@ -67,6 +72,55 @@ class ReclamationControllerTest extends TestCase
|
|
|
$response->assertStatus(200);
|
|
|
}
|
|
|
|
|
|
+ public function test_all_tab_displays_reclamations_of_every_type(): void
|
|
|
+ {
|
|
|
+ $dkr = Reclamation::factory()->dkr()->create(['reason' => 'Рекламация ДКР для общего списка']);
|
|
|
+ $other = Reclamation::factory()->other()->create(['reason' => 'Прочая рекламация для общего списка']);
|
|
|
+
|
|
|
+ $response = $this->actingAs($this->managerUser)
|
|
|
+ ->get(route('reclamations.index'));
|
|
|
+
|
|
|
+ $response->assertOk()
|
|
|
+ ->assertViewHas('tab', 'all')
|
|
|
+ ->assertSee($dkr->reason)
|
|
|
+ ->assertSee($other->reason);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function test_dkr_tab_displays_only_dkr_reclamations(): void
|
|
|
+ {
|
|
|
+ $dkr = Reclamation::factory()->dkr()->create(['reason' => 'Рекламация только вкладки ДКР']);
|
|
|
+ $other = Reclamation::factory()->other()->create(['reason' => 'Рекламация типа Прочее']);
|
|
|
+
|
|
|
+ $response = $this->actingAs($this->managerUser)
|
|
|
+ ->get(route('reclamations.index', ['tab' => 'dkr']));
|
|
|
+
|
|
|
+ $response->assertOk()
|
|
|
+ ->assertViewHas('tab', ReclamationType::CODE_DKR)
|
|
|
+ ->assertSee($dkr->reason)
|
|
|
+ ->assertDontSee($other->reason);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function test_export_with_dkr_tab_filter_contains_only_dkr_reclamations(): void
|
|
|
+ {
|
|
|
+ Bus::fake();
|
|
|
+
|
|
|
+ $dkr = Reclamation::factory()->dkr()->create();
|
|
|
+ Reclamation::factory()->other()->create();
|
|
|
+
|
|
|
+ $response = $this->actingAs($this->managerUser)
|
|
|
+ ->post(route('reclamations.export'), [
|
|
|
+ 'withFilter' => '1',
|
|
|
+ 'tab' => ReclamationType::CODE_DKR,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $response->assertRedirect();
|
|
|
+ Bus::assertDispatched(ExportReclamationsJob::class, function (ExportReclamationsJob $job) use ($dkr) {
|
|
|
+ $property = new ReflectionProperty($job, 'reclamationIds');
|
|
|
+
|
|
|
+ return $property->getValue($job) === [$dkr->id];
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
public function test_brigadier_sees_only_assigned_reclamations_with_allowed_statuses(): void
|
|
|
{
|
|
|
$visibleReclamation = Reclamation::factory()->create([
|
|
|
@@ -116,11 +170,33 @@ class ReclamationControllerTest extends TestCase
|
|
|
|
|
|
$this->assertDatabaseHas('reclamations', [
|
|
|
'order_id' => $order->id,
|
|
|
+ 'reclamation_type_id' => ReclamationType::idForCode(ReclamationType::CODE_DKR),
|
|
|
'user_id' => $this->managerUser->id,
|
|
|
'status_id' => Reclamation::STATUS_NEW,
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+ public function test_creating_reclamation_from_dkr_order_ignores_spoofed_type(): void
|
|
|
+ {
|
|
|
+ $order = Order::factory()->create();
|
|
|
+ $productSku = ProductSKU::factory()->create([
|
|
|
+ 'order_id' => $order->id,
|
|
|
+ 'product_id' => Product::factory(),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $this->actingAs($this->managerUser)
|
|
|
+ ->post(route('reclamations.create', $order), [
|
|
|
+ 'skus' => [$productSku->id],
|
|
|
+ 'reclamation_type_id' => ReclamationType::idForCode(ReclamationType::CODE_OTHER),
|
|
|
+ ])
|
|
|
+ ->assertRedirect();
|
|
|
+
|
|
|
+ $this->assertDatabaseHas('reclamations', [
|
|
|
+ 'order_id' => $order->id,
|
|
|
+ 'reclamation_type_id' => ReclamationType::idForCode(ReclamationType::CODE_DKR),
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
public function test_creating_reclamation_from_order_preserves_nav_token(): void
|
|
|
{
|
|
|
$order = Order::factory()->create();
|
|
|
@@ -187,6 +263,26 @@ class ReclamationControllerTest extends TestCase
|
|
|
$response->assertViewIs('reclamations.edit');
|
|
|
}
|
|
|
|
|
|
+ public function test_reclamation_card_displays_type_and_payment_action_only_for_dkr(): void
|
|
|
+ {
|
|
|
+ $dkr = Reclamation::factory()->dkr()->create();
|
|
|
+ $other = Reclamation::factory()->other()->create();
|
|
|
+
|
|
|
+ $this->actingAs($this->managerUser)
|
|
|
+ ->get(route('reclamations.show', $dkr))
|
|
|
+ ->assertOk()
|
|
|
+ ->assertSee('Тип рекламации')
|
|
|
+ ->assertSee('ДКР')
|
|
|
+ ->assertSee('Пакет документов на оплату');
|
|
|
+
|
|
|
+ $this->actingAs($this->managerUser)
|
|
|
+ ->get(route('reclamations.show', $other))
|
|
|
+ ->assertOk()
|
|
|
+ ->assertSee('Тип рекламации')
|
|
|
+ ->assertSee('Прочее')
|
|
|
+ ->assertDontSee('Пакет документов на оплату');
|
|
|
+ }
|
|
|
+
|
|
|
public function test_reclamation_show_uses_nav_context_for_back_url(): void
|
|
|
{
|
|
|
$reclamation = Reclamation::factory()->create();
|
|
|
@@ -849,6 +945,31 @@ class ReclamationControllerTest extends TestCase
|
|
|
$response->assertSessionHas('success');
|
|
|
}
|
|
|
|
|
|
+ public function test_can_generate_reclamation_payment_pack_for_dkr(): void
|
|
|
+ {
|
|
|
+ Bus::fake([GenerateReclamationPaymentPack::class]);
|
|
|
+ $reclamation = Reclamation::factory()->dkr()->create();
|
|
|
+
|
|
|
+ $this->actingAs($this->managerUser)
|
|
|
+ ->get(route('reclamation.generate-reclamation-payment-pack', $reclamation))
|
|
|
+ ->assertRedirect()
|
|
|
+ ->assertSessionHas('success');
|
|
|
+
|
|
|
+ Bus::assertDispatched(GenerateReclamationPaymentPack::class);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function test_cannot_generate_reclamation_payment_pack_for_other_type(): void
|
|
|
+ {
|
|
|
+ Bus::fake([GenerateReclamationPaymentPack::class]);
|
|
|
+ $reclamation = Reclamation::factory()->other()->create();
|
|
|
+
|
|
|
+ $this->actingAs($this->managerUser)
|
|
|
+ ->get(route('reclamation.generate-reclamation-payment-pack', $reclamation))
|
|
|
+ ->assertForbidden();
|
|
|
+
|
|
|
+ Bus::assertNotDispatched(GenerateReclamationPaymentPack::class);
|
|
|
+ }
|
|
|
+
|
|
|
public function test_can_generate_photos_before_pack(): void
|
|
|
{
|
|
|
$reclamation = Reclamation::factory()->create();
|