Merge pull request #1851 from cuneytsenturk/master
Added import/export, bulk action export feature test
This commit is contained in:
commit
e5eb41025b
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
namespace Tests\Feature\Common;
|
namespace Tests\Feature\Common;
|
||||||
|
|
||||||
|
use App\Exports\Common\Items as Export;
|
||||||
use App\Jobs\Common\CreateItem;
|
use App\Jobs\Common\CreateItem;
|
||||||
use App\Models\Common\Item;
|
use App\Models\Common\Item;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
use Tests\Feature\FeatureTestCase;
|
use Tests\Feature\FeatureTestCase;
|
||||||
|
|
||||||
class ItemsTest extends FeatureTestCase
|
class ItemsTest extends FeatureTestCase
|
||||||
@ -82,6 +85,69 @@ class ItemsTest extends FeatureTestCase
|
|||||||
$this->assertSoftDeleted('items', $request);
|
$this->assertSoftDeleted('items', $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItShouldExportItems()
|
||||||
|
{
|
||||||
|
$count = 5;
|
||||||
|
Item::factory()->count($count)->create();
|
||||||
|
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->get(route('items.export'))
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertDownloaded(
|
||||||
|
\Str::filename(trans_choice('general.items', 2)) . '.xlsx',
|
||||||
|
function (Export $export) use ($count) {
|
||||||
|
// Assert that the correct export is downloaded.
|
||||||
|
return $export->sheets()['items']->collection()->count() === $count;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItShouldExportSelectedItems()
|
||||||
|
{
|
||||||
|
$count = 5;
|
||||||
|
$items = Item::factory()->count($count)->create();
|
||||||
|
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->post(
|
||||||
|
route('bulk-actions.action', ['group' => 'common', 'type' => 'items']),
|
||||||
|
['handle' => 'export', 'selected' => [$items->random()->id]]
|
||||||
|
)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertDownloaded(
|
||||||
|
\Str::filename(trans_choice('general.items', 2)) . '.xlsx',
|
||||||
|
function (Export $export) {
|
||||||
|
return $export->sheets()['items']->collection()->count() === 1;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItShouldImportItems()
|
||||||
|
{
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->post(
|
||||||
|
route('items.import'),
|
||||||
|
[
|
||||||
|
'import' => UploadedFile::fake()->createWithContent(
|
||||||
|
'items.xlsx',
|
||||||
|
File::get(public_path('files/import/items.xlsx'))
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertImported('items.xlsx');
|
||||||
|
|
||||||
|
$this->assertFlashLevel('success');
|
||||||
|
}
|
||||||
|
|
||||||
public function getRequest()
|
public function getRequest()
|
||||||
{
|
{
|
||||||
return Item::factory()->enabled()->raw();
|
return Item::factory()->enabled()->raw();
|
||||||
|
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
namespace Tests\Feature\Purchases;
|
namespace Tests\Feature\Purchases;
|
||||||
|
|
||||||
|
use App\Exports\Purchases\Bills as Export;
|
||||||
use App\Jobs\Document\CreateDocument;
|
use App\Jobs\Document\CreateDocument;
|
||||||
use App\Models\Document\Document;
|
use App\Models\Document\Document;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
use Tests\Feature\FeatureTestCase;
|
use Tests\Feature\FeatureTestCase;
|
||||||
|
|
||||||
class BillsTest extends FeatureTestCase
|
class BillsTest extends FeatureTestCase
|
||||||
@ -104,6 +107,69 @@ class BillsTest extends FeatureTestCase
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItShouldExportBills()
|
||||||
|
{
|
||||||
|
$count = 5;
|
||||||
|
Document::factory()->bill()->count($count)->create();
|
||||||
|
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->get(route('bills.export'))
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertDownloaded(
|
||||||
|
\Str::filename(trans_choice('general.bills', 2)) . '.xlsx',
|
||||||
|
function (Export $export) use ($count) {
|
||||||
|
// Assert that the correct export is downloaded.
|
||||||
|
return $export->sheets()['bills']->collection()->count() === $count;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItShouldExportSelectedBills()
|
||||||
|
{
|
||||||
|
$count = 5;
|
||||||
|
$bills = Document::factory()->bill()->count($count)->create();
|
||||||
|
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->post(
|
||||||
|
route('bulk-actions.action', ['group' => 'purchases', 'type' => 'bills']),
|
||||||
|
['handle' => 'export', 'selected' => [$bills->random()->id]]
|
||||||
|
)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertDownloaded(
|
||||||
|
\Str::filename(trans_choice('general.bills', 2)) . '.xlsx',
|
||||||
|
function (Export $export) {
|
||||||
|
return $export->sheets()['bills']->collection()->count() === 1;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItShouldImportBills()
|
||||||
|
{
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->post(
|
||||||
|
route('bills.import'),
|
||||||
|
[
|
||||||
|
'import' => UploadedFile::fake()->createWithContent(
|
||||||
|
'bills.xlsx',
|
||||||
|
File::get(public_path('files/import/bills.xlsx'))
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertImported('bills.xlsx');
|
||||||
|
|
||||||
|
$this->assertFlashLevel('success');
|
||||||
|
}
|
||||||
|
|
||||||
public function getRequest($recurring = false)
|
public function getRequest($recurring = false)
|
||||||
{
|
{
|
||||||
$factory = Document::factory();
|
$factory = Document::factory();
|
||||||
|
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
namespace Tests\Feature\Purchases;
|
namespace Tests\Feature\Purchases;
|
||||||
|
|
||||||
|
use App\Exports\Purchases\Payments as Export;
|
||||||
use App\Jobs\Banking\CreateTransaction;
|
use App\Jobs\Banking\CreateTransaction;
|
||||||
use App\Models\Banking\Transaction;
|
use App\Models\Banking\Transaction;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
use Tests\Feature\FeatureTestCase;
|
use Tests\Feature\FeatureTestCase;
|
||||||
|
|
||||||
class PaymentsTest extends FeatureTestCase
|
class PaymentsTest extends FeatureTestCase
|
||||||
@ -82,6 +85,69 @@ class PaymentsTest extends FeatureTestCase
|
|||||||
$this->assertSoftDeleted('transactions', $request);
|
$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()
|
public function getRequest()
|
||||||
{
|
{
|
||||||
return Transaction::factory()->expense()->raw();
|
return Transaction::factory()->expense()->raw();
|
||||||
|
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
namespace Tests\Feature\Purchases;
|
namespace Tests\Feature\Purchases;
|
||||||
|
|
||||||
|
use App\Exports\Purchases\Vendors as Export;
|
||||||
use App\Jobs\Common\CreateContact;
|
use App\Jobs\Common\CreateContact;
|
||||||
use App\Models\Common\Contact;
|
use App\Models\Common\Contact;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
use Tests\Feature\FeatureTestCase;
|
use Tests\Feature\FeatureTestCase;
|
||||||
|
|
||||||
class VendorsTest extends FeatureTestCase
|
class VendorsTest extends FeatureTestCase
|
||||||
@ -96,6 +99,69 @@ class VendorsTest extends FeatureTestCase
|
|||||||
$this->assertSoftDeleted('contacts', $request);
|
$this->assertSoftDeleted('contacts', $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItShouldExportVendors()
|
||||||
|
{
|
||||||
|
$count = 5;
|
||||||
|
Contact::factory()->vendor()->count($count)->create();
|
||||||
|
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->get(route('vendors.export'))
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertDownloaded(
|
||||||
|
\Str::filename(trans_choice('general.vendors', 2)) . '.xlsx',
|
||||||
|
function (Export $export) use ($count) {
|
||||||
|
// Assert that the correct export is downloaded.
|
||||||
|
return $export->collection()->count() === $count;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItShouldExportSelectedVendors()
|
||||||
|
{
|
||||||
|
$count = 5;
|
||||||
|
$vendors = Contact::factory()->vendor()->count($count)->create();
|
||||||
|
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->post(
|
||||||
|
route('bulk-actions.action', ['group' => 'purchases', 'type' => 'vendors']),
|
||||||
|
['handle' => 'export', 'selected' => [$vendors->random()->id]]
|
||||||
|
)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertDownloaded(
|
||||||
|
\Str::filename(trans_choice('general.vendors', 2)) . '.xlsx',
|
||||||
|
function (Export $export) {
|
||||||
|
return $export->collection()->count() === 1;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItShouldImportVendors()
|
||||||
|
{
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->post(
|
||||||
|
route('vendors.import'),
|
||||||
|
[
|
||||||
|
'import' => UploadedFile::fake()->createWithContent(
|
||||||
|
'vendors.xlsx',
|
||||||
|
File::get(public_path('files/import/vendors.xlsx'))
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertImported('vendors.xlsx');
|
||||||
|
|
||||||
|
$this->assertFlashLevel('success');
|
||||||
|
}
|
||||||
|
|
||||||
public function getRequest()
|
public function getRequest()
|
||||||
{
|
{
|
||||||
return Contact::factory()->vendor()->enabled()->raw();
|
return Contact::factory()->vendor()->enabled()->raw();
|
||||||
|
@ -2,136 +2,201 @@
|
|||||||
|
|
||||||
namespace Tests\Feature\Sales;
|
namespace Tests\Feature\Sales;
|
||||||
|
|
||||||
|
use App\Exports\Sales\Customers as Export;
|
||||||
use App\Jobs\Common\CreateContact;
|
use App\Jobs\Common\CreateContact;
|
||||||
use App\Models\Auth\User;
|
use App\Models\Auth\User;
|
||||||
use App\Models\Common\Contact;
|
use App\Models\Common\Contact;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
use Tests\Feature\FeatureTestCase;
|
use Tests\Feature\FeatureTestCase;
|
||||||
|
|
||||||
class CustomersTest extends FeatureTestCase
|
class CustomersTest extends FeatureTestCase
|
||||||
{
|
{
|
||||||
public function testItShouldSeeCustomerListPage()
|
public function testItShouldSeeCustomerListPage()
|
||||||
{
|
{
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->get(route('customers.index'))
|
->get(route('customers.index'))
|
||||||
->assertStatus(200)
|
->assertStatus(200)
|
||||||
->assertSeeText(trans_choice('general.customers', 2));
|
->assertSeeText(trans_choice('general.customers', 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItShouldSeeCustomerCreatePage()
|
public function testItShouldSeeCustomerCreatePage()
|
||||||
{
|
{
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->get(route('customers.create'))
|
->get(route('customers.create'))
|
||||||
->assertStatus(200)
|
->assertStatus(200)
|
||||||
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.customers', 1)]));
|
->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.customers', 1)]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItShouldCreateCustomer()
|
public function testItShouldCreateCustomer()
|
||||||
{
|
{
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->post(route('customers.store'), $request)
|
->post(route('customers.store'), $request)
|
||||||
->assertStatus(200);
|
->assertStatus(200);
|
||||||
|
|
||||||
$this->assertFlashLevel('success');
|
$this->assertFlashLevel('success');
|
||||||
|
|
||||||
$this->assertDatabaseHas('contacts', $request);
|
$this->assertDatabaseHas('contacts', $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItShouldCreateCustomerWithUser()
|
public function testItShouldCreateCustomerWithUser()
|
||||||
{
|
{
|
||||||
$request = $this->getRequestWithUser();
|
$request = $this->getRequestWithUser();
|
||||||
|
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->post(route('customers.store'), $request)
|
->post(route('customers.store'), $request)
|
||||||
->assertStatus(200);
|
->assertStatus(200);
|
||||||
|
|
||||||
$this->assertFlashLevel('success');
|
$this->assertFlashLevel('success');
|
||||||
|
|
||||||
$user = User::where('email', $request['email'])->first();
|
$user = User::where('email', $request['email'])->first();
|
||||||
|
|
||||||
$this->assertNotNull($user);
|
$this->assertNotNull($user);
|
||||||
$this->assertEquals($request['email'], $user->email);
|
$this->assertEquals($request['email'], $user->email);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItShouldSeeCustomerDetailPage()
|
public function testItShouldSeeCustomerDetailPage()
|
||||||
{
|
{
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
$customer = $this->dispatch(new CreateContact($request));
|
$customer = $this->dispatch(new CreateContact($request));
|
||||||
|
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->get(route('customers.show', $customer->id))
|
->get(route('customers.show', $customer->id))
|
||||||
->assertStatus(200)
|
->assertStatus(200)
|
||||||
->assertSee($customer->email);
|
->assertSee($customer->email);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItShouldSeeCustomerUpdatePage()
|
public function testItShouldSeeCustomerUpdatePage()
|
||||||
{
|
{
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
$customer = $this->dispatch(new CreateContact($request));
|
$customer = $this->dispatch(new CreateContact($request));
|
||||||
|
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->get(route('customers.edit', $customer->id))
|
->get(route('customers.edit', $customer->id))
|
||||||
->assertStatus(200)
|
->assertStatus(200)
|
||||||
->assertSee($customer->email);
|
->assertSee($customer->email);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItShouldUpdateCustomer()
|
public function testItShouldUpdateCustomer()
|
||||||
{
|
{
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
$customer = $this->dispatch(new CreateContact($request));
|
$customer = $this->dispatch(new CreateContact($request));
|
||||||
|
|
||||||
$request['email'] = $this->faker->safeEmail;
|
$request['email'] = $this->faker->safeEmail;
|
||||||
|
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->patch(route('customers.update', $customer->id), $request)
|
->patch(route('customers.update', $customer->id), $request)
|
||||||
->assertStatus(200)
|
->assertStatus(200)
|
||||||
->assertSee($request['email']);
|
->assertSee($request['email']);
|
||||||
|
|
||||||
$this->assertFlashLevel('success');
|
$this->assertFlashLevel('success');
|
||||||
|
|
||||||
$this->assertDatabaseHas('contacts', $request);
|
$this->assertDatabaseHas('contacts', $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItShouldDeleteCustomer()
|
public function testItShouldDeleteCustomer()
|
||||||
{
|
{
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
$customer = $this->dispatch(new CreateContact($request));
|
$customer = $this->dispatch(new CreateContact($request));
|
||||||
|
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->delete(route('customers.destroy', $customer->id))
|
->delete(route('customers.destroy', $customer->id))
|
||||||
->assertStatus(200);
|
->assertStatus(200);
|
||||||
|
|
||||||
$this->assertFlashLevel('success');
|
$this->assertFlashLevel('success');
|
||||||
|
|
||||||
$this->assertSoftDeleted('contacts', $request);
|
$this->assertSoftDeleted('contacts', $request);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public function testItShouldNotDeleteCustomerIfHasRelations()
|
||||||
|
{
|
||||||
|
$this->assertTrue(true);
|
||||||
|
//TODO : This will write after done invoice and revenues tests.
|
||||||
|
}
|
||||||
|
|
||||||
public function testItShouldNotDeleteCustomerIfHasRelations()
|
public function testItShouldExportCustomers()
|
||||||
{
|
{
|
||||||
$this->assertTrue(true);
|
$count = 5;
|
||||||
//TODO : This will write after done invoice and revenues tests.
|
Contact::factory()->customer()->count($count)->create();
|
||||||
}
|
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->get(route('customers.export'))
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertDownloaded(
|
||||||
|
\Str::filename(trans_choice('general.customers', 2)) . '.xlsx',
|
||||||
|
function (Export $export) use ($count) {
|
||||||
|
// Assert that the correct export is downloaded.
|
||||||
|
return $export->collection()->count() === $count + 1;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItShouldExportSelectedCustomers()
|
||||||
|
{
|
||||||
|
$count = 5;
|
||||||
|
$customers = Contact::factory()->customer()->count($count)->create();
|
||||||
|
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->post(
|
||||||
|
route('bulk-actions.action', ['group' => 'sales', 'type' => 'customers']),
|
||||||
|
['handle' => 'export', 'selected' => [$customers->random()->id]]
|
||||||
|
)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertDownloaded(
|
||||||
|
\Str::filename(trans_choice('general.customers', 2)) . '.xlsx',
|
||||||
|
function (Export $export) {
|
||||||
|
return $export->collection()->count() === 1;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItShouldImportCustomers()
|
||||||
|
{
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->post(
|
||||||
|
route('customers.import'),
|
||||||
|
[
|
||||||
|
'import' => UploadedFile::fake()->createWithContent(
|
||||||
|
'customers.xlsx',
|
||||||
|
File::get(public_path('files/import/customers.xlsx'))
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertImported('customers.xlsx');
|
||||||
|
|
||||||
|
$this->assertFlashLevel('success');
|
||||||
|
}
|
||||||
|
|
||||||
public function getRequest()
|
public function getRequest()
|
||||||
{
|
{
|
||||||
return Contact::factory()->customer()->enabled()->raw();
|
return Contact::factory()->customer()->enabled()->raw();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRequestWithUser()
|
public function getRequestWithUser()
|
||||||
{
|
{
|
||||||
$password = $this->faker->password;
|
$password = $this->faker->password;
|
||||||
|
|
||||||
return $this->getRequest() + [
|
return $this->getRequest() + [
|
||||||
'create_user' => 'true',
|
'create_user' => 'true',
|
||||||
'locale' => 'en-GB',
|
'locale' => 'en-GB',
|
||||||
'password' => $password,
|
'password' => $password,
|
||||||
'password_confirmation' => $password,
|
'password_confirmation' => $password,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
namespace Tests\Feature\Sales;
|
namespace Tests\Feature\Sales;
|
||||||
|
|
||||||
|
use App\Exports\Sales\Invoices as Export;
|
||||||
use App\Jobs\Document\CreateDocument;
|
use App\Jobs\Document\CreateDocument;
|
||||||
use App\Models\Document\Document;
|
use App\Models\Document\Document;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
use Tests\Feature\FeatureTestCase;
|
use Tests\Feature\FeatureTestCase;
|
||||||
|
|
||||||
class InvoicesTest extends 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)
|
public function getRequest($recurring = false)
|
||||||
{
|
{
|
||||||
$factory = Document::factory();
|
$factory = Document::factory();
|
||||||
|
@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
namespace Tests\Feature\Sales;
|
namespace Tests\Feature\Sales;
|
||||||
|
|
||||||
|
use App\Exports\Sales\Revenues as Export;
|
||||||
use App\Jobs\Banking\CreateTransaction;
|
use App\Jobs\Banking\CreateTransaction;
|
||||||
use App\Models\Banking\Transaction;
|
use App\Models\Banking\Transaction;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Illuminate\Support\Facades\File;
|
||||||
use Tests\Feature\FeatureTestCase;
|
use Tests\Feature\FeatureTestCase;
|
||||||
|
|
||||||
class RevenuesTest extends FeatureTestCase
|
class RevenuesTest extends FeatureTestCase
|
||||||
@ -82,6 +85,69 @@ class RevenuesTest extends FeatureTestCase
|
|||||||
$this->assertSoftDeleted('transactions', $request);
|
$this->assertSoftDeleted('transactions', $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItShouldExportRevenues()
|
||||||
|
{
|
||||||
|
$count = 5;
|
||||||
|
Transaction::factory()->income()->count($count)->create();
|
||||||
|
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->get(route('revenues.export'))
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertDownloaded(
|
||||||
|
\Str::filename(trans_choice('general.revenues', 2)) . '.xlsx',
|
||||||
|
function (Export $export) use ($count) {
|
||||||
|
// Assert that the correct export is downloaded.
|
||||||
|
return $export->collection()->count() === $count;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItShouldExportSelectedRevenues()
|
||||||
|
{
|
||||||
|
$count = 5;
|
||||||
|
$revenues = Transaction::factory()->income()->count($count)->create();
|
||||||
|
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->post(
|
||||||
|
route('bulk-actions.action', ['group' => 'sales', 'type' => 'revenues']),
|
||||||
|
['handle' => 'export', 'selected' => [$revenues->random()->id]]
|
||||||
|
)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertDownloaded(
|
||||||
|
\Str::filename(trans_choice('general.revenues', 2)) . '.xlsx',
|
||||||
|
function (Export $export) {
|
||||||
|
return $export->collection()->count() === 1;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testItShouldImportRevenues()
|
||||||
|
{
|
||||||
|
\Excel::fake();
|
||||||
|
|
||||||
|
$this->loginAs()
|
||||||
|
->post(
|
||||||
|
route('revenues.import'),
|
||||||
|
[
|
||||||
|
'import' => UploadedFile::fake()->createWithContent(
|
||||||
|
'revenues.xlsx',
|
||||||
|
File::get(public_path('files/import/revenues.xlsx'))
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
\Excel::assertImported('revenues.xlsx');
|
||||||
|
|
||||||
|
$this->assertFlashLevel('success');
|
||||||
|
}
|
||||||
|
|
||||||
public function getRequest()
|
public function getRequest()
|
||||||
{
|
{
|
||||||
return Transaction::factory()->income()->raw();
|
return Transaction::factory()->income()->raw();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user