v5.0.0 update

This commit is contained in:
Mohit Panjwani
2021-11-30 18:58:19 +05:30
parent d332712c22
commit 082d5cacf2
1253 changed files with 88309 additions and 71741 deletions

View 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",
],
]);
});

View File

@ -0,0 +1,146 @@
<?php
use Crater\Http\Controllers\V1\Admin\Settings\CompanyController;
use Crater\Http\Requests\CompanyRequest;
use Crater\Http\Requests\ProfileRequest;
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 () {
$response = getJson('api/v1/me');
$response->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',
];
$response = putJson('api/v1/company', $company);
$response->assertOk();
$this->assertDatabaseHas('companies', [
'name' => $company['name'],
]);
$this->assertDatabaseHas('addresses', [
'country_id' => $company['country_id'],
'state' => $company['state'],
'city' => $company['city'],
'address_street_1' => $company['address_street_1'],
'address_street_2' => $company['address_street_2'],
'phone' => $company['phone'],
'zip' => $company['zip'],
]);
});
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('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();
});

View File

@ -0,0 +1,69 @@
<?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\deleteJson;
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();
postJson('/api/v1/companies', $company)
->assertStatus(201);
$company = collect($company)
->only([
'name'
])
->toArray();
$this->assertDatabaseHas('companies', $company);
});
test('delete company', function () {
$company = Company::factory()->create();
deleteJson('/api/v1/companies/delete')
->assertOk();
});
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();
});

View File

@ -0,0 +1,74 @@
<?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();
});
test('get supported currencies of currency freak', function () {
$driver = [
'driver' => "currency_freak",
'key' => "9ab5bc6424604778ad61103b628518f8"
];
$queryString = http_build_query($driver, '', '&');
getJson("/api/v1/supported-currencies?".$queryString)
->assertOk();
});
test('get supported currencies of currency layer', function () {
$driver = [
'driver' => "currency_layer",
'key' => "2bb7a25e6f24f42a66fde1f57b5210fd"
];
$queryString = http_build_query($driver, '', '&');
getJson("/api/v1/supported-currencies?".$queryString)
->assertOk();
});
test('get supported currencies of open exchange rate', function () {
$driver = [
'driver' => "open_exchange_rate",
'key' => "c5f404d414d245209923cd4f2d4c3875"
];
$queryString = http_build_query($driver, '', '&');
getJson("/api/v1/supported-currencies?".$queryString)
->assertOk();
});
test('get supported currencies of currency converter', function () {
$driver = [
'driver' => "currency_converter",
'key' => "0a1cef4d5f6fd01cc87a",
'type' => 'FREE'
];
$queryString = http_build_query($driver, '', '&');
getJson("/api/v1/supported-currencies?".$queryString)
->assertOk();
});

View 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);
});

View 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,
]);
});

View 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();

View File

@ -0,0 +1,268 @@
<?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(200);
$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);
});

View File

@ -0,0 +1,101 @@
<?php
use Crater\Http\Controllers\V1\Admin\ExchangeRate\ExchangeRateProviderController;
use Crater\Http\Requests\ExchangeRateProviderRequest;
use Crater\Models\ExchangeRateProvider;
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 exchange rate providers', function () {
getJson('api/v1/exchange-rate-providers?page=1')
->assertOk();
});
test('store user using a form request', function () {
$this->assertActionUsesFormRequest(
ExchangeRateProviderController::class,
'store',
ExchangeRateProviderRequest::class
);
});
test('store recurring invoice', function () {
$exchangeRateProvider = ExchangeRateProvider::factory()->raw();
postJson('api/v1/exchange-rate-providers', $exchangeRateProvider)
->assertStatus(201);
$exchangeRateProvider = collect($exchangeRateProvider)
->only([
'driver',
'key',
'active',
])
->toArray();
$this->assertDatabaseHas('exchange_rate_providers', $exchangeRateProvider);
});
test('get exchange rate provider', function () {
$exchangeRateProvider = ExchangeRateProvider::factory()->create();
getJson("api/v1/exchange-rate-providers/{$exchangeRateProvider->id}")
->assertOk();
});
test('update user using a form request', function () {
$this->assertActionUsesFormRequest(
ExchangeRateProviderController::class,
'update',
ExchangeRateProviderRequest::class
);
});
test('update exchange rate provider', function () {
$exchangeRateProvider = ExchangeRateProvider::factory()->create();
$newExchangeRateProvider = ExchangeRateProvider::factory()->raw();
putJson("api/v1/exchange-rate-providers/{$exchangeRateProvider->id}", $newExchangeRateProvider)
->assertOk();
$newExchangeRateProvider = collect($newExchangeRateProvider)
->only([
'driver',
'key',
'active',
])
->toArray();
$this->assertDatabaseHas('exchange_rate_providers', $newExchangeRateProvider);
});
test('delete exchange rate provider', function () {
$exchangeRateProvider = ExchangeRateProvider::factory()->create([
'active' => false
]);
deleteJson("api/v1/exchange-rate-providers/{$exchangeRateProvider->id}")
->assertOk();
$this->assertDeleted($exchangeRateProvider);
});

View 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);
});

View File

@ -0,0 +1,128 @@
<?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();
postJson('api/v1/expenses', $expense)->assertStatus(201);
$this->assertDatabaseHas('expenses', [
'notes' => $expense['notes'],
'expense_category_id' => $expense['expense_category_id'],
'amount' => $expense['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);
}
});

View 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);
});

View File

@ -0,0 +1,290 @@
<?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',
]);
$response = postJson("api/v1/invoices/{$invoices->id}/clone");
$response
->assertOk();
});
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']
]);
});

View 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();
});

View 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();
});

View 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',
]);
});

View 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);
});

View 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);
});

View File

@ -0,0 +1,157 @@
<?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,
]);
$payment = Payment::factory()->raw([
'invoice_id' => $invoice->id,
'payment_number' => "PAY-000001",
'amount' => $invoice->due_amount
]);
$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
]);
$payment2 = Payment::factory()->raw([
'invoice_id' => $invoice->id
]);
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,
]);
});

View File

@ -0,0 +1,140 @@
<?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([
'starts_at',
'send_automatically',
'next_invoice_at',
'frequency',
'limit_by',
'limit_count',
'limit_date'
])
->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([
'starts_at',
'send_automatically',
'next_invoice_at',
'frequency',
'limit_by',
'limit_count',
'limit_date'
])
->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();
});

View File

@ -0,0 +1,96 @@
<?php
use Crater\Models\Company;
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 customer sales report', function () {
$filters = [
'page' => 1,
'limit' => 15,
'from_date' => '2020-07-18',
'to_date' => '2020-07-20',
];
$queryString = http_build_query($filters, '', '&');
$queryString = Company::find(1)->unique_hash.'?'.$queryString;
$response = getJson('reports/sales/customers/'.$queryString);
$response->assertOk();
});
test('get item sales report', function () {
$filters = [
'page' => 1,
'limit' => 15,
'from_date' => '2020-07-18',
'to_date' => '2020-07-20',
];
$queryString = http_build_query($filters, '', '&');
$queryString = Company::find(1)->unique_hash.'?'.$queryString;
$response = getJson('reports/sales/items/'.$queryString);
$response->assertOk();
});
test('get expenses report', function () {
$filters = [
'page' => 1,
'limit' => 15,
'from_date' => '2020-07-18',
'to_date' => '2020-07-20',
];
$queryString = http_build_query($filters, '', '&');
$queryString = Company::find(1)->unique_hash.'?'.$queryString;
$response = getJson('reports/expenses/'.$queryString);
$response->assertOk();
});
test('get tax summary', function () {
$filters = [
'page' => 1,
'limit' => 15,
'from_date' => '2020-07-18',
'to_date' => '2020-07-20',
];
$queryString = http_build_query($filters, '', '&');
$queryString = Company::find(1)->unique_hash.'?'.$queryString;
$response = getJson('reports/tax-summary/'.$queryString);
$response->assertOk();
});
test('get profit loss', function () {
$filters = [
'page' => 1,
'limit' => 15,
'from_date' => '2020-07-18',
'to_date' => '2020-07-20',
];
$queryString = http_build_query($filters, '', '&');
$queryString = Company::find(1)->unique_hash.'?'.$queryString;
$response = getJson('reports/profit-loss/'.$queryString);
$response->assertOk();
});

View 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 retrospective edits', function () {
getJson('api/v1/config/retrospective-edit-options')
->assertOk();
});

View File

@ -0,0 +1,34 @@
<?php
use Crater\Models\User;
use Illuminate\Support\Arr;
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",
"role" => "super admin",
"password" => "lorem@123"
];
postJson('api/v1/users', $data)->assertStatus(201);
$this->assertDatabaseHas('users', Arr::except($data, ['password']));
});

View 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);
});

View 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);
});

View File

@ -0,0 +1,95 @@
<?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);
});