Moved to _dev
This commit is contained in:
22
crater/tests/CreatesApplication.php
Normal file
22
crater/tests/CreatesApplication.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
|
||||
trait CreatesApplication
|
||||
{
|
||||
/**
|
||||
* Creates the application.
|
||||
*
|
||||
* @return \Illuminate\Foundation\Application
|
||||
*/
|
||||
public function createApplication()
|
||||
{
|
||||
$app = require __DIR__.'/../bootstrap/app.php';
|
||||
|
||||
$app->make(Kernel::class)->bootstrap();
|
||||
|
||||
return $app;
|
||||
}
|
||||
}
|
||||
57
crater/tests/Feature/Admin/BackupTest.php
Normal file
57
crater/tests/Feature/Admin/BackupTest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use Crater\Jobs\CreateBackupJob;
|
||||
use Crater\Models\FileDisk;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get backups', function () {
|
||||
$disk = FileDisk::factory()->create([
|
||||
'set_as_default' => true,
|
||||
]);
|
||||
|
||||
$response = getJson("/api/v1/backups?disk={$disk->driver}&&file_disk_id={$disk->id}");
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('create backup', function () {
|
||||
Queue::fake();
|
||||
|
||||
$disk = FileDisk::factory()->create();
|
||||
|
||||
$data = [
|
||||
'option' => 'full',
|
||||
'file_disk_id' => $disk->id,
|
||||
];
|
||||
|
||||
$response = postJson("/api/v1/backups", $data);
|
||||
|
||||
Queue::assertPushed(CreateBackupJob::class);
|
||||
|
||||
$response = getJson("/api/v1/backups?disk={$disk->driver}&&file_disk_id={$disk->id}");
|
||||
|
||||
$response->assertStatus(200)->assertJson([
|
||||
"disks" => [
|
||||
"local",
|
||||
],
|
||||
]);
|
||||
});
|
||||
201
crater/tests/Feature/Admin/CompanySettingTest.php
Normal file
201
crater/tests/Feature/Admin/CompanySettingTest.php
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Controllers\V1\Admin\Settings\CompanyController;
|
||||
use Crater\Http\Requests\CompanyRequest;
|
||||
use Crater\Http\Requests\ProfileRequest;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\InvoiceItem;
|
||||
use Crater\Models\Tax;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
use function Pest\Laravel\putJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get profile', function () {
|
||||
getJson('api/v1/me')
|
||||
->assertOk();
|
||||
});
|
||||
|
||||
|
||||
test('update profile using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
CompanyController::class,
|
||||
'updateProfile',
|
||||
ProfileRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('update profile', function () {
|
||||
$user = [
|
||||
'name' => 'John Doe',
|
||||
'password' => 'admin@123',
|
||||
'email' => 'admin@crater.in',
|
||||
];
|
||||
|
||||
$response = putJson('api/v1/me', $user);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'name' => $user['name'],
|
||||
'email' => $user['email'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('update company using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
CompanyController::class,
|
||||
'updateCompany',
|
||||
CompanyRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('update company', function () {
|
||||
$company = [
|
||||
'name' => 'XYZ',
|
||||
'country_id' => 2,
|
||||
'state' => 'city',
|
||||
'city' => 'state',
|
||||
'address_street_1' => 'test1',
|
||||
'address_street_2' => 'test2',
|
||||
'phone' => '1234567890',
|
||||
'zip' => '112233',
|
||||
'address' => [
|
||||
'country_id' => 2
|
||||
]
|
||||
];
|
||||
|
||||
putJson('api/v1/company', $company)
|
||||
->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('companies', [
|
||||
'name' => $company['name'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('addresses', [
|
||||
'country_id' => $company['country_id'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('update settings', function () {
|
||||
$settings = [
|
||||
'currency' => 1,
|
||||
'time_zone' => 'Asia/Kolkata',
|
||||
'language' => 'en',
|
||||
'fiscal_year' => '1-12',
|
||||
'carbon_date_format' => 'Y/m/d',
|
||||
'moment_date_format' => 'YYYY/MM/DD',
|
||||
'notification_email' => 'noreply@crater.in',
|
||||
'notify_invoice_viewed' => 'YES',
|
||||
'notify_estimate_viewed' => 'YES',
|
||||
'tax_per_item' => 'YES',
|
||||
'discount_per_item' => 'YES',
|
||||
];
|
||||
|
||||
$response = postJson('/api/v1/company/settings', ['settings' => $settings]);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
foreach ($settings as $key => $value) {
|
||||
$this->assertDatabaseHas('company_settings', [
|
||||
'option' => $key,
|
||||
'value' => $value,
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
test('update settings without currency setting', function () {
|
||||
$settings = [
|
||||
'notification_email' => 'noreply@crater.in',
|
||||
];
|
||||
|
||||
$response = postJson('/api/v1/company/settings', ['settings' => $settings]);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
foreach ($settings as $key => $value) {
|
||||
$this->assertDatabaseHas('company_settings', [
|
||||
'option' => $key,
|
||||
'value' => $value,
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
test('update currency settings after company has currency and transactions is not allowed', function () {
|
||||
$settings = [
|
||||
'currency' => 1,
|
||||
];
|
||||
|
||||
$response = postJson('/api/v1/company/settings', ['settings' => $settings]);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
Invoice::factory()
|
||||
->raw([
|
||||
'taxes' => [Tax::factory()->raw()],
|
||||
'items' => [InvoiceItem::factory()->raw()],
|
||||
]);
|
||||
|
||||
$settings = [
|
||||
'currency' => 2,
|
||||
];
|
||||
|
||||
$response = postJson('/api/v1/company/settings', ['settings' => $settings]);
|
||||
|
||||
$response->assertOK()
|
||||
->assertJson([
|
||||
'success' => false,
|
||||
'message' => 'Cannot update company currency after transactions are created.'
|
||||
]);
|
||||
|
||||
|
||||
$this->assertDatabaseHas('company_settings', [
|
||||
'option' => 'currency',
|
||||
'value' => 1,
|
||||
]);
|
||||
});
|
||||
|
||||
test('get notification email settings', function () {
|
||||
$data['settings'] = [
|
||||
'currency',
|
||||
'time_zone',
|
||||
'language',
|
||||
'fiscal_year',
|
||||
'carbon_date_format',
|
||||
'moment_date_format',
|
||||
'notification_email',
|
||||
'notify_invoice_viewed',
|
||||
'notify_estimate_viewed',
|
||||
'tax_per_item',
|
||||
'discount_per_item',
|
||||
];
|
||||
|
||||
$response = getJson('/api/v1/company/settings?'.http_build_query($data));
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
71
crater/tests/Feature/Admin/CompanyTest.php
Normal file
71
crater/tests/Feature/Admin/CompanyTest.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Controllers\V1\Admin\Company\CompaniesController;
|
||||
use Crater\Http\Requests\CompaniesRequest;
|
||||
use Crater\Models\Company;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('store user using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
CompaniesController::class,
|
||||
'store',
|
||||
CompaniesRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('store company', function () {
|
||||
$company = Company::factory()->raw([
|
||||
'currency' => 12,
|
||||
'address' => [
|
||||
'country_id' => 12
|
||||
]
|
||||
]);
|
||||
|
||||
postJson('/api/v1/companies', $company)
|
||||
->assertStatus(201);
|
||||
|
||||
$company = collect($company)
|
||||
->only([
|
||||
'name'
|
||||
])
|
||||
->toArray();
|
||||
|
||||
$this->assertDatabaseHas('companies', $company);
|
||||
});
|
||||
|
||||
test('delete company', function () {
|
||||
postJson('/api/v1/companies/delete', ["xyz"])
|
||||
->assertStatus(422);
|
||||
});
|
||||
|
||||
test('transfer ownership', function () {
|
||||
$company = Company::factory()->create();
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
postJson('/api/v1/transfer/ownership/'.$user->id)
|
||||
->assertOk();
|
||||
});
|
||||
|
||||
test('get companies', function () {
|
||||
getJson('/api/v1/companies')
|
||||
->assertOk();
|
||||
});
|
||||
69
crater/tests/Feature/Admin/ConfigTest.php
Normal file
69
crater/tests/Feature/Admin/ConfigTest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get all languages', function () {
|
||||
$key = 'languages';
|
||||
|
||||
getJson('api/v1/config?key='.$key)
|
||||
->assertOk();
|
||||
});
|
||||
|
||||
test('get all fiscal years', function () {
|
||||
$key = 'fiscal_years';
|
||||
|
||||
getJson('api/v1/config?key='.$key)
|
||||
->assertOk();
|
||||
});
|
||||
|
||||
test('get all convert estimate options', function () {
|
||||
$key = 'convert_estimate_options';
|
||||
|
||||
getJson('api/v1/config?key='.$key)
|
||||
->assertOk();
|
||||
});
|
||||
|
||||
test('get all retrospective edits', function () {
|
||||
$key = 'retrospective_edits';
|
||||
|
||||
getJson('api/v1/config?key='.$key)
|
||||
->assertOk();
|
||||
});
|
||||
|
||||
test('get all currency converter servers', function () {
|
||||
$key = 'currency_converter_servers';
|
||||
|
||||
getJson('api/v1/config?key='.$key)
|
||||
->assertOk();
|
||||
});
|
||||
|
||||
test('get all exchange rate drivers', function () {
|
||||
$key = 'exchange_rate_drivers';
|
||||
|
||||
getJson('api/v1/config?key='.$key)
|
||||
->assertOk();
|
||||
});
|
||||
|
||||
test('get all custom field models', function () {
|
||||
$key = 'custom_field_models';
|
||||
|
||||
getJson('api/v1/config?key='.$key)
|
||||
->assertOk();
|
||||
});
|
||||
25
crater/tests/Feature/Admin/CurrenciesTest.php
Normal file
25
crater/tests/Feature/Admin/CurrenciesTest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get all used currencies', function () {
|
||||
getJson("/api/v1/currencies/used")
|
||||
->assertOk();
|
||||
});
|
||||
96
crater/tests/Feature/Admin/CustomFieldTest.php
Normal file
96
crater/tests/Feature/Admin/CustomFieldTest.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Controllers\V1\Admin\CustomField\CustomFieldsController;
|
||||
use Crater\Http\Requests\CustomFieldRequest;
|
||||
use Crater\Models\CustomField;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\deleteJson;
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
use function Pest\Laravel\putJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get custom fields', function () {
|
||||
$response = getJson('api/v1/custom-fields?page=1');
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('create custom field', function () {
|
||||
$data = CustomField::factory()->raw();
|
||||
|
||||
postJson('api/v1/custom-fields', $data)
|
||||
->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('custom_fields', [
|
||||
'name' => $data['name'],
|
||||
'label' => $data['label'],
|
||||
'type' => $data['type'],
|
||||
'model_type' => $data['model_type'],
|
||||
'is_required' => $data['is_required'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('store validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
CustomFieldsController::class,
|
||||
'store',
|
||||
CustomFieldRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('update custom field', function () {
|
||||
$customField = CustomField::factory()->create();
|
||||
|
||||
$newCustomField = CustomField::factory()->raw([
|
||||
'is_required' => false,
|
||||
]);
|
||||
|
||||
putJson('api/v1/custom-fields/'.$customField->id, $newCustomField)
|
||||
->assertStatus(200);
|
||||
|
||||
$this->assertDatabaseHas('custom_fields', [
|
||||
'id' => $customField->id,
|
||||
'name' => $newCustomField['name'],
|
||||
'label' => $newCustomField['label'],
|
||||
'type' => $newCustomField['type'],
|
||||
'model_type' => $newCustomField['model_type'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('update validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
CustomFieldsController::class,
|
||||
'update',
|
||||
CustomFieldRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('delete custom field', function () {
|
||||
$customField = CustomField::factory()->create();
|
||||
|
||||
$response = deleteJson('api/v1/custom-fields/'.$customField->id);
|
||||
|
||||
$response
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$this->assertDeleted($customField);
|
||||
});
|
||||
158
crater/tests/Feature/Admin/CustomerTest.php
Normal file
158
crater/tests/Feature/Admin/CustomerTest.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Controllers\V1\Admin\Customer\CustomersController;
|
||||
use Crater\Http\Requests\CustomerRequest;
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
use function Pest\Laravel\putJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get customers', function () {
|
||||
$response = getJson('api/v1/customers?page=1');
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('customer stats', function () {
|
||||
$customer = Customer::factory()->create();
|
||||
|
||||
$invoice = Invoice::factory()->create([
|
||||
'customer_id' => $customer->id,
|
||||
]);
|
||||
|
||||
$response = getJson("api/v1/customers/{$customer->id}/stats");
|
||||
|
||||
$response->assertStatus(200);
|
||||
});
|
||||
|
||||
test('create customer', function () {
|
||||
$customer = Customer::factory()->raw([
|
||||
'shipping' => [
|
||||
'name' => 'newName',
|
||||
'address_street_1' => 'address'
|
||||
],
|
||||
'billing' => [
|
||||
'name' => 'newName',
|
||||
'address_street_1' => 'address'
|
||||
]
|
||||
]);
|
||||
|
||||
postJson('api/v1/customers', $customer)
|
||||
->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('customers', [
|
||||
'name' => $customer['name'],
|
||||
'email' => $customer['email']
|
||||
]);
|
||||
});
|
||||
|
||||
test('store validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
CustomersController::class,
|
||||
'store',
|
||||
CustomerRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('get customer', function () {
|
||||
$customer = Customer::factory()->create();
|
||||
|
||||
$response = getJson("api/v1/customers/{$customer->id}");
|
||||
|
||||
$this->assertDatabaseHas('customers', [
|
||||
'id' => $customer->id,
|
||||
'name' => $customer['name'],
|
||||
'email' => $customer['email']
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('update customer', function () {
|
||||
$customer = Customer::factory()->create();
|
||||
|
||||
$customer1 = Customer::factory()->raw([
|
||||
'shipping' => [
|
||||
'name' => 'newName',
|
||||
'address_street_1' => 'address'
|
||||
],
|
||||
'billing' => [
|
||||
'name' => 'newName',
|
||||
'address_street_1' => 'address'
|
||||
]
|
||||
]);
|
||||
|
||||
$response = putJson('api/v1/customers/'.$customer->id, $customer1);
|
||||
|
||||
$customer1 = collect($customer1)
|
||||
->only([
|
||||
'email'
|
||||
])
|
||||
->merge([
|
||||
'creator_id' => Auth::id()
|
||||
])
|
||||
->toArray();
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('customers', $customer1);
|
||||
});
|
||||
|
||||
test('update validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
CustomersController::class,
|
||||
'update',
|
||||
CustomerRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('search customers', function () {
|
||||
$filters = [
|
||||
'page' => 1,
|
||||
'limit' => 15,
|
||||
'search' => 'doe',
|
||||
'email' => '.com',
|
||||
];
|
||||
|
||||
$queryString = http_build_query($filters, '', '&');
|
||||
|
||||
$response = getJson('api/v1/customers?'.$queryString);
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('delete multiple customer', function () {
|
||||
$customers = Customer::factory()->count(4)->create();
|
||||
|
||||
$ids = $customers->pluck('id');
|
||||
|
||||
$data = [
|
||||
'ids' => $ids,
|
||||
];
|
||||
|
||||
$response = postJson('api/v1/customers/delete', $data);
|
||||
|
||||
$response
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
});
|
||||
24
crater/tests/Feature/Admin/DashboardTest.php
Normal file
24
crater/tests/Feature/Admin/DashboardTest.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
getJson('api/v1/dashboard')->assertOk();
|
||||
|
||||
getJson('api/v1/search?name=ab')->assertOk();
|
||||
446
crater/tests/Feature/Admin/EstimateTest.php
Normal file
446
crater/tests/Feature/Admin/EstimateTest.php
Normal file
@@ -0,0 +1,446 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Controllers\V1\Admin\Estimate\EstimatesController;
|
||||
use Crater\Http\Controllers\V1\Admin\Estimate\SendEstimateController;
|
||||
use Crater\Http\Requests\DeleteEstimatesRequest;
|
||||
use Crater\Http\Requests\EstimatesRequest;
|
||||
use Crater\Http\Requests\SendEstimatesRequest;
|
||||
use Crater\Mail\SendEstimateMail;
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Models\EstimateItem;
|
||||
use Crater\Models\Tax;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
use function Pest\Laravel\putJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get estimates', function () {
|
||||
$response = getJson('api/v1/estimates?page=1');
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('create estimate', function () {
|
||||
$estimate = Estimate::factory()->raw([
|
||||
'estimate_number' => 'EST-000006',
|
||||
'items' => [
|
||||
EstimateItem::factory()->raw(),
|
||||
],
|
||||
'taxes' => [
|
||||
Tax::factory()->raw(),
|
||||
],
|
||||
]);
|
||||
|
||||
postJson('api/v1/estimates', $estimate)
|
||||
->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('estimates', [
|
||||
'template_name' => $estimate['template_name'],
|
||||
'estimate_number' => $estimate['estimate_number'],
|
||||
'discount_type' => $estimate['discount_type'],
|
||||
'discount_val' => $estimate['discount_val'],
|
||||
'sub_total' => $estimate['sub_total'],
|
||||
'discount' => $estimate['discount'],
|
||||
'customer_id' => $estimate['customer_id'],
|
||||
'total' => $estimate['total'],
|
||||
'notes' => $estimate['notes'],
|
||||
'tax' => $estimate['tax'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('store validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
EstimatesController::class,
|
||||
'store',
|
||||
EstimatesRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('update estimate', function () {
|
||||
$estimate = Estimate::factory()
|
||||
->hasItems(1)
|
||||
->hasTaxes(1)
|
||||
->create([
|
||||
'estimate_date' => '1988-07-18',
|
||||
'expiry_date' => '1988-08-18',
|
||||
]);
|
||||
|
||||
$estimate2 = Estimate::factory()->raw([
|
||||
'items' => [
|
||||
EstimateItem::factory()->raw([
|
||||
'estimate_id' => $estimate->id
|
||||
]),
|
||||
],
|
||||
'taxes' => [
|
||||
Tax::factory()->raw([
|
||||
'tax_type_id' => $estimate->taxes[0]->tax_type_id,
|
||||
]),
|
||||
],
|
||||
]);
|
||||
|
||||
$response = putJson('api/v1/estimates/'.$estimate->id, $estimate2);
|
||||
|
||||
$this->assertDatabaseHas('estimates', [
|
||||
'template_name' => $estimate2['template_name'],
|
||||
'estimate_number' => $estimate2['estimate_number'],
|
||||
'discount_type' => $estimate2['discount_type'],
|
||||
'discount_val' => $estimate2['discount_val'],
|
||||
'sub_total' => $estimate2['sub_total'],
|
||||
'discount' => $estimate2['discount'],
|
||||
'customer_id' => $estimate2['customer_id'],
|
||||
'total' => $estimate2['total'],
|
||||
'notes' => $estimate2['notes'],
|
||||
'tax' => $estimate2['tax'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('estimate_items', [
|
||||
'estimate_id' => $estimate2['items'][0]['estimate_id'],
|
||||
]);
|
||||
|
||||
$response->assertStatus(200);
|
||||
});
|
||||
|
||||
test('update validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
EstimatesController::class,
|
||||
'update',
|
||||
EstimatesRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('search estimates', function () {
|
||||
$filters = [
|
||||
'page' => 1,
|
||||
'limit' => 15,
|
||||
'search' => 'doe',
|
||||
'from_date' => '2020-07-18',
|
||||
'to_date' => '2020-07-20',
|
||||
'estimate_number' => '000003',
|
||||
];
|
||||
|
||||
$queryString = http_build_query($filters, '', '&');
|
||||
|
||||
$response = getJson('api/v1/estimates?'.$queryString);
|
||||
|
||||
$response->assertStatus(200);
|
||||
});
|
||||
|
||||
test('send estimate using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
SendEstimateController::class,
|
||||
'__invoke',
|
||||
SendEstimatesRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('send estimate to customer', function () {
|
||||
Mail::fake();
|
||||
|
||||
$estimate = Estimate::factory()->create([
|
||||
'estimate_date' => '1988-07-18',
|
||||
'expiry_date' => '1988-08-18',
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'subject' => 'test',
|
||||
'body' => 'test',
|
||||
'from' => 'john@example.com',
|
||||
'to' => 'doe@example.com',
|
||||
];
|
||||
|
||||
postJson("api/v1/estimates/{$estimate->id}/send", $data)
|
||||
->assertStatus(200)
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
Mail::assertSent(SendEstimateMail::class);
|
||||
});
|
||||
|
||||
test('estimate mark as accepted', function () {
|
||||
$estimate = Estimate::factory()->create([
|
||||
'estimate_date' => '1988-07-18',
|
||||
'expiry_date' => '1988-08-18',
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'status' => Estimate::STATUS_ACCEPTED,
|
||||
];
|
||||
|
||||
$response = postJson("api/v1/estimates/{$estimate->id}/status", $data);
|
||||
|
||||
$response
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$estimate2 = Estimate::find($estimate->id);
|
||||
$this->assertEquals($estimate2->status, Estimate::STATUS_ACCEPTED);
|
||||
});
|
||||
|
||||
test('estimate mark as rejected', function () {
|
||||
$estimate = Estimate::factory()->create([
|
||||
'estimate_date' => '1988-07-18',
|
||||
'expiry_date' => '1988-08-18',
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'status' => Estimate::STATUS_REJECTED,
|
||||
];
|
||||
|
||||
$response = postJson("api/v1/estimates/{$estimate->id}/status", $data);
|
||||
|
||||
$response
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$estimate2 = Estimate::find($estimate->id);
|
||||
$this->assertEquals($estimate2->status, Estimate::STATUS_REJECTED);
|
||||
});
|
||||
|
||||
test('create invoice from estimate', function () {
|
||||
$estimate = Estimate::factory()->create([
|
||||
'estimate_date' => '1988-07-18',
|
||||
'expiry_date' => '1988-08-18',
|
||||
]);
|
||||
|
||||
$response = postJson("api/v1/estimates/{$estimate->id}/convert-to-invoice")
|
||||
->assertStatus(200);
|
||||
});
|
||||
|
||||
test('delete multiple estimates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
EstimatesController::class,
|
||||
'delete',
|
||||
DeleteEstimatesRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('delete multiple estimates', function () {
|
||||
$estimates = Estimate::factory()
|
||||
->count(3)
|
||||
->create([
|
||||
'estimate_date' => '1988-07-18',
|
||||
'expiry_date' => '1988-08-18',
|
||||
]);
|
||||
|
||||
$ids = $estimates->pluck('id');
|
||||
|
||||
$data = [
|
||||
'ids' => $ids,
|
||||
];
|
||||
|
||||
$response = postJson('api/v1/estimates/delete', $data);
|
||||
|
||||
$response
|
||||
->assertStatus(200)
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
foreach ($estimates as $estimate) {
|
||||
$this->assertDeleted($estimate);
|
||||
}
|
||||
});
|
||||
|
||||
test('get estimate templates', function () {
|
||||
getJson('api/v1/estimates/templates')->assertStatus(200);
|
||||
});
|
||||
|
||||
test('create estimate with tax per item', function () {
|
||||
$estimate = Estimate::factory()->raw([
|
||||
'estimate_number' => 'EST-000006',
|
||||
'tax_per_item' => 'YES',
|
||||
'items' => [
|
||||
EstimateItem::factory()->raw([
|
||||
'taxes' => [Tax::factory()->raw()],
|
||||
]),
|
||||
EstimateItem::factory()->raw([
|
||||
'taxes' => [Tax::factory()->raw()],
|
||||
]),
|
||||
],
|
||||
]);
|
||||
|
||||
postJson('api/v1/estimates', $estimate)
|
||||
->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('estimates', [
|
||||
'template_name' => $estimate['template_name'],
|
||||
'estimate_number' => $estimate['estimate_number'],
|
||||
'discount_type' => $estimate['discount_type'],
|
||||
'discount_val' => $estimate['discount_val'],
|
||||
'sub_total' => $estimate['sub_total'],
|
||||
'discount' => $estimate['discount'],
|
||||
'customer_id' => $estimate['customer_id'],
|
||||
'total' => $estimate['total'],
|
||||
'notes' => $estimate['notes'],
|
||||
'tax' => $estimate['tax'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('estimate_items', [
|
||||
'name' => $estimate['items'][0]['name'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('taxes', [
|
||||
'tax_type_id' => $estimate['items'][0]['taxes'][0]['tax_type_id']
|
||||
]);
|
||||
});
|
||||
|
||||
test('create estimate with EUR currency', function () {
|
||||
$estimate = Estimate::factory()
|
||||
->raw([
|
||||
'discount_type' => 'fixed',
|
||||
'discount_val' => 20,
|
||||
'sub_total' => 200,
|
||||
'total' => 189,
|
||||
'tax' => 9,
|
||||
'exchange_rate' => 86.403538,
|
||||
'base_discount_val' => 1728.07,
|
||||
'base_sub_total' => 17280.71,
|
||||
'base_total' => 16330.27,
|
||||
'base_tax' => 777.63,
|
||||
'taxes' => [Tax::factory()->raw([
|
||||
'amount' => 9,
|
||||
'percent' => 5,
|
||||
'exchange_rate' => 86.403538,
|
||||
'base_amount' => 777.63,
|
||||
])],
|
||||
'items' => [EstimateItem::factory()->raw([
|
||||
'discount_type' => 'fixed',
|
||||
'quantity' => 1,
|
||||
'discount' => 0,
|
||||
'discount_val' => 0,
|
||||
'price' => 200,
|
||||
'tax' => 0,
|
||||
'total' => 200,
|
||||
'exchange_rate' => 86.403538,
|
||||
'base_discount_val' => 0,
|
||||
'base_price' => 17280.71,
|
||||
'base_tax' => 777.63,
|
||||
'base_total' => 17280.71,
|
||||
])],
|
||||
]);
|
||||
|
||||
$response = postJson('api/v1/estimates', $estimate)->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('estimates', [
|
||||
'template_name' => $estimate['template_name'],
|
||||
'estimate_number' => $estimate['estimate_number'],
|
||||
'discount_type' => $estimate['discount_type'],
|
||||
'discount_val' => $estimate['discount_val'],
|
||||
'sub_total' => $estimate['sub_total'],
|
||||
'discount' => $estimate['discount'],
|
||||
'customer_id' => $estimate['customer_id'],
|
||||
'total' => $estimate['total'],
|
||||
'notes' => $estimate['notes'],
|
||||
'tax' => $estimate['tax'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('taxes', [
|
||||
'tax_type_id' => $estimate['taxes'][0]['tax_type_id'],
|
||||
'amount' => $estimate['tax']
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('estimate_items', [
|
||||
'item_id' => $estimate['items'][0]['item_id'],
|
||||
'name' => $estimate['items'][0]['name']
|
||||
]);
|
||||
});
|
||||
|
||||
test('update estimate with EUR currency', function () {
|
||||
$estimate = Estimate::factory()
|
||||
->hasItems(1)
|
||||
->hasTaxes(1)
|
||||
->create([
|
||||
'estimate_date' => '1988-07-18',
|
||||
'expiry_date' => '1988-08-18',
|
||||
]);
|
||||
|
||||
$estimate2 = Estimate::factory()
|
||||
->raw([
|
||||
'id' => $estimate->id,
|
||||
'discount_type' => 'fixed',
|
||||
'discount_val' => 20,
|
||||
'sub_total' => 200,
|
||||
'total' => 189,
|
||||
'tax' => 9,
|
||||
'exchange_rate' => 86.403538,
|
||||
'base_discount_val' => 1728.07076,
|
||||
'base_sub_total' => 17280.7076,
|
||||
'base_total' => 16330.268682,
|
||||
'base_tax' => 777.631842,
|
||||
'taxes' => [Tax::factory()->raw([
|
||||
'tax_type_id' => $estimate->taxes[0]->tax_type_id,
|
||||
'amount' => 9,
|
||||
'percent' => 5,
|
||||
'exchange_rate' => 86.403538,
|
||||
'base_amount' => 777.631842,
|
||||
])],
|
||||
'items' => [EstimateItem::factory()->raw([
|
||||
'estimate_id' => $estimate->id,
|
||||
'discount_type' => 'fixed',
|
||||
'quantity' => 1,
|
||||
'discount' => 0,
|
||||
'discount_val' => 0,
|
||||
'price' => 200,
|
||||
'tax' => 0,
|
||||
'total' => 200,
|
||||
'exchange_rate' => 86.403538,
|
||||
'base_discount_val' => 0,
|
||||
'base_price' => 17280.7076,
|
||||
'base_tax' => 777.631842,
|
||||
'base_total' => 17280.7076,
|
||||
])],
|
||||
]);
|
||||
|
||||
$response = putJson('api/v1/estimates/'.$estimate->id, $estimate2);
|
||||
|
||||
$this->assertDatabaseHas('estimates', [
|
||||
'id' => $estimate['id'],
|
||||
'template_name' => $estimate2['template_name'],
|
||||
'estimate_number' => $estimate2['estimate_number'],
|
||||
'discount_type' => $estimate2['discount_type'],
|
||||
'discount_val' => $estimate2['discount_val'],
|
||||
'sub_total' => $estimate2['sub_total'],
|
||||
'discount' => $estimate2['discount'],
|
||||
'customer_id' => $estimate2['customer_id'],
|
||||
'total' => $estimate2['total'],
|
||||
'tax' => $estimate2['tax'],
|
||||
'exchange_rate' => $estimate2['exchange_rate'],
|
||||
'base_discount_val' => $estimate2['base_discount_val'],
|
||||
'base_sub_total' => $estimate2['base_sub_total'],
|
||||
'base_total' => $estimate2['base_total'],
|
||||
'base_tax' => $estimate2['base_tax'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('estimate_items', [
|
||||
'estimate_id' => $estimate2['items'][0]['estimate_id'],
|
||||
'exchange_rate' => $estimate2['items'][0]['exchange_rate'],
|
||||
'base_price' => $estimate2['items'][0]['base_price'],
|
||||
'base_discount_val' => $estimate2['items'][0]['base_discount_val'],
|
||||
'base_tax' => $estimate2['items'][0]['base_tax'],
|
||||
'base_total' => $estimate2['items'][0]['base_total'],
|
||||
]);
|
||||
|
||||
$response->assertStatus(200);
|
||||
});
|
||||
93
crater/tests/Feature/Admin/ExpenseCategoryTest.php
Normal file
93
crater/tests/Feature/Admin/ExpenseCategoryTest.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Controllers\V1\Admin\Expense\ExpenseCategoriesController;
|
||||
use Crater\Http\Requests\ExpenseCategoryRequest;
|
||||
use Crater\Models\ExpenseCategory;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\deleteJson;
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
use function Pest\Laravel\putJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get categories', function () {
|
||||
$response = getJson('api/v1/categories');
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('create category', function () {
|
||||
$category = ExpenseCategory::factory()->raw();
|
||||
|
||||
$response = postJson('api/v1/categories', $category);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('expense_categories', [
|
||||
'name' => $category['name'],
|
||||
'description' => $category['description'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('store validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
ExpenseCategoriesController::class,
|
||||
'store',
|
||||
ExpenseCategoryRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('get category', function () {
|
||||
$category = ExpenseCategory::factory()->create();
|
||||
|
||||
getJson("api/v1/categories/{$category->id}")->assertOk();
|
||||
});
|
||||
|
||||
test('update category', function () {
|
||||
$category = ExpenseCategory::factory()->create();
|
||||
|
||||
$category2 = ExpenseCategory::factory()->raw();
|
||||
|
||||
putJson('api/v1/categories/'.$category->id, $category2)->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('expense_categories', [
|
||||
'id' => $category->id,
|
||||
'name' => $category2['name'],
|
||||
'description' => $category2['description'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('update validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
ExpenseCategoriesController::class,
|
||||
'update',
|
||||
ExpenseCategoryRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('delete category', function () {
|
||||
$category = ExpenseCategory::factory()->create();
|
||||
|
||||
deleteJson('api/v1/categories/'.$category->id)
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$this->assertDeleted($category);
|
||||
});
|
||||
156
crater/tests/Feature/Admin/ExpenseTest.php
Normal file
156
crater/tests/Feature/Admin/ExpenseTest.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Controllers\V1\Admin\Expense\ExpensesController;
|
||||
use Crater\Http\Requests\ExpenseRequest;
|
||||
use Crater\Models\Expense;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
use function Pest\Laravel\putJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get expenses', function () {
|
||||
getJson('api/v1/expenses?page=1')->assertOk();
|
||||
});
|
||||
|
||||
test('create expense', function () {
|
||||
$expense = Expense::factory()->raw([
|
||||
'amount' => 150,
|
||||
'exchange_rate' => 76.217498,
|
||||
'base_amount' => 11432.6247,
|
||||
]);
|
||||
|
||||
postJson('api/v1/expenses', $expense)->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('expenses', [
|
||||
'notes' => $expense['notes'],
|
||||
'expense_category_id' => $expense['expense_category_id'],
|
||||
'amount' => $expense['amount'],
|
||||
'exchange_rate' => $expense['exchange_rate'],
|
||||
'base_amount' => $expense['base_amount'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('store validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
ExpensesController::class,
|
||||
'store',
|
||||
ExpenseRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('get expense data', function () {
|
||||
$expense = Expense::factory()->create([
|
||||
'expense_date' => '2019-02-05',
|
||||
]);
|
||||
|
||||
getJson("api/v1/expenses/{$expense->id}")->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('expenses', [
|
||||
'id' => $expense->id,
|
||||
'notes' => $expense['notes'],
|
||||
'expense_category_id' => $expense['expense_category_id'],
|
||||
'amount' => $expense['amount'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('update expense', function () {
|
||||
$expense = Expense::factory()->create([
|
||||
'expense_date' => '2019-02-05',
|
||||
]);
|
||||
|
||||
$expense2 = Expense::factory()->raw();
|
||||
|
||||
putJson('api/v1/expenses/'.$expense->id, $expense2)->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('expenses', [
|
||||
'id' => $expense->id,
|
||||
'notes' => $expense2['notes'],
|
||||
'expense_category_id' => $expense2['expense_category_id'],
|
||||
'amount' => $expense2['amount'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('update validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
ExpensesController::class,
|
||||
'update',
|
||||
ExpenseRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('search expenses', function () {
|
||||
$filters = [
|
||||
'page' => 1,
|
||||
'limit' => 15,
|
||||
'expense_category_id' => 1,
|
||||
'search' => 'cate',
|
||||
'from_date' => '2020-07-18',
|
||||
'to_date' => '2020-07-20',
|
||||
];
|
||||
|
||||
$queryString = http_build_query($filters, '', '&');
|
||||
|
||||
$response = getJson('api/v1/expenses?'.$queryString);
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('delete multiple expenses', function () {
|
||||
$expenses = Expense::factory()->count(3)->create([
|
||||
'expense_date' => '2019-02-05',
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'ids' => $expenses->pluck('id'),
|
||||
];
|
||||
|
||||
$response = postJson('api/v1/expenses/delete', $data);
|
||||
|
||||
$response
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
foreach ($expenses as $expense) {
|
||||
$this->assertDeleted($expense);
|
||||
}
|
||||
});
|
||||
|
||||
test('update expense with EUR currency', function () {
|
||||
$expense = Expense::factory()->create([
|
||||
'expense_date' => '2019-02-05',
|
||||
]);
|
||||
|
||||
$expense2 = Expense::factory()->raw([
|
||||
'amount' => 150,
|
||||
'exchange_rate' => 76.217498,
|
||||
'base_amount' => 11432.6247,
|
||||
]);
|
||||
|
||||
putJson('api/v1/expenses/'.$expense->id, $expense2)->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('expenses', [
|
||||
'id' => $expense->id,
|
||||
'expense_category_id' => $expense2['expense_category_id'],
|
||||
'amount' => $expense2['amount'],
|
||||
'exchange_rate' => $expense2['exchange_rate'],
|
||||
'base_amount' => $expense2['base_amount'],
|
||||
]);
|
||||
});
|
||||
66
crater/tests/Feature/Admin/FileDiskTest.php
Normal file
66
crater/tests/Feature/Admin/FileDiskTest.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\FileDisk;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
use function Pest\Laravel\putJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get file disks', function () {
|
||||
$response = getJson('/api/v1/disks');
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('create file disk', function () {
|
||||
$disk = FileDisk::factory()->raw();
|
||||
|
||||
$response = postJson('/api/v1/disks', $disk);
|
||||
|
||||
$disk['credentials'] = json_encode($disk['credentials']);
|
||||
$this->assertDatabaseHas('file_disks', $disk);
|
||||
});
|
||||
|
||||
|
||||
test('update file disk', function () {
|
||||
$disk = FileDisk::factory()->create();
|
||||
|
||||
$disk2 = FileDisk::factory()->raw();
|
||||
|
||||
$response = putJson("/api/v1/disks/{$disk->id}", $disk2)->assertStatus(200);
|
||||
|
||||
$disk2['credentials'] = json_encode($disk2['credentials']);
|
||||
|
||||
$this->assertDatabaseHas('file_disks', $disk2);
|
||||
});
|
||||
|
||||
|
||||
test('get disk', function () {
|
||||
$disk = FileDisk::factory()->create();
|
||||
|
||||
$response = getJson("/api/v1/disks/{$disk->driver}");
|
||||
|
||||
$response->assertStatus(200);
|
||||
});
|
||||
|
||||
test('get drivers', function () {
|
||||
$response = getJson("/api/v1/disk/drivers");
|
||||
|
||||
$response->assertStatus(200);
|
||||
});
|
||||
461
crater/tests/Feature/Admin/InvoiceTest.php
Normal file
461
crater/tests/Feature/Admin/InvoiceTest.php
Normal file
@@ -0,0 +1,461 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Controllers\V1\Admin\Invoice\InvoicesController;
|
||||
use Crater\Http\Requests\InvoicesRequest;
|
||||
use Crater\Mail\SendInvoiceMail;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\InvoiceItem;
|
||||
use Crater\Models\Tax;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
use function Pest\Laravel\putJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('testGetInvoices', function () {
|
||||
$response = getJson('api/v1/invoices?page=1&type=OVERDUE&limit=20');
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('create invoice', function () {
|
||||
$invoice = Invoice::factory()
|
||||
->raw([
|
||||
'taxes' => [Tax::factory()->raw()],
|
||||
'items' => [InvoiceItem::factory()->raw()],
|
||||
]);
|
||||
|
||||
$response = postJson('api/v1/invoices', $invoice);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'template_name' => $invoice['template_name'],
|
||||
'invoice_number' => $invoice['invoice_number'],
|
||||
'sub_total' => $invoice['sub_total'],
|
||||
'discount' => $invoice['discount'],
|
||||
'customer_id' => $invoice['customer_id'],
|
||||
'total' => $invoice['total'],
|
||||
'tax' => $invoice['tax'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'item_id' => $invoice['items'][0]['item_id'],
|
||||
'name' => $invoice['items'][0]['name']
|
||||
]);
|
||||
});
|
||||
|
||||
test('create invoice as sent', function () {
|
||||
$invoice = Invoice::factory()
|
||||
->raw([
|
||||
'taxes' => [Tax::factory()->raw()],
|
||||
'items' => [InvoiceItem::factory()->raw()],
|
||||
]);
|
||||
|
||||
$response = postJson('api/v1/invoices', $invoice);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'invoice_number' => $invoice['invoice_number'],
|
||||
'sub_total' => $invoice['sub_total'],
|
||||
'total' => $invoice['total'],
|
||||
'tax' => $invoice['tax'],
|
||||
'discount' => $invoice['discount'],
|
||||
'customer_id' => $invoice['customer_id'],
|
||||
'template_name' => $invoice['template_name'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'item_id' => $invoice['items'][0]['item_id'],
|
||||
'name' => $invoice['items'][0]['name']
|
||||
]);
|
||||
});
|
||||
|
||||
test('store validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
InvoicesController::class,
|
||||
'store',
|
||||
InvoicesRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('update invoice', function () {
|
||||
$invoice = Invoice::factory()->create([
|
||||
'invoice_date' => '1988-07-18',
|
||||
'due_date' => '1988-08-18',
|
||||
]);
|
||||
|
||||
$invoice2 = Invoice::factory()
|
||||
->raw([
|
||||
'taxes' => [Tax::factory()->raw()],
|
||||
'items' => [InvoiceItem::factory()->raw()],
|
||||
]);
|
||||
|
||||
putJson('api/v1/invoices/'.$invoice->id, $invoice2)->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'invoice_number' => $invoice2['invoice_number'],
|
||||
'sub_total' => $invoice2['sub_total'],
|
||||
'total' => $invoice2['total'],
|
||||
'tax' => $invoice2['tax'],
|
||||
'discount' => $invoice2['discount'],
|
||||
'customer_id' => $invoice2['customer_id'],
|
||||
'template_name' => $invoice2['template_name'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'item_id' => $invoice2['items'][0]['item_id'],
|
||||
'name' => $invoice2['items'][0]['name']
|
||||
]);
|
||||
});
|
||||
|
||||
test('update validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
InvoicesController::class,
|
||||
'update',
|
||||
InvoicesRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('send invoice to customer', function () {
|
||||
Mail::fake();
|
||||
|
||||
$invoices = Invoice::factory()->create([
|
||||
'invoice_date' => '1988-07-18',
|
||||
'due_date' => '1988-08-18',
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'from' => 'john@example.com',
|
||||
'to' => 'doe@example.com',
|
||||
'subject' => 'email subject',
|
||||
'body' => 'email body',
|
||||
];
|
||||
|
||||
$response = postJson('api/v1/invoices/'.$invoices->id.'/send', $data);
|
||||
|
||||
$response
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$invoice2 = Invoice::find($invoices->id);
|
||||
|
||||
$this->assertEquals($invoice2->status, Invoice::STATUS_SENT);
|
||||
Mail::assertSent(SendInvoiceMail::class);
|
||||
});
|
||||
|
||||
test('invoice mark as paid', function () {
|
||||
$invoice = Invoice::factory()->create([
|
||||
'invoice_date' => '1988-07-18',
|
||||
'due_date' => '1988-08-18',
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'status' => Invoice::STATUS_COMPLETED,
|
||||
];
|
||||
|
||||
$response = postJson('api/v1/invoices/'.$invoice->id.'/status', $data);
|
||||
|
||||
$response
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$this->assertEquals(Invoice::find($invoice->id)->paid_status, Invoice::STATUS_PAID);
|
||||
});
|
||||
|
||||
test('invoice mark as sent', function () {
|
||||
$invoice = Invoice::factory()->create([
|
||||
'invoice_date' => '1988-07-18',
|
||||
'due_date' => '1988-08-18',
|
||||
]);
|
||||
|
||||
$data = [
|
||||
'status' => Invoice::STATUS_SENT,
|
||||
];
|
||||
|
||||
$response = postJson('api/v1/invoices/'.$invoice->id.'/status', $data);
|
||||
|
||||
$response
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$this->assertEquals(Invoice::find($invoice->id)->status, Invoice::STATUS_SENT);
|
||||
});
|
||||
|
||||
test('search invoices', function () {
|
||||
$filters = [
|
||||
'page' => 1,
|
||||
'limit' => 15,
|
||||
'search' => 'doe',
|
||||
'status' => Invoice::STATUS_DRAFT,
|
||||
'from_date' => '2019-01-20',
|
||||
'to_date' => '2019-01-27',
|
||||
'invoice_number' => '000012',
|
||||
];
|
||||
|
||||
$queryString = http_build_query($filters, '', '&');
|
||||
|
||||
$response = getJson('api/v1/invoices?'.$queryString);
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('delete multiple invoices', function () {
|
||||
$invoices = Invoice::factory()->count(3)->create([
|
||||
'invoice_date' => '1988-07-18',
|
||||
'due_date' => '1988-08-18',
|
||||
]);
|
||||
|
||||
$ids = $invoices->pluck('id');
|
||||
|
||||
$data = [
|
||||
'ids' => $ids,
|
||||
];
|
||||
|
||||
postJson('api/v1/invoices/delete', $data)
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
foreach ($invoices as $invoice) {
|
||||
$this->assertDeleted($invoice);
|
||||
}
|
||||
});
|
||||
|
||||
test('clone invoice', function () {
|
||||
$invoices = Invoice::factory()->create([
|
||||
'invoice_date' => '1988-07-18',
|
||||
'due_date' => '1988-08-18',
|
||||
]);
|
||||
|
||||
postJson("api/v1/invoices/{$invoices->id}/clone")
|
||||
->assertStatus(201);
|
||||
});
|
||||
|
||||
test('create invoice with negative tax', function () {
|
||||
$invoice = Invoice::factory()
|
||||
->raw([
|
||||
'taxes' => [Tax::factory()->raw([
|
||||
'percent' => -9.99
|
||||
])],
|
||||
'items' => [InvoiceItem::factory()->raw()],
|
||||
]);
|
||||
|
||||
$response = postJson('api/v1/invoices', $invoice);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'invoice_number' => $invoice['invoice_number'],
|
||||
'sub_total' => $invoice['sub_total'],
|
||||
'total' => $invoice['total'],
|
||||
'tax' => $invoice['tax'],
|
||||
'discount' => $invoice['discount'],
|
||||
'customer_id' => $invoice['customer_id'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'name' => $invoice['items'][0]['name'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('taxes', [
|
||||
'tax_type_id' => $invoice['taxes'][0]['tax_type_id']
|
||||
]);
|
||||
});
|
||||
|
||||
test('create invoice with tax per item', function () {
|
||||
$invoice = Invoice::factory()
|
||||
->raw([
|
||||
'tax_per_item' => 'YES',
|
||||
'items' => [
|
||||
InvoiceItem::factory()->raw([
|
||||
'taxes' => [Tax::factory()->raw()],
|
||||
]),
|
||||
InvoiceItem::factory()->raw([
|
||||
'taxes' => [Tax::factory()->raw()],
|
||||
]),
|
||||
],
|
||||
]);
|
||||
|
||||
$response = postJson('api/v1/invoices', $invoice);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'invoice_number' => $invoice['invoice_number'],
|
||||
'sub_total' => $invoice['sub_total'],
|
||||
'total' => $invoice['total'],
|
||||
'tax' => $invoice['tax'],
|
||||
'discount' => $invoice['discount'],
|
||||
'customer_id' => $invoice['customer_id'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'name' => $invoice['items'][0]['name'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('taxes', [
|
||||
'tax_type_id' => $invoice['items'][0]['taxes'][0]['tax_type_id']
|
||||
]);
|
||||
});
|
||||
|
||||
test('create invoice with EUR currency', function () {
|
||||
$invoice = Invoice::factory()
|
||||
->raw([
|
||||
'discount_type' => 'fixed',
|
||||
'discount_val' => 20,
|
||||
'sub_total' => 100,
|
||||
'total' => 84,
|
||||
'tax' => 4,
|
||||
'due_amount' => 84,
|
||||
'exchange_rate' => 86.403538,
|
||||
'base_discount_val' => 1728.07,
|
||||
'base_sub_total' => 8640.35,
|
||||
'base_total' => 7257.90,
|
||||
'base_tax' => 345.61,
|
||||
'base_due_amount' => 7257.90,
|
||||
'taxes' => [Tax::factory()->raw([
|
||||
'amount' => 4,
|
||||
'percent' => 5,
|
||||
'base_amount' => 345.61,
|
||||
])],
|
||||
'items' => [InvoiceItem::factory()->raw([
|
||||
'discount_type' => 'fixed',
|
||||
'price' => 100,
|
||||
'quantity' => 1,
|
||||
'discount' => 0,
|
||||
'discount_val' => 0,
|
||||
'tax' => 0,
|
||||
'total' => 100,
|
||||
'base_price' => 8640.35,
|
||||
'exchange_rate' => 86.403538,
|
||||
'base_discount_val' => 0,
|
||||
'base_tax' => 0,
|
||||
'base_total' => 8640.35,
|
||||
])],
|
||||
]);
|
||||
|
||||
$response = postJson('api/v1/invoices', $invoice)->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'template_name' => $invoice['template_name'],
|
||||
'invoice_number' => $invoice['invoice_number'],
|
||||
'sub_total' => $invoice['sub_total'],
|
||||
'discount' => $invoice['discount'],
|
||||
'customer_id' => $invoice['customer_id'],
|
||||
'total' => $invoice['total'],
|
||||
'tax' => $invoice['tax'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('taxes', [
|
||||
'tax_type_id' => $invoice['taxes'][0]['tax_type_id'],
|
||||
'amount' => $invoice['tax']
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'item_id' => $invoice['items'][0]['item_id'],
|
||||
'name' => $invoice['items'][0]['name']
|
||||
]);
|
||||
});
|
||||
|
||||
test('update invoice with EUR currency', function () {
|
||||
$invoice = Invoice::factory()
|
||||
->hasItems(1)
|
||||
->hasTaxes(1)
|
||||
->create([
|
||||
'invoice_date' => '1988-07-18',
|
||||
'due_date' => '1988-08-18',
|
||||
]);
|
||||
|
||||
$invoice2 = Invoice::factory()
|
||||
->raw([
|
||||
'id' => $invoice['id'],
|
||||
'discount_type' => 'fixed',
|
||||
'discount_val' => 20,
|
||||
'sub_total' => 100,
|
||||
'total' => 84,
|
||||
'tax' => 4,
|
||||
'due_amount' => 84,
|
||||
'exchange_rate' => 86.403538,
|
||||
'base_discount_val' => 1728.07,
|
||||
'base_sub_total' => 8640.35,
|
||||
'base_total' => 7257.897192,
|
||||
'base_tax' => 345.614152,
|
||||
'base_due_amount' => 7257.897192,
|
||||
'taxes' => [Tax::factory()->raw([
|
||||
'tax_type_id' => $invoice->taxes[0]->tax_type_id,
|
||||
'amount' => 4,
|
||||
'percent' => 5,
|
||||
'base_amount' => 345.614152,
|
||||
])],
|
||||
'items' => [InvoiceItem::factory()->raw([
|
||||
'invoice_id' => $invoice->id,
|
||||
'discount_type' => 'fixed',
|
||||
'price' => 100,
|
||||
'quantity' => 1,
|
||||
'discount' => 0,
|
||||
'discount_val' => 0,
|
||||
'tax' => 0,
|
||||
'total' => 100,
|
||||
'base_price' => 8640.3538,
|
||||
'exchange_rate' => 86.403538,
|
||||
'base_discount_val' => 0,
|
||||
'base_tax' => 0,
|
||||
'base_total' => 8640.3538,
|
||||
])],
|
||||
]);
|
||||
|
||||
putJson('api/v1/invoices/'.$invoice->id, $invoice2)->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'id' => $invoice['id'],
|
||||
'invoice_number' => $invoice2['invoice_number'],
|
||||
'sub_total' => $invoice2['sub_total'],
|
||||
'total' => $invoice2['total'],
|
||||
'tax' => $invoice2['tax'],
|
||||
'discount' => $invoice2['discount'],
|
||||
'customer_id' => $invoice2['customer_id'],
|
||||
'template_name' => $invoice2['template_name'],
|
||||
'exchange_rate' => $invoice2['exchange_rate'],
|
||||
'base_total' => $invoice2['base_total'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'invoice_id' => $invoice2['items'][0]['invoice_id'],
|
||||
'item_id' => $invoice2['items'][0]['item_id'],
|
||||
'name' => $invoice2['items'][0]['name'],
|
||||
'exchange_rate' => $invoice2['items'][0]['exchange_rate'],
|
||||
'base_price' => $invoice2['items'][0]['base_price'],
|
||||
'base_total' => $invoice2['items'][0]['base_total'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('taxes', [
|
||||
'amount' => $invoice2['taxes'][0]['amount'],
|
||||
'name' => $invoice2['taxes'][0]['name'],
|
||||
'base_amount' => $invoice2['taxes'][0]['base_amount'],
|
||||
]);
|
||||
});
|
||||
142
crater/tests/Feature/Admin/ItemTest.php
Normal file
142
crater/tests/Feature/Admin/ItemTest.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Controllers\V1\Admin\Item\ItemsController;
|
||||
use Crater\Http\Requests\ItemsRequest;
|
||||
use Crater\Models\Item;
|
||||
use Crater\Models\Tax;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
use function Pest\Laravel\putJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get items', function () {
|
||||
$response = getJson('api/v1/items?page=1');
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('create item', function () {
|
||||
$item = Item::factory()->raw([
|
||||
'taxes' => [
|
||||
Tax::factory()->raw(),
|
||||
Tax::factory()->raw(),
|
||||
],
|
||||
]);
|
||||
|
||||
$response = postJson('api/v1/items', $item);
|
||||
|
||||
$this->assertDatabaseHas('items', [
|
||||
'name' => $item['name'],
|
||||
'description' => $item['description'],
|
||||
'price' => $item['price'],
|
||||
'company_id' => $item['company_id'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('taxes', [
|
||||
'item_id' => $response->getData()->data->id,
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('store validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
ItemsController::class,
|
||||
'store',
|
||||
ItemsRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('get item', function () {
|
||||
$item = Item::factory()->create();
|
||||
|
||||
$response = getJson("api/v1/items/{$item->id}");
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('items', [
|
||||
'name' => $item['name'],
|
||||
'description' => $item['description'],
|
||||
'price' => $item['price'],
|
||||
'company_id' => $item['company_id'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('update item', function () {
|
||||
$item = Item::factory()->create();
|
||||
|
||||
$update_item = Item::factory()->raw([
|
||||
'taxes' => [
|
||||
Tax::factory()->raw(),
|
||||
],
|
||||
]);
|
||||
|
||||
$response = putJson('api/v1/items/'.$item->id, $update_item);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('items', [
|
||||
'name' => $update_item['name'],
|
||||
'description' => $update_item['description'],
|
||||
'price' => $update_item['price'],
|
||||
'company_id' => $update_item['company_id'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('taxes', [
|
||||
'item_id' => $item->id,
|
||||
]);
|
||||
});
|
||||
|
||||
test('update validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
ItemsController::class,
|
||||
'update',
|
||||
ItemsRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('delete multiple items', function () {
|
||||
$items = Item::factory()->count(5)->create();
|
||||
|
||||
$data = [
|
||||
'ids' => $items->pluck('id'),
|
||||
];
|
||||
|
||||
postJson("/api/v1/items/delete", $data)->assertOk();
|
||||
|
||||
foreach ($items as $item) {
|
||||
$this->assertDeleted($item);
|
||||
}
|
||||
});
|
||||
|
||||
test('search items', function () {
|
||||
$filters = [
|
||||
'page' => 1,
|
||||
'limit' => 15,
|
||||
'search' => 'doe',
|
||||
'price' => 6,
|
||||
'unit' => 'kg',
|
||||
];
|
||||
|
||||
$queryString = http_build_query($filters, '', '&');
|
||||
|
||||
$response = getJson('api/v1/items?'.$queryString);
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
26
crater/tests/Feature/Admin/LocationTest.php
Normal file
26
crater/tests/Feature/Admin/LocationTest.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get countries', function () {
|
||||
$response = getJson('api/v1/countries');
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
47
crater/tests/Feature/Admin/NextNumberTest.php
Normal file
47
crater/tests/Feature/Admin/NextNumberTest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\{getJson};
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('next number', function () {
|
||||
$key = 'invoice';
|
||||
|
||||
$response = getJson('api/v1/next-number?key='.$key);
|
||||
|
||||
$response->assertStatus(200)->assertJson([
|
||||
'nextNumber' => 'INV-000001',
|
||||
]);
|
||||
|
||||
$key = 'estimate';
|
||||
|
||||
$response = getJson('api/v1/next-number?key='.$key);
|
||||
|
||||
$response->assertStatus(200)->assertJson([
|
||||
'nextNumber' => 'EST-000001',
|
||||
]);
|
||||
|
||||
$key = 'payment';
|
||||
|
||||
$response = getJson('api/v1/next-number?key='.$key);
|
||||
|
||||
$response->assertStatus(200)->assertJson([
|
||||
'nextNumber' => 'PAY-000001',
|
||||
]);
|
||||
});
|
||||
66
crater/tests/Feature/Admin/NotesTest.php
Normal file
66
crater/tests/Feature/Admin/NotesTest.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Note;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\deleteJson;
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
use function Pest\Laravel\putJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('retrieve notes', function () {
|
||||
getJson('/api/v1/notes')->assertStatus(200);
|
||||
});
|
||||
|
||||
test('create note', function () {
|
||||
$note = Note::factory()->raw();
|
||||
|
||||
postJson('/api/v1/notes', $note)->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('notes', $note);
|
||||
});
|
||||
|
||||
test('retrieve note', function () {
|
||||
$note = Note::factory()->create();
|
||||
|
||||
getJson("/api/v1/notes/{$note->id}")
|
||||
->assertStatus(200);
|
||||
});
|
||||
|
||||
test('update note', function () {
|
||||
$note = Note::factory()->create();
|
||||
|
||||
$data = Note::factory()->raw();
|
||||
|
||||
putJson("/api/v1/notes/{$note->id}", $data)
|
||||
->assertStatus(200);
|
||||
|
||||
$this->assertDatabaseHas('notes', $data);
|
||||
});
|
||||
|
||||
test('delete note', function () {
|
||||
$note = Note::factory()->create();
|
||||
|
||||
deleteJson("/api/v1/notes/{$note->id}")
|
||||
->assertStatus(200)
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$this->assertDeleted($note);
|
||||
});
|
||||
105
crater/tests/Feature/Admin/PaymentMethodTest.php
Normal file
105
crater/tests/Feature/Admin/PaymentMethodTest.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Controllers\V1\Admin\Payment\PaymentMethodsController;
|
||||
use Crater\Http\Requests\PaymentMethodRequest;
|
||||
use Crater\Models\PaymentMethod;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\deleteJson;
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
use function Pest\Laravel\putJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get payment methods', function () {
|
||||
$response = getJson('api/v1/payment-methods?page=1');
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('create payment method', function () {
|
||||
$data = [
|
||||
'name' => 'demo name',
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
];
|
||||
|
||||
$response = postJson('api/v1/payment-methods', $data);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('payment_methods', [
|
||||
'name' => $data['name'],
|
||||
'company_id' => $data['company_id'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('store validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
PaymentMethodsController::class,
|
||||
'store',
|
||||
PaymentMethodRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('get payment method', function () {
|
||||
$method = PaymentMethod::factory()->create();
|
||||
|
||||
$response = getJson("api/v1/payment-methods/{$method->id}");
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('payment_methods', [
|
||||
'id' => $method->id,
|
||||
'name' => $method['name'],
|
||||
'company_id' => $method['company_id'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('update payment method', function () {
|
||||
$method = PaymentMethod::factory()->create();
|
||||
|
||||
$data = [
|
||||
'name' => 'updated name',
|
||||
];
|
||||
|
||||
$response = putJson("api/v1/payment-methods/{$method->id}", $data);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('payment_methods', [
|
||||
'id' => $method->id,
|
||||
'name' => $data['name'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('update validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
PaymentMethodsController::class,
|
||||
'update',
|
||||
PaymentMethodRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('delete payment method', function () {
|
||||
$method = PaymentMethod::factory()->create();
|
||||
|
||||
$response = deleteJson('api/v1/payment-methods/'.$method->id);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDeleted($method);
|
||||
});
|
||||
241
crater/tests/Feature/Admin/PaymentTest.php
Normal file
241
crater/tests/Feature/Admin/PaymentTest.php
Normal file
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Controllers\V1\Admin\Payment\PaymentsController;
|
||||
use Crater\Http\Requests\PaymentRequest;
|
||||
use Crater\Mail\SendPaymentMail;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\Payment;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
use function Pest\Laravel\putJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get payments', function () {
|
||||
$response = getJson('api/v1/payments?page=1');
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('get payment', function () {
|
||||
$payment = Payment::factory()->create();
|
||||
|
||||
$response = getJson("api/v1/payments/{$payment->id}");
|
||||
|
||||
$response->assertStatus(200);
|
||||
});
|
||||
|
||||
test('create payment', function () {
|
||||
$invoice = Invoice::factory()->create([
|
||||
'due_amount' => 100,
|
||||
'exchange_rate' => 1
|
||||
]);
|
||||
|
||||
$payment = Payment::factory()->raw([
|
||||
'invoice_id' => $invoice->id,
|
||||
'payment_number' => "PAY-000001",
|
||||
'amount' => $invoice->due_amount,
|
||||
'exchange_rate' => 1
|
||||
]);
|
||||
|
||||
$response = postJson('api/v1/payments', $payment);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('payments', [
|
||||
'payment_number' => $payment['payment_number'],
|
||||
'customer_id' => $payment['customer_id'],
|
||||
'amount' => $payment['amount'],
|
||||
'company_id' => $payment['company_id'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('store validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
PaymentsController::class,
|
||||
'store',
|
||||
PaymentRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('update payment', function () {
|
||||
$invoice = Invoice::factory()->create();
|
||||
|
||||
$payment = Payment::factory()->create([
|
||||
'payment_date' => '1988-08-18',
|
||||
'invoice_id' => $invoice->id,
|
||||
'exchange_rate' => 1
|
||||
]);
|
||||
|
||||
$payment2 = Payment::factory()->raw([
|
||||
'invoice_id' => $invoice->id,
|
||||
'exchange_rate' => 1
|
||||
]);
|
||||
|
||||
putJson("api/v1/payments/{$payment->id}", $payment2)
|
||||
->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('payments', [
|
||||
'id' => $payment->id,
|
||||
'payment_number' => $payment2['payment_number'],
|
||||
'customer_id' => $payment2['customer_id'],
|
||||
'amount' => $payment2['amount'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('update validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
PaymentsController::class,
|
||||
'update',
|
||||
PaymentRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('search payments', function () {
|
||||
$filters = [
|
||||
'page' => 1,
|
||||
'limit' => 15,
|
||||
'search' => 'doe',
|
||||
'payment_number' => 'PAY-000001',
|
||||
'payment_mode' => 'OTHER',
|
||||
];
|
||||
|
||||
$queryString = http_build_query($filters, '', '&');
|
||||
|
||||
$response = getJson('api/v1/payments?'.$queryString);
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('send payment to customer', function () {
|
||||
Mail::fake();
|
||||
|
||||
$payment = Payment::factory()->create();
|
||||
|
||||
$data = [
|
||||
'subject' => 'test',
|
||||
'body' => 'test',
|
||||
'from' => 'john@example.com',
|
||||
'to' => 'doe@example.com',
|
||||
];
|
||||
|
||||
$response = postJson("api/v1/payments/{$payment->id}/send", $data);
|
||||
|
||||
$response->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
Mail::assertSent(SendPaymentMail::class);
|
||||
});
|
||||
|
||||
test('delete payment', function () {
|
||||
$payments = Payment::factory()->count(5)->create();
|
||||
|
||||
$ids = $payments->pluck('id');
|
||||
|
||||
$data = [
|
||||
'ids' => $ids,
|
||||
];
|
||||
|
||||
$response = postJson('api/v1/payments/delete', $data);
|
||||
|
||||
$response->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
});
|
||||
|
||||
test('create payment without invoice', function () {
|
||||
$payment = Payment::factory()->raw([
|
||||
'payment_number' => "PAY-000001",
|
||||
'exchange_rate' => 1
|
||||
]);
|
||||
|
||||
postJson('api/v1/payments', $payment)->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('payments', [
|
||||
'payment_number' => $payment['payment_number'],
|
||||
'customer_id' => $payment['customer_id'],
|
||||
'amount' => $payment['amount'],
|
||||
'company_id' => $payment['company_id'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('create payment with invoice', function () {
|
||||
$payment = Payment::factory()->raw([
|
||||
'payment_number' => "PAY-000001",
|
||||
]);
|
||||
|
||||
$invoice = Invoice::factory()->create();
|
||||
|
||||
$payment = Payment::factory()->raw([
|
||||
'invoice_id' => $invoice->id,
|
||||
'amount' => $invoice->due_amount,
|
||||
'exchange_rate' => 1
|
||||
]);
|
||||
|
||||
postJson('api/v1/payments', $payment)->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('payments', [
|
||||
'payment_number' => $payment['payment_number'],
|
||||
'customer_id' => $payment['customer_id'],
|
||||
'invoice_id' => $payment['invoice_id'],
|
||||
'amount' => $payment['amount'],
|
||||
'company_id' => $payment['company_id'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('create payment with partially paid', function () {
|
||||
$invoice = Invoice::factory()->create([
|
||||
'sub_total' => 100,
|
||||
'total' => 100,
|
||||
'due_amount' => 100,
|
||||
'exchange_rate' => 1,
|
||||
'base_discount_val' => 100,
|
||||
'base_sub_total' => 100,
|
||||
'base_total' => 100,
|
||||
'base_tax' => 100,
|
||||
'base_due_amount' => 100,
|
||||
]);
|
||||
|
||||
$payment = Payment::factory()->raw([
|
||||
'invoice_id' => $invoice->id,
|
||||
'customer_id' => $invoice->customer_id,
|
||||
'exchange_rate' => $invoice->exchange_rate,
|
||||
'amount' => 100,
|
||||
'currency_id' => $invoice->currency_id
|
||||
]);
|
||||
|
||||
$response = postJson("api/v1/payments", $payment)->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('payments', [
|
||||
'payment_number' => $payment['payment_number'],
|
||||
'customer_id' => (string)$payment['customer_id'],
|
||||
'amount' => (string)$payment['amount'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'id' => $invoice['id'],
|
||||
'invoice_number' => $response['data']['invoice']['invoice_number'],
|
||||
'total' => $response['data']['invoice']['total'],
|
||||
'customer_id' => $response['data']['invoice']['customer_id'],
|
||||
'exchange_rate' => $response['data']['invoice']['exchange_rate'],
|
||||
'base_total' => $response['data']['invoice']['base_total'],
|
||||
'paid_status' => $response['data']['invoice']['paid_status'],
|
||||
]);
|
||||
});
|
||||
128
crater/tests/Feature/Admin/RecurringInvoiceTest.php
Normal file
128
crater/tests/Feature/Admin/RecurringInvoiceTest.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Crater\Http\Controllers\V1\Admin\RecurringInvoice\RecurringInvoiceController;
|
||||
use Crater\Http\Requests\RecurringInvoiceRequest;
|
||||
use Crater\Models\InvoiceItem;
|
||||
use Crater\Models\RecurringInvoice;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
use function Pest\Laravel\putJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get recurring invoices', function () {
|
||||
RecurringInvoice::factory()->create();
|
||||
|
||||
getJson('api/v1/recurring-invoices?page=1')
|
||||
->assertOk();
|
||||
});
|
||||
|
||||
test('store user using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
RecurringInvoiceController::class,
|
||||
'store',
|
||||
RecurringInvoiceRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('store recurring invoice', function () {
|
||||
$recurringInvoice = RecurringInvoice::factory()->raw();
|
||||
$recurringInvoice['items'] = [
|
||||
InvoiceItem::factory()->raw()
|
||||
];
|
||||
|
||||
postJson('api/v1/recurring-invoices', $recurringInvoice)
|
||||
->assertStatus(201);
|
||||
|
||||
$recurringInvoice = collect($recurringInvoice)
|
||||
->only([
|
||||
'frequency',
|
||||
])
|
||||
->toArray();
|
||||
|
||||
$this->assertDatabaseHas('recurring_invoices', $recurringInvoice);
|
||||
});
|
||||
|
||||
test('get recurring invoice', function () {
|
||||
$recurringInvoice = RecurringInvoice::factory()->create();
|
||||
|
||||
getJson("api/v1/recurring-invoices/{$recurringInvoice->id}")
|
||||
->assertOk();
|
||||
});
|
||||
|
||||
test('update user using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
RecurringInvoiceController::class,
|
||||
'update',
|
||||
RecurringInvoiceRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('update recurring invoice', function () {
|
||||
$recurringInvoice = RecurringInvoice::factory()->create();
|
||||
$recurringInvoice['items'] = [
|
||||
InvoiceItem::factory()->raw()
|
||||
];
|
||||
|
||||
$new_recurringInvoice = RecurringInvoice::factory()->raw();
|
||||
$new_recurringInvoice['items'] = [
|
||||
InvoiceItem::factory()->raw()
|
||||
];
|
||||
|
||||
putJson("api/v1/recurring-invoices/{$recurringInvoice->id}", $new_recurringInvoice)
|
||||
->assertOk();
|
||||
|
||||
$new_recurringInvoice = collect($new_recurringInvoice)
|
||||
->only([
|
||||
'frequency',
|
||||
])
|
||||
->toArray();
|
||||
|
||||
$this->assertDatabaseHas('recurring_invoices', $new_recurringInvoice);
|
||||
});
|
||||
|
||||
test('delete multiple recurring invoice', function () {
|
||||
$recurringInvoices = RecurringInvoice::factory()->count(3)->create();
|
||||
|
||||
$data = [
|
||||
'ids' => $recurringInvoices->pluck('id'),
|
||||
];
|
||||
|
||||
postJson('api/v1/recurring-invoices/delete', $data)
|
||||
->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
foreach ($recurringInvoices as $recurringInvoice) {
|
||||
$this->assertDeleted($recurringInvoice);
|
||||
}
|
||||
});
|
||||
|
||||
test('calculate frequency for recurring invoice', function () {
|
||||
$data = [
|
||||
'frequency' => '* * 2 * *',
|
||||
'starts_at' => Carbon::now()->format('Y-m-d')
|
||||
];
|
||||
|
||||
$queryString = http_build_query($data, '', '&');
|
||||
|
||||
getJson("api/v1/recurring-invoice-frequency?".$queryString)
|
||||
->assertOk();
|
||||
});
|
||||
46
crater/tests/Feature/Admin/RoleTest.php
Normal file
46
crater/tests/Feature/Admin/RoleTest.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\postJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('create super admin role', function () {
|
||||
$data = [
|
||||
"email" => "loremipsum@gmail.com",
|
||||
"name" => "lorem",
|
||||
"password" => "lorem@123"
|
||||
];
|
||||
$data['companies'] = [
|
||||
[
|
||||
"role" => "super admin",
|
||||
"id" => 1
|
||||
]
|
||||
];
|
||||
|
||||
postJson('api/v1/users', $data)
|
||||
->assertStatus(201);
|
||||
|
||||
$data = collect($data)
|
||||
->only([
|
||||
'email',
|
||||
'name',
|
||||
])
|
||||
->toArray();
|
||||
|
||||
$this->assertDatabaseHas('users', $data);
|
||||
});
|
||||
100
crater/tests/Feature/Admin/TaxTypeTest.php
Normal file
100
crater/tests/Feature/Admin/TaxTypeTest.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Controllers\V1\Admin\Settings\TaxTypesController;
|
||||
use Crater\Http\Requests\TaxTypeRequest;
|
||||
use Crater\Models\TaxType;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
use function Pest\Laravel\deleteJson;
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
use function Pest\Laravel\putJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get tax types', function () {
|
||||
$response = getJson('api/v1/tax-types');
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('create tax type', function () {
|
||||
$taxType = TaxType::factory()->raw();
|
||||
|
||||
postJson('api/v1/tax-types', $taxType);
|
||||
|
||||
$this->assertDatabaseHas('tax_types', $taxType);
|
||||
});
|
||||
|
||||
test('store validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
TaxTypesController::class,
|
||||
'store',
|
||||
TaxTypeRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('get tax type', function () {
|
||||
$taxType = TaxType::factory()->create();
|
||||
|
||||
$response = getJson('api/v1/tax-types/'.$taxType->id);
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('update tax type', function () {
|
||||
$taxType = TaxType::factory()->create();
|
||||
|
||||
$taxType1 = TaxType::factory()->raw();
|
||||
|
||||
$response = putJson('api/v1/tax-types/'.$taxType->id, $taxType1);
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('update validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
TaxTypesController::class,
|
||||
'update',
|
||||
TaxTypeRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('delete tax type', function () {
|
||||
$taxType = TaxType::factory()->create();
|
||||
|
||||
$response = deleteJson('api/v1/tax-types/'.$taxType->id);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'success' => true,
|
||||
]);
|
||||
|
||||
$this->assertDeleted($taxType);
|
||||
});
|
||||
|
||||
|
||||
test('create negative tax type', function () {
|
||||
$taxType = TaxType::factory()->raw([
|
||||
'percent' => -9.99
|
||||
]);
|
||||
|
||||
postJson('api/v1/tax-types', $taxType)
|
||||
->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('tax_types', $taxType);
|
||||
});
|
||||
101
crater/tests/Feature/Admin/UnitTest.php
Normal file
101
crater/tests/Feature/Admin/UnitTest.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Controllers\V1\Admin\Item\UnitsController;
|
||||
use Crater\Http\Requests\UnitRequest;
|
||||
use Crater\Models\Unit;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\deleteJson;
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
use function Pest\Laravel\putJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::find(1);
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('get units', function () {
|
||||
$response = getJson('api/v1/units?page=1');
|
||||
|
||||
$response->assertOk();
|
||||
});
|
||||
|
||||
test('create unit', function () {
|
||||
$data = [
|
||||
'name' => 'unit name',
|
||||
'company_id' => User::find(1)->companies()->first()->id,
|
||||
];
|
||||
|
||||
$response = postJson('api/v1/units', $data);
|
||||
|
||||
$response->assertStatus(201);
|
||||
|
||||
$this->assertDatabaseHas('units', $data);
|
||||
});
|
||||
|
||||
test('store validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
UnitsController::class,
|
||||
'store',
|
||||
UnitRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('get unit', function () {
|
||||
$unit = Unit::factory()->create();
|
||||
|
||||
$response = getJson("api/v1/units/{$unit->id}");
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('units', [
|
||||
'id' => $unit->id,
|
||||
'name' => $unit['name'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('update unit', function () {
|
||||
$unit = Unit::factory()->create();
|
||||
|
||||
$update_unit = [
|
||||
'name' => 'new name',
|
||||
];
|
||||
|
||||
$response = putJson("api/v1/units/{$unit->id}", $update_unit);
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('units', [
|
||||
'id' => $unit->id,
|
||||
'name' => $update_unit['name'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('update validates using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
UnitsController::class,
|
||||
'update',
|
||||
UnitRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('delete unit', function () {
|
||||
$unit = Unit::factory()->create();
|
||||
|
||||
$response = deleteJson("api/v1/units/{$unit->id}");
|
||||
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertDeleted($unit);
|
||||
});
|
||||
96
crater/tests/Feature/Admin/UserTest.php
Normal file
96
crater/tests/Feature/Admin/UserTest.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Controllers\V1\Admin\Users\UsersController;
|
||||
use Crater\Http\Requests\UserRequest;
|
||||
use Crater\Models\User;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Faker\faker;
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
use function Pest\Laravel\putJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::where('role', 'super admin')->first();
|
||||
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
getJson('/api/v1/users')->assertOk();
|
||||
|
||||
test('store user using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
UsersController::class,
|
||||
'store',
|
||||
UserRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
// test('store user', function () {
|
||||
// $data = [
|
||||
// 'name' => faker()->name,
|
||||
// 'email' => faker()->unique()->safeEmail,
|
||||
// 'phone' => faker()->phoneNumber,
|
||||
// 'password' => faker()->password
|
||||
// ];
|
||||
|
||||
// postJson('/api/v1/users', $data)->assertOk();
|
||||
|
||||
// $this->assertDatabaseHas('users', [
|
||||
// 'name' => $data['name'],
|
||||
// 'email' => $data['email'],
|
||||
// 'phone' => $data['phone'],
|
||||
// ]);
|
||||
// });
|
||||
|
||||
test('get user', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
getJson("/api/v1/users/{$user->id}")->assertOk();
|
||||
});
|
||||
|
||||
test('update user using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
UsersController::class,
|
||||
'update',
|
||||
UserRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
// test('update user', function () {
|
||||
// $user = User::factory()->create();
|
||||
|
||||
// $data = [
|
||||
// 'name' => faker()->name,
|
||||
// 'email' => faker()->unique()->safeEmail,
|
||||
// 'phone' => faker()->phoneNumber,
|
||||
// 'password' => faker()->password
|
||||
// ];
|
||||
|
||||
// putJson("/api/v1/users/{$user->id}", $data)->assertOk();
|
||||
|
||||
// $this->assertDatabaseHas('users', [
|
||||
// 'name' => $data['name'],
|
||||
// 'email' => $data['email'],
|
||||
// 'phone' => $data['phone'],
|
||||
// ]);
|
||||
// });
|
||||
|
||||
// test('delete users', function () {
|
||||
// $user = User::factory()->create();
|
||||
// $data['users'] = [$user->id];
|
||||
|
||||
// postJson("/api/v1/users/delete", $data)
|
||||
// ->assertOk();
|
||||
|
||||
// $this->assertDeleted($user);
|
||||
// });
|
||||
28
crater/tests/Feature/Customer/DashboardTest.php
Normal file
28
crater/tests/Feature/Customer/DashboardTest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Customer;
|
||||
|
||||
use Crater\Models\Customer;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$customer = Customer::factory()->create();
|
||||
|
||||
Sanctum::actingAs(
|
||||
$customer,
|
||||
['*'],
|
||||
'customer'
|
||||
);
|
||||
});
|
||||
|
||||
test('customer dashboard', function () {
|
||||
$customer = Auth::guard('customer')->user();
|
||||
|
||||
getJson("api/v1/{$customer->company->slug}/customer/dashboard")->assertOk();
|
||||
});
|
||||
79
crater/tests/Feature/Customer/EstimateTest.php
Normal file
79
crater/tests/Feature/Customer/EstimateTest.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Customer;
|
||||
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\Estimate;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$customer = Customer::factory()->create();
|
||||
|
||||
Sanctum::actingAs(
|
||||
$customer,
|
||||
['*'],
|
||||
'customer'
|
||||
);
|
||||
});
|
||||
|
||||
test('get customer estimates', function () {
|
||||
$customer = Auth::guard('customer')->user();
|
||||
|
||||
getJson("api/v1/{$customer->company->slug}/customer/estimates?page=1")->assertOk();
|
||||
});
|
||||
|
||||
test('get customer estimate', function () {
|
||||
$customer = Auth::guard('customer')->user();
|
||||
|
||||
$estimate = Estimate::factory()->create([
|
||||
'customer_id' => $customer->id
|
||||
]);
|
||||
|
||||
getJson("/api/v1/{$customer->company->slug}/customer/estimates/{$estimate->id}")
|
||||
->assertOk();
|
||||
});
|
||||
|
||||
test('customer estimate mark as accepted', function () {
|
||||
$customer = Auth::guard('customer')->user();
|
||||
|
||||
$estimate = Estimate::factory()->create([
|
||||
'estimate_date' => '1988-07-18',
|
||||
'expiry_date' => '1988-08-18',
|
||||
'customer_id' => $customer->id
|
||||
]);
|
||||
|
||||
$status = [
|
||||
'status' => Estimate::STATUS_ACCEPTED
|
||||
];
|
||||
|
||||
$response = postJson("api/v1/{$customer->company->slug}/customer/estimate/{$estimate->id}/status", $status)
|
||||
->assertOk();
|
||||
|
||||
$this->assertEquals($response->json()['data']['status'], Estimate::STATUS_ACCEPTED);
|
||||
});
|
||||
|
||||
test('customer estimate mark as rejected', function () {
|
||||
$customer = Auth::guard('customer')->user();
|
||||
|
||||
$estimate = Estimate::factory()->create([
|
||||
'estimate_date' => '1988-07-18',
|
||||
'expiry_date' => '1988-08-18',
|
||||
'customer_id' => $customer->id
|
||||
]);
|
||||
|
||||
$status = [
|
||||
'status' => Estimate::STATUS_REJECTED
|
||||
];
|
||||
|
||||
$response = postJson("api/v1/{$customer->company->slug}/customer/estimate/{$estimate->id}/status", $status)
|
||||
->assertOk();
|
||||
|
||||
$this->assertEquals($response->json()['data']['status'], Estimate::STATUS_REJECTED);
|
||||
});
|
||||
41
crater/tests/Feature/Customer/ExpenseTest.php
Normal file
41
crater/tests/Feature/Customer/ExpenseTest.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Customer;
|
||||
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\Expense;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$customer = Customer::factory()->create();
|
||||
|
||||
Sanctum::actingAs(
|
||||
$customer,
|
||||
['*'],
|
||||
'customer'
|
||||
);
|
||||
});
|
||||
|
||||
test('get customer expenses', function () {
|
||||
$customer = Auth::guard('customer')->user();
|
||||
|
||||
getJson("api/v1/{$customer->company->slug}/customer/expenses?page=1")->assertOk();
|
||||
});
|
||||
|
||||
test('get customer expense', function () {
|
||||
$customer = Auth::guard('customer')->user();
|
||||
|
||||
$expense = Expense::factory()->create([
|
||||
'customer_id' => $customer->id,
|
||||
'company_id' => $customer->company->id
|
||||
]);
|
||||
|
||||
getJson("/api/v1/{$customer->company->slug}/customer/expenses/{$expense->id}")
|
||||
->assertOk();
|
||||
});
|
||||
49
crater/tests/Feature/Customer/InvoiceTest.php
Normal file
49
crater/tests/Feature/Customer/InvoiceTest.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Customer;
|
||||
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\Invoice;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$customer = Customer::factory()->create();
|
||||
|
||||
Sanctum::actingAs(
|
||||
$customer,
|
||||
['*'],
|
||||
'customer'
|
||||
);
|
||||
});
|
||||
|
||||
test('get customer invoices', function () {
|
||||
$customer = Auth::guard('customer')->user();
|
||||
|
||||
getJson("api/v1/{$customer->company->slug}/customer/invoices?page=1")->assertOk();
|
||||
});
|
||||
|
||||
test('get customer invoice', function () {
|
||||
$customer = Auth::guard('customer')->user();
|
||||
|
||||
$invoice = Invoice::factory()->create([
|
||||
'customer_id' => $customer->id
|
||||
]);
|
||||
|
||||
getJson("/api/v1/{$customer->company->slug}/customer/invoices/{$invoice->id}")->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'template_name' => $invoice['template_name'],
|
||||
'invoice_number' => $invoice['invoice_number'],
|
||||
'sub_total' => $invoice['sub_total'],
|
||||
'discount' => $invoice['discount'],
|
||||
'customer_id' => $invoice['customer_id'],
|
||||
'total' => $invoice['total'],
|
||||
'tax' => $invoice['tax'],
|
||||
]);
|
||||
});
|
||||
39
crater/tests/Feature/Customer/PaymentTest.php
Normal file
39
crater/tests/Feature/Customer/PaymentTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Customer;
|
||||
|
||||
use Crater\Models\Customer;
|
||||
use Crater\Models\Payment;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$customer = Customer::factory()->create();
|
||||
|
||||
Sanctum::actingAs(
|
||||
$customer,
|
||||
['*'],
|
||||
'customer'
|
||||
);
|
||||
});
|
||||
|
||||
test('get customer payments', function () {
|
||||
$customer = Auth::guard('customer')->user();
|
||||
|
||||
getJson("api/v1/{$customer->company->slug}/customer/payments?page=1")->assertOk();
|
||||
});
|
||||
|
||||
test('get customer payment', function () {
|
||||
$customer = Auth::guard('customer')->user();
|
||||
|
||||
$payment = Payment::factory()->create([
|
||||
'customer_id' => $customer->id
|
||||
]);
|
||||
|
||||
getJson("/api/v1/{$customer->company->slug}/customer/payments/{$payment->id}")->assertOk();
|
||||
});
|
||||
61
crater/tests/Feature/Customer/ProfileTest.php
Normal file
61
crater/tests/Feature/Customer/ProfileTest.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Customer;
|
||||
|
||||
use Crater\Http\Controllers\V1\Customer\General\ProfileController;
|
||||
use Crater\Http\Requests\Customer\CustomerProfileRequest;
|
||||
use Crater\Models\Customer;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use function Pest\Laravel\getJson;
|
||||
use function Pest\Laravel\postJson;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$customer = Customer::factory()->create();
|
||||
|
||||
Sanctum::actingAs(
|
||||
$customer,
|
||||
['*'],
|
||||
'customer'
|
||||
);
|
||||
});
|
||||
|
||||
test('update customer profile using a form request', function () {
|
||||
$this->assertActionUsesFormRequest(
|
||||
ProfileController::class,
|
||||
'updateProfile',
|
||||
CustomerProfileRequest::class
|
||||
);
|
||||
});
|
||||
|
||||
test('update customer profile', function () {
|
||||
$customer = Auth::guard('customer')->user();
|
||||
|
||||
$newCustomer = Customer::factory()->raw([
|
||||
'shipping' => [
|
||||
'name' => 'newName',
|
||||
'address_street_1' => 'address'
|
||||
],
|
||||
'billing' => [
|
||||
'name' => 'newName',
|
||||
'address_street_1' => 'address'
|
||||
]
|
||||
]);
|
||||
|
||||
postJson("api/v1/{$customer->company->slug}/customer/profile", $newCustomer)->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('customers', [
|
||||
'name' => $customer['name'],
|
||||
'email' => $customer['email']
|
||||
]);
|
||||
});
|
||||
|
||||
test('get customer', function () {
|
||||
$customer = Auth::guard('customer')->user();
|
||||
|
||||
getJson("api/v1/{$customer->company->slug}/customer/me")->assertOk();
|
||||
});
|
||||
11
crater/tests/Helpers.php
Normal file
11
crater/tests/Helpers.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
/**
|
||||
* A basic assert example.
|
||||
*/
|
||||
function assertExample(): void
|
||||
{
|
||||
test()->assertTrue(true);
|
||||
}
|
||||
7
crater/tests/Pest.php
Normal file
7
crater/tests/Pest.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
uses(TestCase::class, RefreshDatabase::class)->in('Feature');
|
||||
uses(TestCase::class, RefreshDatabase::class)->in('Unit');
|
||||
31
crater/tests/TestCase.php
Normal file
31
crater/tests/TestCase.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||
use Illuminate\Support\Str;
|
||||
use JMac\Testing\Traits\AdditionalAssertions;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
use CreatesApplication;
|
||||
use AdditionalAssertions;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Factory::guessFactoryNamesUsing(function (string $modelName) {
|
||||
// We can also customise where our factories live too if we want:
|
||||
$namespace = 'Database\\Factories\\';
|
||||
|
||||
// Here we are getting the model name from the class namespace
|
||||
$modelName = Str::afterLast($modelName, '\\');
|
||||
|
||||
// Finally we'll build up the full class path where
|
||||
// Laravel will find our model factory
|
||||
return $namespace.$modelName.'Factory';
|
||||
});
|
||||
}
|
||||
}
|
||||
27
crater/tests/Unit/AddressTest.php
Normal file
27
crater/tests/Unit/AddressTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Address;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('an address belongs to user', function () {
|
||||
$address = Address::factory()->forUser()->create();
|
||||
|
||||
$this->assertTrue($address->user->exists());
|
||||
});
|
||||
|
||||
test('an address belongs to country', function () {
|
||||
$address = Address::factory()->create();
|
||||
|
||||
$this->assertTrue($address->country->exists());
|
||||
});
|
||||
|
||||
test('an address belongs to customer', function () {
|
||||
$address = Address::factory()->forCustomer()->create();
|
||||
|
||||
$this->assertTrue($address->customer()->exists());
|
||||
});
|
||||
45
crater/tests/Unit/CompanySettingTest.php
Normal file
45
crater/tests/Unit/CompanySettingTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Company;
|
||||
use Crater\Models\CompanySetting;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use function Pest\Faker\faker;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('company setting belongs to company', function () {
|
||||
$setting = CompanySetting::factory()->create();
|
||||
|
||||
$this->assertTrue($setting->company()->exists());
|
||||
});
|
||||
|
||||
test('set settings', function () {
|
||||
$key = faker()->name;
|
||||
|
||||
$value = faker()->word;
|
||||
|
||||
$company = Company::factory()->create();
|
||||
|
||||
CompanySetting::setSettings([$key => $value], $company->id);
|
||||
|
||||
$response = CompanySetting::getSetting($key, $company->id);
|
||||
|
||||
$this->assertEquals($value, $response);
|
||||
});
|
||||
|
||||
test('get settings', function () {
|
||||
$key = faker()->name;
|
||||
|
||||
$value = faker()->word;
|
||||
|
||||
$company = Company::factory()->create();
|
||||
|
||||
CompanySetting::setSettings([$key => $value], $company->id);
|
||||
|
||||
$response = CompanySetting::getSettings([$key], $company->id);
|
||||
|
||||
$this->assertEquals([$key => $value], $response->toArray());
|
||||
});
|
||||
29
crater/tests/Unit/CompanyTest.php
Normal file
29
crater/tests/Unit/CompanyTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Company;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('company has many customers', function () {
|
||||
$company = Company::factory()->hasCustomers()->create();
|
||||
|
||||
$this->assertTrue($company->customers()->exists());
|
||||
});
|
||||
|
||||
test('company has many company settings', function () {
|
||||
$company = Company::factory()->hasSettings(5)->create();
|
||||
|
||||
$this->assertCount(5, $company->settings);
|
||||
|
||||
$this->assertTrue($company->settings()->exists());
|
||||
});
|
||||
|
||||
test('a company belongs to many users', function () {
|
||||
$company = Company::factory()->hasUsers(5)->create();
|
||||
|
||||
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $company->users);
|
||||
});
|
||||
20
crater/tests/Unit/CountryTest.php
Normal file
20
crater/tests/Unit/CountryTest.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Address;
|
||||
use Crater\Models\Country;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('country has many addresses', function () {
|
||||
$country = Country::find(1);
|
||||
|
||||
$address = Address::factory()->count(5)->create([
|
||||
'country_id' => $country->id,
|
||||
]);
|
||||
|
||||
$this->assertTrue($country->address()->exists());
|
||||
});
|
||||
23
crater/tests/Unit/CustomFieldTest.php
Normal file
23
crater/tests/Unit/CustomFieldTest.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\CustomField;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('custom field belongs to company', function () {
|
||||
$customField = CustomField::factory()->create();
|
||||
|
||||
$this->assertTrue($customField->company()->exists());
|
||||
});
|
||||
|
||||
test('custom field has many custom field value', function () {
|
||||
$customField = CustomField::factory()->hasCustomFieldValues(5)->create();
|
||||
|
||||
$this->assertCount(5, $customField->customFieldValues);
|
||||
|
||||
$this->assertTrue($customField->customFieldValues()->exists());
|
||||
});
|
||||
21
crater/tests/Unit/CustomFieldValueTest.php
Normal file
21
crater/tests/Unit/CustomFieldValueTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\CustomFieldValue;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('custom field value belongs to company', function () {
|
||||
$fieldValue = CustomFieldValue::factory()->create();
|
||||
|
||||
$this->assertTrue($fieldValue->company()->exists());
|
||||
});
|
||||
|
||||
test('custom field value belongs to custom field', function () {
|
||||
$fieldValue = CustomFieldValue::factory()->forCustomField()->create();
|
||||
|
||||
$this->assertTrue($fieldValue->customField()->exists());
|
||||
});
|
||||
78
crater/tests/Unit/CustomerTest.php
Normal file
78
crater/tests/Unit/CustomerTest.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Address;
|
||||
use Crater\Models\Customer;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('customer has many estimates', function () {
|
||||
$customer = Customer::factory()->hasEstimates(5)->create();
|
||||
|
||||
$this->assertCount(5, $customer->estimates);
|
||||
|
||||
$this->assertTrue($customer->estimates()->exists());
|
||||
});
|
||||
|
||||
test('customer has many expenses', function () {
|
||||
$customer = Customer::factory()->hasExpenses(5)->create();
|
||||
|
||||
$this->assertCount(5, $customer->expenses);
|
||||
|
||||
$this->assertTrue($customer->expenses()->exists());
|
||||
});
|
||||
|
||||
test('customer has many invoices', function () {
|
||||
$customer = Customer::factory()->hasInvoices(5)->create();
|
||||
|
||||
$this->assertCount(5, $customer->invoices);
|
||||
|
||||
$this->assertTrue($customer->invoices()->exists());
|
||||
});
|
||||
|
||||
test('customer has many payments', function () {
|
||||
$customer = Customer::factory()->hasPayments(5)->create();
|
||||
|
||||
$this->assertCount(5, $customer->payments);
|
||||
|
||||
$this->assertTrue($customer->payments()->exists());
|
||||
});
|
||||
|
||||
test('customer has many addresses', function () {
|
||||
$customer = Customer::factory()->hasAddresses(5)->create();
|
||||
|
||||
$this->assertCount(5, $customer->addresses);
|
||||
|
||||
$this->assertTrue($customer->addresses()->exists());
|
||||
});
|
||||
|
||||
test('customer belongs to currency', function () {
|
||||
$customer = Customer::factory()->create();
|
||||
|
||||
$this->assertTrue($customer->currency()->exists());
|
||||
});
|
||||
|
||||
test('customer belongs to company', function () {
|
||||
$customer = Customer::factory()->forCompany()->create();
|
||||
|
||||
$this->assertTrue($customer->company()->exists());
|
||||
});
|
||||
|
||||
it('customer has one billing address', function () {
|
||||
$customer = Customer::factory()->has(Address::factory()->state([
|
||||
'type' => Address::BILLING_TYPE,
|
||||
]))->create();
|
||||
|
||||
$this->assertTrue($customer->billingAddress()->exists());
|
||||
});
|
||||
|
||||
it('customer has one shipping address', function () {
|
||||
$customer = Customer::factory()->has(Address::factory()->state([
|
||||
'type' => Address::SHIPPING_TYPE,
|
||||
]))->create();
|
||||
|
||||
$this->assertTrue($customer->shippingAddress()->exists());
|
||||
});
|
||||
37
crater/tests/Unit/EstimateItemTest.php
Normal file
37
crater/tests/Unit/EstimateItemTest.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Models\EstimateItem;
|
||||
use Crater\Models\Item;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('estimate item belongs to estimate', function () {
|
||||
$estimateItem = EstimateItem::factory()->forEstimate()->create();
|
||||
|
||||
$this->assertTrue($estimateItem->estimate()->exists());
|
||||
});
|
||||
|
||||
test('estimate item belongs to item', function () {
|
||||
$estimateItem = EstimateItem::factory()->create([
|
||||
'item_id' => Item::factory(),
|
||||
'estimate_id' => Estimate::factory(),
|
||||
]);
|
||||
|
||||
$this->assertTrue($estimateItem->item()->exists());
|
||||
});
|
||||
|
||||
|
||||
test('estimate item has many taxes', function () {
|
||||
$estimateItem = EstimateItem::factory()->hasTaxes(5)->create([
|
||||
'estimate_id' => Estimate::factory(),
|
||||
]);
|
||||
|
||||
$this->assertCount(5, $estimateItem->taxes);
|
||||
|
||||
$this->assertTrue($estimateItem->taxes()->exists());
|
||||
});
|
||||
184
crater/tests/Unit/EstimateTest.php
Normal file
184
crater/tests/Unit/EstimateTest.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Requests\EstimatesRequest;
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Models\EstimateItem;
|
||||
use Crater\Models\Tax;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('estimate has many estimate items', function () {
|
||||
$estimate = Estimate::factory()->create();
|
||||
|
||||
$estimate = Estimate::factory()->hasItems(5)->create();
|
||||
|
||||
$this->assertCount(5, $estimate->items);
|
||||
|
||||
$this->assertTrue($estimate->items()->exists());
|
||||
});
|
||||
|
||||
test('estimate belongs to customer', function () {
|
||||
$estimate = Estimate::factory()->forCustomer()->create();
|
||||
|
||||
$this->assertTrue($estimate->customer()->exists());
|
||||
});
|
||||
|
||||
test('estimate has many taxes', function () {
|
||||
$estimate = Estimate::factory()->hasTaxes(5)->create();
|
||||
|
||||
$this->assertCount(5, $estimate->taxes);
|
||||
|
||||
$this->assertTrue($estimate->taxes()->exists());
|
||||
});
|
||||
|
||||
test('create estimate', function () {
|
||||
$estimate = Estimate::factory()->raw();
|
||||
|
||||
$item = EstimateItem::factory()->raw();
|
||||
|
||||
$estimate['items'] = [];
|
||||
array_push($estimate['items'], $item);
|
||||
|
||||
$estimate['taxes'] = [];
|
||||
array_push($estimate['taxes'], Tax::factory()->raw());
|
||||
|
||||
$request = new EstimatesRequest();
|
||||
|
||||
$request->replace($estimate);
|
||||
|
||||
$response = Estimate::createEstimate($request);
|
||||
|
||||
$this->assertDatabaseHas('estimate_items', [
|
||||
'estimate_id' => $response->id,
|
||||
'name' => $item['name'],
|
||||
'description' => $item['description'],
|
||||
'price' => $item['price'],
|
||||
'quantity' => $item['quantity'],
|
||||
'total' => $item['total'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('estimates', [
|
||||
'estimate_number' => $estimate['estimate_number'],
|
||||
'customer_id' => $estimate['customer_id'],
|
||||
'template_name' => $estimate['template_name'],
|
||||
'sub_total' => $estimate['sub_total'],
|
||||
'total' => $estimate['total'],
|
||||
'discount' => $estimate['discount'],
|
||||
'discount_type' => $estimate['discount_type'],
|
||||
'discount_val' => $estimate['discount_val'],
|
||||
'tax' => $estimate['tax'],
|
||||
'notes' => $estimate['notes'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('update estimate', function () {
|
||||
$estimate = Estimate::factory()->hasItems()->hasTaxes()->create();
|
||||
|
||||
$newEstimate = Estimate::factory()->raw();
|
||||
|
||||
$item = EstimateItem::factory()->raw([
|
||||
'estimate_id' => $estimate->id,
|
||||
]);
|
||||
|
||||
$newEstimate['items'] = [];
|
||||
$newEstimate['taxes'] = [];
|
||||
|
||||
array_push($newEstimate['items'], $item);
|
||||
array_push($newEstimate['taxes'], Tax::factory()->raw());
|
||||
|
||||
$request = new EstimatesRequest();
|
||||
|
||||
$request->replace($newEstimate);
|
||||
|
||||
$estimate_number = explode("-", $newEstimate['estimate_number']);
|
||||
|
||||
$number_attributes['estimate_number'] = $estimate_number[0].'-'.sprintf('%06d', intval($estimate_number[1]));
|
||||
|
||||
$estimate->updateEstimate($request);
|
||||
|
||||
$this->assertDatabaseHas('estimate_items', [
|
||||
'estimate_id' => $estimate->id,
|
||||
'name' => $item['name'],
|
||||
'description' => $item['description'],
|
||||
'price' => $item['price'],
|
||||
'total' => $item['total'],
|
||||
'quantity' => $item['quantity'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('estimates', [
|
||||
'estimate_number' => $newEstimate['estimate_number'],
|
||||
'customer_id' => $newEstimate['customer_id'],
|
||||
'template_name' => $newEstimate['template_name'],
|
||||
'sub_total' => $newEstimate['sub_total'],
|
||||
'total' => $newEstimate['total'],
|
||||
'discount' => $newEstimate['discount'],
|
||||
'discount_type' => $newEstimate['discount_type'],
|
||||
'discount_val' => $newEstimate['discount_val'],
|
||||
'tax' => $newEstimate['tax'],
|
||||
'notes' => $newEstimate['notes'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('create items', function () {
|
||||
$estimate = Estimate::factory()->create();
|
||||
|
||||
$items = [];
|
||||
|
||||
$item = EstimateItem::factory()->raw([
|
||||
'invoice_id' => $estimate->id,
|
||||
]);
|
||||
|
||||
array_push($items, $item);
|
||||
|
||||
$request = new Request();
|
||||
|
||||
$request->replace(['items' => $items ]);
|
||||
|
||||
Estimate::createItems($estimate, $request, $estimate->exchange_rate);
|
||||
|
||||
$this->assertDatabaseHas('estimate_items', [
|
||||
'estimate_id' => $estimate->id,
|
||||
'description' => $item['description'],
|
||||
'price' => $item['price'],
|
||||
'tax' => $item['tax'],
|
||||
'quantity' => $item['quantity'],
|
||||
'total' => $item['total'],
|
||||
]);
|
||||
|
||||
$this->assertCount(1, $estimate->items);
|
||||
});
|
||||
|
||||
test('create taxes', function () {
|
||||
$estimate = Estimate::factory()->create();
|
||||
$taxes = [];
|
||||
|
||||
$tax1 = Tax::factory()->raw([
|
||||
'estimate_id' => $estimate->id,
|
||||
]);
|
||||
|
||||
$tax2 = Tax::factory()->raw([
|
||||
'estimate_id' => $estimate->id,
|
||||
]);
|
||||
|
||||
array_push($taxes, $tax1);
|
||||
array_push($taxes, $tax2);
|
||||
|
||||
$request = new Request();
|
||||
|
||||
$request->replace(['taxes' => $taxes ]);
|
||||
|
||||
Estimate::createTaxes($estimate, $request, $estimate->exchange_rate);
|
||||
|
||||
$this->assertCount(2, $estimate->taxes);
|
||||
|
||||
$this->assertDatabaseHas('taxes', [
|
||||
'estimate_id' => $estimate->id,
|
||||
'name' => $tax1['name'],
|
||||
'amount' => $tax1['amount'],
|
||||
]);
|
||||
});
|
||||
26
crater/tests/Unit/ExchangeRateLogTest.php
Normal file
26
crater/tests/Unit/ExchangeRateLogTest.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\ExchangeRateLog;
|
||||
use Crater\Models\Expense;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('an exchange rate log belongs to company', function () {
|
||||
$exchangeRateLog = ExchangeRateLog::factory()->forCompany()->create();
|
||||
|
||||
$this->assertTrue($exchangeRateLog->company->exists());
|
||||
});
|
||||
|
||||
test('add exchange rate log', function () {
|
||||
$expense = Expense::factory()->create();
|
||||
$response = ExchangeRateLog::addExchangeRateLog($expense);
|
||||
|
||||
$this->assertDatabaseHas('exchange_Rate_logs', [
|
||||
'exchange_rate' => $response->exchange_rate,
|
||||
'base_currency_id' => $response->base_currency_id,
|
||||
'currency_id' => $response->currency_id,
|
||||
]);
|
||||
});
|
||||
16
crater/tests/Unit/ExpenseCategoryTest.php
Normal file
16
crater/tests/Unit/ExpenseCategoryTest.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\ExpenseCategory;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('expense category has many expenses', function () {
|
||||
$category = ExpenseCategory::factory()->hasExpenses(5)->create();
|
||||
|
||||
$this->assertCount(5, $category->expenses);
|
||||
$this->assertTrue($category->expenses()->exists());
|
||||
});
|
||||
27
crater/tests/Unit/ExpenseTest.php
Normal file
27
crater/tests/Unit/ExpenseTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Expense;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('expense belongs to category', function () {
|
||||
$expense = Expense::factory()->forCategory()->create();
|
||||
|
||||
$this->assertTrue($expense->category()->exists());
|
||||
});
|
||||
|
||||
test('expense belongs to customer', function () {
|
||||
$expense = Expense::factory()->forCustomer()->create();
|
||||
|
||||
$this->assertTrue($expense->customer()->exists());
|
||||
});
|
||||
|
||||
test('expense belongs to company', function () {
|
||||
$expense = Expense::factory()->forCompany()->create();
|
||||
|
||||
$this->assertTrue($expense->company()->exists());
|
||||
});
|
||||
37
crater/tests/Unit/InvoiceItemTest.php
Normal file
37
crater/tests/Unit/InvoiceItemTest.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\InvoiceItem;
|
||||
use Crater\Models\Item;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('invoice item belongs to invoice', function () {
|
||||
$invoiceItem = InvoiceItem::factory()->forInvoice()->create();
|
||||
|
||||
$this->assertTrue($invoiceItem->invoice()->exists());
|
||||
});
|
||||
|
||||
test('invoice item belongs to item', function () {
|
||||
$invoiceItem = InvoiceItem::factory()->create([
|
||||
'item_id' => Item::factory(),
|
||||
'invoice_id' => Invoice::factory(),
|
||||
]);
|
||||
|
||||
$this->assertTrue($invoiceItem->item()->exists());
|
||||
});
|
||||
|
||||
|
||||
test('invoice item has many taxes', function () {
|
||||
$invoiceItem = InvoiceItem::factory()->hasTaxes(5)->create([
|
||||
'invoice_id' => Invoice::factory(),
|
||||
]);
|
||||
|
||||
$this->assertCount(5, $invoiceItem->taxes);
|
||||
|
||||
$this->assertTrue($invoiceItem->taxes()->exists());
|
||||
});
|
||||
196
crater/tests/Unit/InvoiceTest.php
Normal file
196
crater/tests/Unit/InvoiceTest.php
Normal file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Requests\InvoicesRequest;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\InvoiceItem;
|
||||
use Crater\Models\Tax;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('invoice has many invoice items', function () {
|
||||
$invoice = Invoice::factory()->hasItems(5)->create();
|
||||
|
||||
$this->assertCount(5, $invoice->items);
|
||||
|
||||
$this->assertTrue($invoice->items()->exists());
|
||||
});
|
||||
|
||||
test('invoice has many taxes', function () {
|
||||
$invoice = Invoice::factory()->hasTaxes(5)->create();
|
||||
|
||||
$this->assertCount(5, $invoice->taxes);
|
||||
|
||||
$this->assertTrue($invoice->taxes()->exists());
|
||||
});
|
||||
|
||||
test('invoice has many payments', function () {
|
||||
$invoice = Invoice::factory()->hasPayments(5)->create();
|
||||
|
||||
$this->assertCount(5, $invoice->payments);
|
||||
|
||||
$this->assertTrue($invoice->payments()->exists());
|
||||
});
|
||||
|
||||
test('invoice belongs to customer', function () {
|
||||
$invoice = Invoice::factory()->forCustomer()->create();
|
||||
|
||||
$this->assertTrue($invoice->customer()->exists());
|
||||
});
|
||||
|
||||
test('get previous status', function () {
|
||||
$invoice = Invoice::factory()->create();
|
||||
|
||||
$status = $invoice->getPreviousStatus();
|
||||
|
||||
$this->assertEquals('DRAFT', $status);
|
||||
});
|
||||
|
||||
|
||||
test('create invoice', function () {
|
||||
$invoice = Invoice::factory()->raw();
|
||||
|
||||
$item = InvoiceItem::factory()->raw();
|
||||
|
||||
$invoice['items'] = [];
|
||||
array_push($invoice['items'], $item);
|
||||
|
||||
$invoice['taxes'] = [];
|
||||
array_push($invoice['taxes'], Tax::factory()->raw());
|
||||
|
||||
$request = new InvoicesRequest();
|
||||
|
||||
$request->replace($invoice);
|
||||
|
||||
$invoice_number = explode("-", $invoice['invoice_number']);
|
||||
$number_attributes['invoice_number'] = $invoice_number[0].'-'.sprintf('%06d', intval($invoice_number[1]));
|
||||
|
||||
$response = Invoice::createInvoice($request);
|
||||
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'invoice_id' => $response->id,
|
||||
'name' => $item['name'],
|
||||
'description' => $item['description'],
|
||||
'total' => $item['total'],
|
||||
'quantity' => $item['quantity'],
|
||||
'discount' => $item['discount'],
|
||||
'price' => $item['price'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'invoice_number' => $invoice['invoice_number'],
|
||||
'sub_total' => $invoice['sub_total'],
|
||||
'total' => $invoice['total'],
|
||||
'tax' => $invoice['tax'],
|
||||
'discount' => $invoice['discount'],
|
||||
'notes' => $invoice['notes'],
|
||||
'customer_id' => $invoice['customer_id'],
|
||||
'template_name' => $invoice['template_name'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('update invoice', function () {
|
||||
$invoice = Invoice::factory()->create();
|
||||
|
||||
$newInvoice = Invoice::factory()->raw();
|
||||
|
||||
$item = InvoiceItem::factory()->raw([
|
||||
'invoice_id' => $invoice->id,
|
||||
]);
|
||||
|
||||
$tax = Tax::factory()->raw([
|
||||
'invoice_id' => $invoice->id,
|
||||
]);
|
||||
|
||||
$newInvoice['items'] = [];
|
||||
$newInvoice['taxes'] = [];
|
||||
|
||||
array_push($newInvoice['items'], $item);
|
||||
array_push($newInvoice['taxes'], $tax);
|
||||
|
||||
$request = new InvoicesRequest();
|
||||
|
||||
$request->replace($newInvoice);
|
||||
|
||||
$invoice_number = explode("-", $newInvoice['invoice_number']);
|
||||
|
||||
$number_attributes['invoice_number'] = $invoice_number[0].'-'.sprintf('%06d', intval($invoice_number[1]));
|
||||
|
||||
$response = $invoice->updateInvoice($request);
|
||||
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'invoice_id' => $response->id,
|
||||
'name' => $item['name'],
|
||||
'description' => $item['description'],
|
||||
'total' => $item['total'],
|
||||
'quantity' => $item['quantity'],
|
||||
'discount' => $item['discount'],
|
||||
'price' => $item['price'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'invoice_number' => $newInvoice['invoice_number'],
|
||||
'sub_total' => $newInvoice['sub_total'],
|
||||
'total' => $newInvoice['total'],
|
||||
'tax' => $newInvoice['tax'],
|
||||
'discount' => $newInvoice['discount'],
|
||||
'notes' => $newInvoice['notes'],
|
||||
'customer_id' => $newInvoice['customer_id'],
|
||||
'template_name' => $newInvoice['template_name'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('create items', function () {
|
||||
$invoice = Invoice::factory()->create();
|
||||
|
||||
$items = [];
|
||||
|
||||
$item = InvoiceItem::factory()->raw([
|
||||
'invoice_id' => $invoice->id,
|
||||
]);
|
||||
|
||||
array_push($items, $item);
|
||||
|
||||
$request = new InvoicesRequest();
|
||||
|
||||
$request->replace(['items' => $items ]);
|
||||
|
||||
Invoice::createItems($invoice, $request->items);
|
||||
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'invoice_id' => $invoice->id,
|
||||
'description' => $item['description'],
|
||||
'price' => $item['price'],
|
||||
'tax' => $item['tax'],
|
||||
'quantity' => $item['quantity'],
|
||||
'total' => $item['total'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('create taxes', function () {
|
||||
$invoice = Invoice::factory()->create();
|
||||
|
||||
$taxes = [];
|
||||
|
||||
$tax = Tax::factory()->raw([
|
||||
'invoice_id' => $invoice->id,
|
||||
]);
|
||||
|
||||
array_push($taxes, $tax);
|
||||
|
||||
$request = new Request();
|
||||
|
||||
$request->replace(['taxes' => $taxes ]);
|
||||
|
||||
Invoice::createTaxes($invoice, $request->taxes);
|
||||
|
||||
$this->assertDatabaseHas('taxes', [
|
||||
'invoice_id' => $invoice->id,
|
||||
'name' => $tax['name'],
|
||||
'amount' => $tax['amount'],
|
||||
]);
|
||||
});
|
||||
49
crater/tests/Unit/ItemTest.php
Normal file
49
crater/tests/Unit/ItemTest.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Models\EstimateItem;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\InvoiceItem;
|
||||
use Crater\Models\Item;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('an item belongs to unit', function () {
|
||||
$item = Item::factory()->forUnit()->create();
|
||||
|
||||
$this->assertTrue($item->unit()->exists());
|
||||
});
|
||||
|
||||
test('an item has many taxes', function () {
|
||||
$item = Item::factory()->hasTaxes(5)->create();
|
||||
|
||||
$this->assertCount(5, $item->taxes);
|
||||
$this->assertTrue($item->taxes()->exists());
|
||||
});
|
||||
|
||||
test('an item has many invoice items', function () {
|
||||
$item = Item::factory()->has(InvoiceItem::factory()->count(5)->state([
|
||||
'invoice_id' => Invoice::factory(),
|
||||
]))->create();
|
||||
|
||||
$this->assertCount(5, $item->invoiceItems);
|
||||
|
||||
$this->assertTrue($item->invoiceItems()->exists());
|
||||
});
|
||||
|
||||
test('an item has many estimate items', function () {
|
||||
$item = Item::factory()->has(EstimateItem::factory()
|
||||
->count(5)
|
||||
->state([
|
||||
'estimate_id' => Estimate::factory(),
|
||||
]))
|
||||
->create();
|
||||
|
||||
$this->assertCount(5, $item->estimateItems);
|
||||
|
||||
$this->assertTrue($item->estimateItems()->exists());
|
||||
});
|
||||
23
crater/tests/Unit/PaymentMethodTest.php
Normal file
23
crater/tests/Unit/PaymentMethodTest.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\PaymentMethod;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('payment method has many payment', function () {
|
||||
$method = PaymentMethod::factory()->hasPayments(5)->create();
|
||||
|
||||
$this->assertCount(5, $method->payments);
|
||||
|
||||
$this->assertTrue($method->payments()->exists());
|
||||
});
|
||||
|
||||
test('payment method belongs to company', function () {
|
||||
$method = PaymentMethod::factory()->create();
|
||||
|
||||
$this->assertTrue($method->company()->exists());
|
||||
});
|
||||
27
crater/tests/Unit/PaymentTest.php
Normal file
27
crater/tests/Unit/PaymentTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Payment;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('payment belongs to invoice', function () {
|
||||
$payment = Payment::factory()->forInvoice()->create();
|
||||
|
||||
$this->assertTrue($payment->invoice()->exists());
|
||||
});
|
||||
|
||||
test('payment belongs to customer', function () {
|
||||
$payment = Payment::factory()->forCustomer()->create();
|
||||
|
||||
$this->assertTrue($payment->customer()->exists());
|
||||
});
|
||||
|
||||
test('payment belongs to payment method', function () {
|
||||
$payment = Payment::factory()->forPaymentMethod()->create();
|
||||
|
||||
$this->assertTrue($payment->paymentMethod()->exists());
|
||||
});
|
||||
39
crater/tests/Unit/RecurringInvoiceTest.php
Normal file
39
crater/tests/Unit/RecurringInvoiceTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\RecurringInvoice;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('recurring invoice has many invoices', function () {
|
||||
$recurringInvoice = RecurringInvoice::factory()->hasInvoices(5)->create();
|
||||
|
||||
$this->assertCount(5, $recurringInvoice->invoices);
|
||||
|
||||
$this->assertTrue($recurringInvoice->invoices()->exists());
|
||||
});
|
||||
|
||||
test('recurring invoice has many invoice items', function () {
|
||||
$recurringInvoice = RecurringInvoice::factory()->hasItems(5)->create();
|
||||
|
||||
$this->assertCount(5, $recurringInvoice->items);
|
||||
|
||||
$this->assertTrue($recurringInvoice->items()->exists());
|
||||
});
|
||||
|
||||
test('recurring invoice has many taxes', function () {
|
||||
$recurringInvoice = RecurringInvoice::factory()->hasTaxes(5)->create();
|
||||
|
||||
$this->assertCount(5, $recurringInvoice->taxes);
|
||||
|
||||
$this->assertTrue($recurringInvoice->taxes()->exists());
|
||||
});
|
||||
|
||||
test('recurring invoice belongs to customer', function () {
|
||||
$recurringInvoice = RecurringInvoice::factory()->forCustomer()->create();
|
||||
|
||||
$this->assertTrue($recurringInvoice->customer()->exists());
|
||||
});
|
||||
22
crater/tests/Unit/SettingTest.php
Normal file
22
crater/tests/Unit/SettingTest.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Setting;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use function Pest\Faker\faker;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('set setting', function () {
|
||||
$key = faker()->name;
|
||||
|
||||
$value = faker()->word;
|
||||
|
||||
Setting::setSetting($key, $value);
|
||||
|
||||
$response = Setting::getSetting($key);
|
||||
|
||||
$this->assertEquals($value, $response);
|
||||
});
|
||||
59
crater/tests/Unit/TaxTest.php
Normal file
59
crater/tests/Unit/TaxTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Models\EstimateItem;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\InvoiceItem;
|
||||
use Crater\Models\Tax;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('tax belongs to tax type', function () {
|
||||
$tax = Tax::factory()->create();
|
||||
|
||||
$this->assertTrue($tax->taxType->exists());
|
||||
});
|
||||
|
||||
test('tax belongs to invoice', function () {
|
||||
$tax = Tax::factory()->forInvoice()->create();
|
||||
|
||||
$this->assertTrue($tax->invoice()->exists());
|
||||
});
|
||||
|
||||
test('tax belongs to recurring invoice', function () {
|
||||
$tax = Tax::factory()->forRecurringInvoice()->create();
|
||||
|
||||
$this->assertTrue($tax->recurringInvoice()->exists());
|
||||
});
|
||||
|
||||
test('tax belongs to estimate', function () {
|
||||
$tax = Tax::factory()->forEstimate()->create();
|
||||
|
||||
$this->assertTrue($tax->estimate()->exists());
|
||||
});
|
||||
|
||||
test('tax belongs to invoice item', function () {
|
||||
$tax = Tax::factory()->for(InvoiceItem::factory()->state([
|
||||
'invoice_id' => Invoice::factory(),
|
||||
]))->create();
|
||||
|
||||
$this->assertTrue($tax->invoiceItem()->exists());
|
||||
});
|
||||
|
||||
test('tax belongs to estimate item', function () {
|
||||
$tax = Tax::factory()->for(EstimateItem::factory()->state([
|
||||
'estimate_id' => Estimate::factory(),
|
||||
]))->create();
|
||||
|
||||
$this->assertTrue($tax->estimateItem()->exists());
|
||||
});
|
||||
|
||||
test('tax belongs to item', function () {
|
||||
$tax = Tax::factory()->forItem()->create();
|
||||
|
||||
$this->assertTrue($tax->item()->exists());
|
||||
});
|
||||
16
crater/tests/Unit/TaxTypeTest.php
Normal file
16
crater/tests/Unit/TaxTypeTest.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\TaxType;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('tax type has many taxes', function () {
|
||||
$taxtype = TaxType::factory()->hasTaxes(4)->create();
|
||||
|
||||
$this->assertCount(4, $taxtype->taxes);
|
||||
$this->assertTrue($taxtype->taxes()->exists());
|
||||
});
|
||||
32
crater/tests/Unit/UnitTest.php
Normal file
32
crater/tests/Unit/UnitTest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Unit;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
|
||||
$user = User::where('role', 'super admin')->first();
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('unit has many items', function () {
|
||||
$unit = Unit::factory()->hasItems(5)->create();
|
||||
|
||||
$this->assertTrue($unit->items()->exists());
|
||||
});
|
||||
|
||||
test('unit belongs to company', function () {
|
||||
$unit = Unit::factory()->create();
|
||||
|
||||
$this->assertTrue($unit->company()->exists());
|
||||
});
|
||||
21
crater/tests/Unit/UserTest.php
Normal file
21
crater/tests/Unit/UserTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('user belongs to currency', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->assertTrue($user->currency()->exists());
|
||||
});
|
||||
|
||||
test('user belongs to many companies', function () {
|
||||
$user = User::factory()->hasCompanies(5)->create();
|
||||
|
||||
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $user->companies);
|
||||
});
|
||||
Reference in New Issue
Block a user