Moved to _dev
This commit is contained in:
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();
|
||||
});
|
||||
Reference in New Issue
Block a user