From d7bd69eb5f2c2606add962eec97c74357b6f122d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Fri, 12 Feb 2021 12:25:03 +0300 Subject: [PATCH] added export/ bulk action export and import feature test for payments.. --- tests/Feature/Purchases/PaymentsTest.php | 66 ++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/Feature/Purchases/PaymentsTest.php b/tests/Feature/Purchases/PaymentsTest.php index 8cc680296..11a6ea6ab 100644 --- a/tests/Feature/Purchases/PaymentsTest.php +++ b/tests/Feature/Purchases/PaymentsTest.php @@ -2,8 +2,11 @@ namespace Tests\Feature\Purchases; +use App\Exports\Purchases\Payments as Export; use App\Jobs\Banking\CreateTransaction; use App\Models\Banking\Transaction; +use Illuminate\Http\UploadedFile; +use Illuminate\Support\Facades\File; use Tests\Feature\FeatureTestCase; class PaymentsTest extends FeatureTestCase @@ -82,6 +85,69 @@ class PaymentsTest extends FeatureTestCase $this->assertSoftDeleted('transactions', $request); } + public function testItShouldExportPayments() + { + $count = 5; + Transaction::factory()->expense()->count($count)->create(); + + \Excel::fake(); + + $this->loginAs() + ->get(route('payments.export')) + ->assertStatus(200); + + \Excel::assertDownloaded( + \Str::filename(trans_choice('general.payments', 2)) . '.xlsx', + function (Export $export) use ($count) { + // Assert that the correct export is downloaded. + return $export->collection()->count() === $count; + } + ); + } + + public function testItShouldExportSelectedPayments() + { + $count = 5; + $payments = Transaction::factory()->expense()->count($count)->create(); + + \Excel::fake(); + + $this->loginAs() + ->post( + route('bulk-actions.action', ['group' => 'purchases', 'type' => 'payments']), + ['handle' => 'export', 'selected' => [$payments->random()->id]] + ) + ->assertStatus(200); + + \Excel::assertDownloaded( + \Str::filename(trans_choice('general.payments', 2)) . '.xlsx', + function (Export $export) { + return $export->collection()->count() === 1; + } + ); + } + + public function testItShouldImportPayments() + { + \Excel::fake(); + + $this->loginAs() + ->post( + route('payments.import'), + [ + 'import' => UploadedFile::fake()->createWithContent( + 'payments.xlsx', + File::get(public_path('files/import/payments.xlsx')) + ), + ] + ) + ->assertStatus(200); + + \Excel::assertImported('payments.xlsx'); + + $this->assertFlashLevel('success'); + } + public function getRequest() { return Transaction::factory()->expense()->raw();