diff --git a/tests/Feature/Sales/CustomersTest.php b/tests/Feature/Sales/CustomersTest.php index 0c6a908fc..abb932adf 100644 --- a/tests/Feature/Sales/CustomersTest.php +++ b/tests/Feature/Sales/CustomersTest.php @@ -155,7 +155,7 @@ class CustomersTest extends FeatureTestCase $this->loginAs() ->post( - route('bulk-actions.action', ['group' => 'purchases', 'type' => 'customers']), + route('bulk-actions.action', ['group' => 'sales', 'type' => 'customers']), ['handle' => 'export', 'selected' => [$customers->random()->id]] ) ->assertStatus(200); diff --git a/tests/Feature/Sales/InvoicesTest.php b/tests/Feature/Sales/InvoicesTest.php index e58dd0052..5ead4eaa9 100644 --- a/tests/Feature/Sales/InvoicesTest.php +++ b/tests/Feature/Sales/InvoicesTest.php @@ -2,8 +2,11 @@ namespace Tests\Feature\Sales; +use App\Exports\Sales\Invoices as Export; use App\Jobs\Document\CreateDocument; use App\Models\Document\Document; +use Illuminate\Http\UploadedFile; +use Illuminate\Support\Facades\File; use Tests\Feature\FeatureTestCase; class InvoicesTest extends FeatureTestCase @@ -115,6 +118,69 @@ class InvoicesTest extends FeatureTestCase ]); } + public function testItShouldExportInvoices() + { + $count = 5; + Document::factory()->invoice()->count($count)->create(); + + \Excel::fake(); + + $this->loginAs() + ->get(route('invoices.export')) + ->assertStatus(200); + + \Excel::assertDownloaded( + \Str::filename(trans_choice('general.invoices', 2)) . '.xlsx', + function (Export $export) use ($count) { + // Assert that the correct export is downloaded. + return $export->sheets()['invoices']->collection()->count() === $count; + } + ); + } + + public function testItShouldExportSelectedInvoices() + { + $count = 5; + $invoices = Document::factory()->invoice()->count($count)->create(); + + \Excel::fake(); + + $this->loginAs() + ->post( + route('bulk-actions.action', ['group' => 'sales', 'type' => 'invoices']), + ['handle' => 'export', 'selected' => [$invoices->random()->id]] + ) + ->assertStatus(200); + + \Excel::assertDownloaded( + \Str::filename(trans_choice('general.invoices', 2)) . '.xlsx', + function (Export $export) { + return $export->sheets()['invoices']->collection()->count() === 1; + } + ); + } + + public function testItShouldImportInvoices() + { + \Excel::fake(); + + $this->loginAs() + ->post( + route('invoices.import'), + [ + 'import' => UploadedFile::fake()->createWithContent( + 'invoices.xlsx', + File::get(public_path('files/import/invoices.xlsx')) + ), + ] + ) + ->assertStatus(200); + + \Excel::assertImported('invoices.xlsx'); + + $this->assertFlashLevel('success'); + } + public function getRequest($recurring = false) { $factory = Document::factory();