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

@ -15,7 +15,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Settings\CompanyController;
use Crater\Http\Controllers\V1\Admin\Settings\CompanyController;
use Crater\Http\Requests\CompanyRequest;
use Crater\Http\Requests\ProfileRequest;
use Crater\Models\User;
@ -16,7 +16,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,

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

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\CustomField\CustomFieldsController;
use Crater\Http\Controllers\V1\Admin\CustomField\CustomFieldsController;
use Crater\Http\Requests\CustomFieldRequest;
use Crater\Models\CustomField;
use Crater\Models\User;
@ -17,7 +17,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -35,10 +35,7 @@ test('create custom field', function () {
$data = CustomField::factory()->raw();
postJson('api/v1/custom-fields', $data)
->assertStatus(200)
->assertJson([
'success' => true,
]);
->assertStatus(201);
$this->assertDatabaseHas('custom_fields', [
'name' => $data['name'],
@ -65,10 +62,7 @@ test('update custom field', function () {
]);
putJson('api/v1/custom-fields/'.$customField->id, $newCustomField)
->assertStatus(200)
->assertJson([
'success' => true,
]);
->assertStatus(200);
$this->assertDatabaseHas('custom_fields', [
'id' => $customField->id,

View File

@ -1,7 +1,8 @@
<?php
use Crater\Http\Controllers\V1\Customer\CustomersController;
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;
@ -16,7 +17,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -31,12 +32,10 @@ test('get customers', function () {
});
test('customer stats', function () {
$customer = User::factory()->create([
'role' => 'customer',
]);
$customer = Customer::factory()->create();
$invoice = Invoice::factory()->create([
'user_id' => $customer->id,
'customer_id' => $customer->id,
]);
$response = getJson("api/v1/customers/{$customer->id}/stats");
@ -45,25 +44,24 @@ test('customer stats', function () {
});
test('create customer', function () {
$customer = User::factory()->raw([
'password' => 'secret',
'role' => 'customer',
$customer = Customer::factory()->raw([
'shipping' => [
'name' => 'newName',
'address_street_1' => 'address'
],
'billing' => [
'name' => 'newName',
'address_street_1' => 'address'
]
]);
$response = postJson('api/v1/customers', $customer);
postJson('api/v1/customers', $customer)
->assertOk();
$this->assertDatabaseHas('users', [
$this->assertDatabaseHas('customers', [
'name' => $customer['name'],
'email' => $customer['email'],
'role' => $customer['role'],
'company_id' => $customer['company_id'],
'email' => $customer['email']
]);
$response
->assertOk()
->assertJson([
'success' => true,
]);
});
test('store validates using a form request', function () {
@ -75,48 +73,47 @@ test('store validates using a form request', function () {
});
test('get customer', function () {
$customer = User::factory()->create([
'role' => 'customer',
]);
$customer = Customer::factory()->create();
$response = getJson("api/v1/customers/{$customer->id}");
$this->assertDatabaseHas('users', [
$this->assertDatabaseHas('customers', [
'id' => $customer->id,
'name' => $customer['name'],
'email' => $customer['email'],
'role' => $customer['role'],
'company_id' => $customer['company_id'],
'email' => $customer['email']
]);
$response->assertOk();
});
test('update customer', function () {
$customer = User::factory()->create([
'role' => 'customer',
]);
$customer = Customer::factory()->create();
$customer1 = User::factory()->raw([
'role' => 'customer',
'name' => 'new name',
$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);
$this->assertDatabaseHas('users', [
'id' => $customer->id,
'name' => $customer1['name'],
'email' => $customer1['email'],
'role' => $customer1['role'],
'company_id' => $customer1['company_id'],
]);
$customer1 = collect($customer1)
->only([
'email'
])
->merge([
'creator_id' => Auth::id()
])
->toArray();
$response
->assertOk()
->assertJson([
'success' => true,
]);
$response->assertOk();
$this->assertDatabaseHas('customers', $customer1);
});
test('update validates using a form request', function () {
@ -143,9 +140,7 @@ test('search customers', function () {
});
test('delete multiple customer', function () {
$customers = User::factory()->count(4)->create([
'role' => 'customer',
]);
$customers = Customer::factory()->count(4)->create();
$ids = $customers->pluck('id');

View File

@ -11,7 +11,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,

View File

@ -1,7 +1,7 @@
<?php
use Crater\Http\Controllers\V1\Estimate\EstimatesController;
use Crater\Http\Controllers\V1\Estimate\SendEstimateController;
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;
@ -23,7 +23,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -39,6 +39,7 @@ test('get estimates', function () {
test('create estimate', function () {
$estimate = Estimate::factory()->raw([
'estimate_number' => 'EST-000006',
'items' => [
EstimateItem::factory()->raw(),
],
@ -57,7 +58,7 @@ test('create estimate', function () {
'discount_val' => $estimate['discount_val'],
'sub_total' => $estimate['sub_total'],
'discount' => $estimate['discount'],
'user_id' => $estimate['user_id'],
'customer_id' => $estimate['customer_id'],
'total' => $estimate['total'],
'notes' => $estimate['notes'],
'tax' => $estimate['tax'],
@ -83,7 +84,9 @@ test('update estimate', function () {
$estimate2 = Estimate::factory()->raw([
'items' => [
EstimateItem::factory()->raw(),
EstimateItem::factory()->raw([
'estimate_id' => $estimate->id
]),
],
'taxes' => [
Tax::factory()->raw([
@ -94,8 +97,6 @@ test('update estimate', function () {
$response = putJson('api/v1/estimates/'.$estimate->id, $estimate2);
$newEstimate = $response->decodeResponseJson()['estimate'];
$this->assertDatabaseHas('estimates', [
'template_name' => $estimate2['template_name'],
'estimate_number' => $estimate2['estimate_number'],
@ -103,18 +104,14 @@ test('update estimate', function () {
'discount_val' => $estimate2['discount_val'],
'sub_total' => $estimate2['sub_total'],
'discount' => $estimate2['discount'],
'user_id' => $estimate2['user_id'],
'customer_id' => $estimate2['customer_id'],
'total' => $estimate2['total'],
'notes' => $estimate2['notes'],
'tax' => $estimate2['tax'],
]);
$this->assertDatabaseHas('taxes', [
'estimate_id' => $newEstimate['id'],
]);
$this->assertDatabaseHas('estimate_items', [
'estimate_id' => $newEstimate['id'],
'estimate_id' => $estimate2['items'][0]['estimate_id'],
]);
$response->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

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Expense\ExpenseCategoriesController;
use Crater\Http\Controllers\V1\Admin\Expense\ExpenseCategoriesController;
use Crater\Http\Requests\ExpenseCategoryRequest;
use Crater\Models\ExpenseCategory;
use Crater\Models\User;
@ -17,7 +17,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -36,7 +36,7 @@ test('create category', function () {
$response = postJson('api/v1/categories', $category);
$response->assertStatus(200);
$response->assertStatus(201);
$this->assertDatabaseHas('expense_categories', [
'name' => $category['name'],

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Expense\ExpensesController;
use Crater\Http\Controllers\V1\Admin\Expense\ExpensesController;
use Crater\Http\Requests\ExpenseRequest;
use Crater\Models\Expense;
use Crater\Models\User;
@ -16,7 +16,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -31,7 +31,7 @@ test('get expenses', function () {
test('create expense', function () {
$expense = Expense::factory()->raw();
postJson('api/v1/expenses', $expense)->assertOk();
postJson('api/v1/expenses', $expense)->assertStatus(201);
$this->assertDatabaseHas('expenses', [
'notes' => $expense['notes'],

View File

@ -14,7 +14,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Invoice\InvoicesController;
use Crater\Http\Controllers\V1\Admin\Invoice\InvoicesController;
use Crater\Http\Requests\InvoicesRequest;
use Crater\Mail\SendInvoiceMail;
use Crater\Models\Invoice;
@ -20,7 +20,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -50,14 +50,15 @@ test('create invoice', function () {
'invoice_number' => $invoice['invoice_number'],
'sub_total' => $invoice['sub_total'],
'discount' => $invoice['discount'],
'user_id' => $invoice['user_id'],
'customer_id' => $invoice['customer_id'],
'total' => $invoice['total'],
'tax' => $invoice['tax'],
]);
$this->assertDatabaseHas('invoice_items', $invoice['items'][0]);
$this->assertDatabaseHas('taxes', $invoice['taxes'][0]);
$this->assertDatabaseHas('invoice_items', [
'item_id' => $invoice['items'][0]['item_id'],
'name' => $invoice['items'][0]['name']
]);
});
test('create invoice as sent', function () {
@ -77,13 +78,14 @@ test('create invoice as sent', function () {
'total' => $invoice['total'],
'tax' => $invoice['tax'],
'discount' => $invoice['discount'],
'user_id' => $invoice['user_id'],
'customer_id' => $invoice['customer_id'],
'template_name' => $invoice['template_name'],
]);
$this->assertDatabaseHas('invoice_items', $invoice['items'][0]);
$this->assertDatabaseHas('taxes', $invoice['taxes'][0]);
$this->assertDatabaseHas('invoice_items', [
'item_id' => $invoice['items'][0]['item_id'],
'name' => $invoice['items'][0]['name']
]);
});
test('store validates using a form request', function () {
@ -114,13 +116,14 @@ test('update invoice', function () {
'total' => $invoice2['total'],
'tax' => $invoice2['tax'],
'discount' => $invoice2['discount'],
'user_id' => $invoice2['user_id'],
'customer_id' => $invoice2['customer_id'],
'template_name' => $invoice2['template_name'],
]);
$this->assertDatabaseHas('invoice_items', $invoice2['items'][0]);
$this->assertDatabaseHas('taxes', $invoice2['taxes'][0]);
$this->assertDatabaseHas('invoice_items', [
'item_id' => $invoice2['items'][0]['item_id'],
'name' => $invoice2['items'][0]['name']
]);
});
test('update validates using a form request', function () {
@ -252,10 +255,7 @@ test('clone invoice', function () {
$response = postJson("api/v1/invoices/{$invoices->id}/clone");
$response
->assertOk()
->assertJson([
'success' => true,
]);
->assertOk();
});
test('create invoice with negative tax', function () {
@ -277,10 +277,14 @@ test('create invoice with negative tax', function () {
'total' => $invoice['total'],
'tax' => $invoice['tax'],
'discount' => $invoice['discount'],
'user_id' => $invoice['user_id'],
'customer_id' => $invoice['customer_id'],
]);
$this->assertDatabaseHas('invoice_items', $invoice['items'][0]);
$this->assertDatabaseHas('invoice_items', [
'name' => $invoice['items'][0]['name'],
]);
$this->assertDatabaseHas('taxes', $invoice['taxes'][0]);
$this->assertDatabaseHas('taxes', [
'tax_type_id' => $invoice['taxes'][0]['tax_type_id']
]);
});

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Item\ItemsController;
use Crater\Http\Controllers\V1\Admin\Item\ItemsController;
use Crater\Http\Requests\ItemsRequest;
use Crater\Models\Item;
use Crater\Models\Tax;
@ -17,7 +17,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -49,7 +49,7 @@ test('create item', function () {
]);
$this->assertDatabaseHas('taxes', [
'item_id' => $response->getData()->item->id,
'item_id' => $response->getData()->data->id,
]);
$response->assertOk();

View File

@ -11,7 +11,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,

View File

@ -11,8 +11,9 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
['*']
@ -25,7 +26,7 @@ test('next number', function () {
$response = getJson('api/v1/next-number?key='.$key);
$response->assertStatus(200)->assertJson([
'nextNumber' => '000001',
'nextNumber' => 'INV-000001',
]);
$key = 'estimate';
@ -33,7 +34,7 @@ test('next number', function () {
$response = getJson('api/v1/next-number?key='.$key);
$response->assertStatus(200)->assertJson([
'nextNumber' => '000001',
'nextNumber' => 'EST-000001',
]);
$key = 'payment';
@ -41,6 +42,6 @@ test('next number', function () {
$response = getJson('api/v1/next-number?key='.$key);
$response->assertStatus(200)->assertJson([
'nextNumber' => '000001',
'nextNumber' => 'PAY-000001',
]);
});

View File

@ -15,7 +15,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -30,7 +30,7 @@ test('retrieve notes', function () {
test('create note', function () {
$note = Note::factory()->raw();
postJson('/api/v1/notes', $note)->assertStatus(200);
postJson('/api/v1/notes', $note)->assertStatus(201);
$this->assertDatabaseHas('notes', $note);
});
@ -39,10 +39,7 @@ test('retrieve note', function () {
$note = Note::factory()->create();
getJson("/api/v1/notes/{$note->id}")
->assertStatus(200)
->assertJson([
'note' => $note->toArray(),
]);
->assertStatus(200);
});
test('update note', function () {

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Payment\PaymentMethodsController;
use Crater\Http\Controllers\V1\Admin\Payment\PaymentMethodsController;
use Crater\Http\Requests\PaymentMethodRequest;
use Crater\Models\PaymentMethod;
use Crater\Models\User;
@ -17,7 +17,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -34,14 +34,12 @@ test('get payment methods', function () {
test('create payment method', function () {
$data = [
'name' => 'demo name',
'company_id' => User::find(1)->company_id,
'company_id' => User::find(1)->companies()->first()->id,
];
$response = postJson('api/v1/payment-methods', $data);
$response->assertOk();
$method = $response->decodeResponseJson()['paymentMethod'];
$response->assertStatus(201);
$this->assertDatabaseHas('payment_methods', [
'name' => $data['name'],

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Payment\PaymentsController;
use Crater\Http\Controllers\V1\Admin\Payment\PaymentsController;
use Crater\Http\Requests\PaymentRequest;
use Crater\Mail\SendPaymentMail;
use Crater\Models\Invoice;
@ -19,7 +19,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -49,6 +49,7 @@ test('create payment', function () {
$payment = Payment::factory()->raw([
'invoice_id' => $invoice->id,
'payment_number' => "PAY-000001",
'amount' => $invoice->due_amount
]);
$response = postJson('api/v1/payments', $payment);
@ -57,7 +58,7 @@ test('create payment', function () {
$this->assertDatabaseHas('payments', [
'payment_number' => $payment['payment_number'],
'user_id' => $payment['user_id'],
'customer_id' => $payment['customer_id'],
'amount' => $payment['amount'],
'company_id' => $payment['company_id'],
]);
@ -72,22 +73,24 @@ test('store validates using a form request', function () {
});
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([
'payment_number' => $payment->payment_number,
'invoice_id' => $invoice->id
]);
$response = putJson("api/v1/payments/{$payment->id}", $payment2);
$response->assertOk();
putJson("api/v1/payments/{$payment->id}", $payment2)
->assertOk();
$this->assertDatabaseHas('payments', [
'id' => $payment->id,
'payment_number' => $payment2['payment_number'],
'user_id' => $payment2['user_id'],
'customer_id' => $payment2['customer_id'],
'amount' => $payment2['amount'],
]);
});

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

@ -12,7 +12,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,

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

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Settings\TaxTypesController;
use Crater\Http\Controllers\V1\Admin\Settings\TaxTypesController;
use Crater\Http\Requests\TaxTypeRequest;
use Crater\Models\TaxType;
use Crater\Models\User;
@ -18,7 +18,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -53,10 +53,7 @@ test('get tax type', function () {
$response = getJson('api/v1/tax-types/'.$taxType->id);
$response->assertOk()
->assertJson([
'taxType' => $taxType->toArray(),
]);
$response->assertOk();
});
test('update tax type', function () {
@ -66,10 +63,7 @@ test('update tax type', function () {
$response = putJson('api/v1/tax-types/'.$taxType->id, $taxType1);
$response->assertOk()
->assertJson([
'taxType' => $taxType1,
]);
$response->assertOk();
});
test('update validates using a form request', function () {
@ -100,7 +94,7 @@ test('create negative tax type', function () {
]);
postJson('api/v1/tax-types', $taxType)
->assertOk();
->assertStatus(201);
$this->assertDatabaseHas('tax_types', $taxType);
});

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Item\UnitsController;
use Crater\Http\Controllers\V1\Admin\Item\UnitsController;
use Crater\Http\Requests\UnitRequest;
use Crater\Models\Unit;
use Crater\Models\User;
@ -17,7 +17,7 @@ beforeEach(function () {
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -34,12 +34,12 @@ test('get units', function () {
test('create unit', function () {
$data = [
'name' => 'unit name',
'company_id' => User::find(1)->company_id,
'company_id' => User::find(1)->companies()->first()->id,
];
$response = postJson('api/v1/units', $data);
$response->assertOk();
$response->assertStatus(201);
$this->assertDatabaseHas('units', $data);
});

View File

@ -1,6 +1,6 @@
<?php
use Crater\Http\Controllers\V1\Users\UsersController;
use Crater\Http\Controllers\V1\Admin\Users\UsersController;
use Crater\Http\Requests\UserRequest;
use Crater\Models\User;
use Laravel\Sanctum\Sanctum;
@ -16,7 +16,7 @@ beforeEach(function () {
$user = User::where('role', 'super admin')->first();
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(

View File

@ -1,22 +1,11 @@
<?php
use Crater\Models\Address;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('an address belongs to user', function () {
@ -30,3 +19,9 @@ test('an address belongs to country', function () {
$this->assertTrue($address->country->exists());
});
test('an address belongs to customer', function () {
$address = Address::factory()->forCustomer()->create();
$this->assertTrue($address->customer()->exists());
});

View File

@ -2,23 +2,12 @@
use Crater\Models\Company;
use Crater\Models\CompanySetting;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
use function Pest\Faker\faker;
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->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('company setting belongs to company', function () {
@ -52,5 +41,5 @@ test('get settings', function () {
$response = CompanySetting::getSettings([$key], $company->id);
$this->assertEquals([$key => $value], $response);
$this->assertEquals([$key => $value], $response->toArray());
});

View File

@ -1,28 +1,17 @@
<?php
use Crater\Models\Company;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('company has one user', function () {
$company = Company::factory()->hasUser()->create();
test('company has one customer', function () {
$company = Company::factory()->hasCustomer()->create();
$this->assertTrue($company->user()->exists());
$this->assertTrue($company->customer()->exists());
});
test('company has many company setings', function () {
@ -32,3 +21,9 @@ test('company has many company setings', function () {
$this->assertTrue($company->settings()->exists());
});
test('a company belongs to many users', function () {
$company = Company::factory()->hasUsers(5)->create();
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $company->users);
});

View File

@ -2,22 +2,11 @@
use Crater\Models\Address;
use Crater\Models\Country;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::where('role', 'super admin')->first();
$this->withHeaders([
'company' => $user->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('country has many addresses', function () {

View File

@ -1,22 +1,11 @@
<?php
use Crater\Models\CustomField;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('custom field belongs to company', function () {
@ -26,9 +15,9 @@ test('custom field belongs to company', function () {
});
test('custom field has many custom field value', function () {
$customField = CustomField::factory()->hascustomFieldValue(5)->create();
$customField = CustomField::factory()->hasCustomFieldValues(5)->create();
$this->assertCount(5, $customField->customFieldValue);
$this->assertCount(5, $customField->customFieldValues);
$this->assertTrue($customField->customFieldValue()->exists());
$this->assertTrue($customField->customFieldValues()->exists());
});

View File

@ -1,22 +1,11 @@
<?php
use Crater\Models\CustomFieldValue;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::find(1);
$this->withHeaders([
'company' => $user->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('custom field value belongs to company', function () {

View File

@ -0,0 +1,78 @@
<?php
use Crater\Models\Address;
use Crater\Models\Customer;
use Illuminate\Support\Facades\Artisan;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
});
test('customer has many estimates', function () {
$customer = Customer::factory()->hasEstimates(5)->create();
$this->assertCount(5, $customer->estimates);
$this->assertTrue($customer->estimates()->exists());
});
test('customer has many expenses', function () {
$customer = Customer::factory()->hasExpenses(5)->create();
$this->assertCount(5, $customer->expenses);
$this->assertTrue($customer->expenses()->exists());
});
test('customer has many invoices', function () {
$customer = Customer::factory()->hasInvoices(5)->create();
$this->assertCount(5, $customer->invoices);
$this->assertTrue($customer->invoices()->exists());
});
test('customer has many payments', function () {
$customer = Customer::factory()->hasPayments(5)->create();
$this->assertCount(5, $customer->payments);
$this->assertTrue($customer->payments()->exists());
});
test('customer has many addresses', function () {
$customer = Customer::factory()->hasAddresses(5)->create();
$this->assertCount(5, $customer->addresses);
$this->assertTrue($customer->addresses()->exists());
});
test('customer belongs to currency', function () {
$customer = Customer::factory()->create();
$this->assertTrue($customer->currency()->exists());
});
test('customer belongs to company', function () {
$customer = Customer::factory()->forCompany()->create();
$this->assertTrue($customer->company()->exists());
});
it('customer has one billing address', function () {
$customer = Customer::factory()->has(Address::factory()->state([
'type' => Address::BILLING_TYPE,
]))->create();
$this->assertTrue($customer->billingAddress()->exists());
});
it('customer has one shipping address', function () {
$customer = Customer::factory()->has(Address::factory()->state([
'type' => Address::SHIPPING_TYPE,
]))->create();
$this->assertTrue($customer->shippingAddress()->exists());
});

View File

@ -3,22 +3,11 @@
use Crater\Models\Estimate;
use Crater\Models\EstimateItem;
use Crater\Models\Item;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::where('role', 'super admin')->first();
$this->withHeaders([
'company' => $user->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('estimate item belongs to estimate', function () {

View File

@ -1,25 +1,15 @@
<?php
use Crater\Http\Requests\EstimatesRequest;
use Crater\Models\Estimate;
use Crater\Models\EstimateItem;
use Crater\Models\Tax;
use Crater\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::where('role', 'super admin')->first();
$this->withHeaders([
'company' => $user->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('estimate has many estimate items', function () {
@ -32,10 +22,10 @@ test('estimate has many estimate items', function () {
$this->assertTrue($estimate->items()->exists());
});
test('estimate belongs to user', function () {
$estimate = Estimate::factory()->forUser()->create();
test('estimate belongs to customer', function () {
$estimate = Estimate::factory()->forCustomer()->create();
$this->assertTrue($estimate->user()->exists());
$this->assertTrue($estimate->customer()->exists());
});
test('estimate has many taxes', function () {
@ -46,38 +36,6 @@ test('estimate has many taxes', function () {
$this->assertTrue($estimate->taxes()->exists());
});
test('get next estimate number', function () {
$estimate = Estimate::factory()->create();
$prefix = $estimate->getEstimatePrefixAttribute();
$nextNumber = $estimate->getNextEstimateNumber($prefix);
$estimate1 = Estimate::factory()->create();
$this->assertEquals($prefix.'-'.$nextNumber, $estimate1['estimate_number']);
});
test('get estimate prefix attribute', function () {
$estimate = Estimate::factory()->create();
$num = $estimate->getEstimateNumAttribute();
$prefix = $estimate->getEstimatePrefixAttribute();
$this->assertEquals($prefix.'-'.$num, $estimate['estimate_number']);
});
test('get estimate num attribute', function () {
$estimate = Estimate::factory()->create();
$prefix = $estimate->getEstimatePrefixAttribute();
$num = $estimate->getEstimateNumAttribute();
$this->assertEquals($prefix.'-'.$num, $estimate['estimate_number']);
});
test('create estimate', function () {
$estimate = Estimate::factory()->raw();
@ -89,7 +47,7 @@ test('create estimate', function () {
$estimate['taxes'] = [];
array_push($estimate['taxes'], Tax::factory()->raw());
$request = new Request();
$request = new EstimatesRequest();
$request->replace($estimate);
@ -106,7 +64,7 @@ test('create estimate', function () {
$this->assertDatabaseHas('estimates', [
'estimate_number' => $estimate['estimate_number'],
'user_id' => $estimate['user_id'],
'customer_id' => $estimate['customer_id'],
'template_name' => $estimate['template_name'],
'sub_total' => $estimate['sub_total'],
'total' => $estimate['total'],
@ -133,7 +91,7 @@ test('update estimate', function () {
array_push($newEstimate['items'], $item);
array_push($newEstimate['taxes'], Tax::factory()->raw());
$request = new Request();
$request = new EstimatesRequest();
$request->replace($newEstimate);
@ -154,7 +112,7 @@ test('update estimate', function () {
$this->assertDatabaseHas('estimates', [
'estimate_number' => $newEstimate['estimate_number'],
'user_id' => $newEstimate['user_id'],
'customer_id' => $newEstimate['customer_id'],
'template_name' => $newEstimate['template_name'],
'sub_total' => $newEstimate['sub_total'],
'total' => $newEstimate['total'],
@ -181,7 +139,7 @@ test('create items', function () {
$request->replace(['items' => $items ]);
Estimate::createItems($estimate, $request);
Estimate::createItems($estimate, $request, $estimate->exchange_rate);
$this->assertDatabaseHas('estimate_items', [
'estimate_id' => $estimate->id,
@ -214,7 +172,7 @@ test('create taxes', function () {
$request->replace(['taxes' => $taxes ]);
Estimate::createTaxes($estimate, $request);
Estimate::createTaxes($estimate, $request, $estimate->exchange_rate);
$this->assertCount(2, $estimate->taxes);

View File

@ -0,0 +1,26 @@
<?php
use Crater\Models\ExchangeRateLog;
use Crater\Models\Expense;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
});
test('an exchange rate log belongs to company', function () {
$exchangeRateLog = ExchangeRateLog::factory()->forCompany()->create();
$this->assertTrue($exchangeRateLog->company->exists());
});
test('add exchange rate log', function () {
$expense = Expense::factory()->create();
$response = ExchangeRateLog::addExchangeRateLog($expense, $expense->currency_id);
$this->assertDatabaseHas('exchange_Rate_logs', [
'exchange_rate' => $response->exchange_rate,
'base_currency_id' => $response->base_currency_id,
'currency_id' => $response->currency_id,
]);
});

View File

@ -1,22 +1,11 @@
<?php
use Crater\Models\ExpenseCategory;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::where('role', 'super admin')->first();
$this->withHeaders([
'company' => $user->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('expense category has many expenses', function () {

View File

@ -1,22 +1,11 @@
<?php
use Crater\Models\Expense;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::where('role', 'super admin')->first();
$this->withHeaders([
'company' => $user->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('expense belongs to category', function () {
@ -25,8 +14,14 @@ test('expense belongs to category', function () {
$this->assertTrue($expense->category()->exists());
});
test('expense belongs to user', function () {
$expense = Expense::factory()->forUser()->create();
test('expense belongs to customer', function () {
$expense = Expense::factory()->forCustomer()->create();
$this->assertTrue($expense->user()->exists());
$this->assertTrue($expense->customer()->exists());
});
test('expense belongs to company', function () {
$expense = Expense::factory()->forCompany()->create();
$this->assertTrue($expense->company()->exists());
});

View File

@ -3,22 +3,11 @@
use Crater\Models\Invoice;
use Crater\Models\InvoiceItem;
use Crater\Models\Item;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::where('role', 'super admin')->first();
$this->withHeaders([
'company' => $user->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('invoice item belongs to invoice', function () {

View File

@ -1,27 +1,17 @@
<?php
use Crater\Http\Requests\InvoicesRequest;
use Crater\Models\Invoice;
use Crater\Models\InvoiceItem;
use Crater\Models\Tax;
use Crater\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'UnitSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'PaymentMethodSeeder', '--force' => true]);
$user = User::where('role', 'super admin')->first();
$this->withHeaders([
'company' => $user->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('invoice has many invoice items', function () {
@ -48,45 +38,12 @@ test('invoice has many payments', function () {
$this->assertTrue($invoice->payments()->exists());
});
test('invoice belongs to user', function () {
$invoice = Invoice::factory()->forUser()->create();
test('invoice belongs to customer', function () {
$invoice = Invoice::factory()->forCustomer()->create();
$this->assertTrue($invoice->user()->exists());
$this->assertTrue($invoice->customer()->exists());
});
test('get next invoice number', function () {
$invoice = Invoice::factory()->create();
$prefix = $invoice->getInvoicePrefixAttribute();
$nextNumber = $invoice->getNextInvoiceNumber($prefix);
$invoice1 = Invoice::factory()->create();
$this->assertEquals($prefix.'-'.$nextNumber, $invoice1['invoice_number']);
});
test('get invoice prefix attribute', function () {
$invoice = Invoice::factory()->create();
$num = $invoice->getInvoiceNumAttribute();
$prefix = $invoice->getInvoicePrefixAttribute();
$this->assertEquals($prefix.'-'.$num, $invoice['invoice_number']);
});
test('get invoice num attribute', function () {
$invoice = Invoice::factory()->create();
$num = $invoice->getInvoiceNumAttribute();
$prefix = $invoice->getInvoicePrefixAttribute();
$this->assertEquals($prefix.'-'.$num, $invoice['invoice_number']);
});
test('get previous status', function () {
$invoice = Invoice::factory()->create();
@ -107,7 +64,7 @@ test('create invoice', function () {
$invoice['taxes'] = [];
array_push($invoice['taxes'], Tax::factory()->raw());
$request = new Request();
$request = new InvoicesRequest();
$request->replace($invoice);
@ -133,7 +90,7 @@ test('create invoice', function () {
'tax' => $invoice['tax'],
'discount' => $invoice['discount'],
'notes' => $invoice['notes'],
'user_id' => $invoice['user_id'],
'customer_id' => $invoice['customer_id'],
'template_name' => $invoice['template_name'],
]);
});
@ -184,7 +141,7 @@ test('update invoice', function () {
'tax' => $newInvoice['tax'],
'discount' => $newInvoice['discount'],
'notes' => $newInvoice['notes'],
'user_id' => $newInvoice['user_id'],
'customer_id' => $newInvoice['customer_id'],
'template_name' => $newInvoice['template_name'],
]);
});
@ -200,11 +157,11 @@ test('create items', function () {
array_push($items, $item);
$request = new Request();
$request = new InvoicesRequest();
$request->replace(['items' => $items ]);
Invoice::createItems($invoice, $request);
Invoice::createItems($invoice, $request, $invoice->exchange_rate);
$this->assertDatabaseHas('invoice_items', [
'invoice_id' => $invoice->id,
@ -231,7 +188,7 @@ test('create taxes', function () {
$request->replace(['taxes' => $taxes ]);
Invoice::createTaxes($invoice, $request);
Invoice::createTaxes($invoice, $request, $invoice->exchange_rate);
$this->assertDatabaseHas('taxes', [
'invoice_id' => $invoice->id,

View File

@ -5,24 +5,12 @@ use Crater\Models\EstimateItem;
use Crater\Models\Invoice;
use Crater\Models\InvoiceItem;
use Crater\Models\Item;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'UnitSeeder', '--force' => true]);
$user = User::where('role', 'super admin')->first();
$this->withHeaders([
'company' => $user->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('an item belongs to unit', function () {

View File

@ -1,24 +1,13 @@
<?php
use Crater\Models\PaymentMethod;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'UnitSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'PaymentMethodSeeder', '--force' => true]);
$user = User::where('role', 'super admin')->first();
$this->withHeaders([
'company' => $user->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('payment method has many payment', function () {

View File

@ -0,0 +1,29 @@
<?php
use Crater\Models\Payment;
use Illuminate\Support\Facades\Artisan;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'UnitSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'PaymentMethodSeeder', '--force' => true]);
});
test('payment belongs to invoice', function () {
$payment = Payment::factory()->forInvoice()->create();
$this->assertTrue($payment->invoice()->exists());
});
test('payment belongs to customer', function () {
$payment = Payment::factory()->forCustomer()->create();
$this->assertTrue($payment->customer()->exists());
});
test('payment belongs to payment method', function () {
$payment = Payment::factory()->forPaymentMethod()->create();
$this->assertTrue($payment->paymentMethod()->exists());
});

View File

@ -0,0 +1,39 @@
<?php
use Crater\Models\RecurringInvoice;
use Illuminate\Support\Facades\Artisan;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
});
test('recurring invoice has many invoices', function () {
$recurringInvoice = RecurringInvoice::factory()->hasInvoices(5)->create();
$this->assertCount(5, $recurringInvoice->invoices);
$this->assertTrue($recurringInvoice->invoices()->exists());
});
test('recurring invoice has many invoice items', function () {
$recurringInvoice = RecurringInvoice::factory()->hasItems(5)->create();
$this->assertCount(5, $recurringInvoice->items);
$this->assertTrue($recurringInvoice->items()->exists());
});
test('recurring invoice has many taxes', function () {
$recurringInvoice = RecurringInvoice::factory()->hasTaxes(5)->create();
$this->assertCount(5, $recurringInvoice->taxes);
$this->assertTrue($recurringInvoice->taxes()->exists());
});
test('recurring invoice belongs to customer', function () {
$recurringInvoice = RecurringInvoice::factory()->forCustomer()->create();
$this->assertTrue($recurringInvoice->customer()->exists());
});

View File

@ -1,23 +1,12 @@
<?php
use Crater\Models\Setting;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
use function Pest\Faker\faker;
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->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('set setting', function () {
@ -31,15 +20,3 @@ test('set setting', function () {
$this->assertEquals($value, $response);
});
test('get setting', function () {
$key = faker()->name;
$value = faker()->word;
Setting::setSetting($key, $value);
$response = Setting::getSetting($key);
$this->assertEquals($value, $response);
});

View File

@ -5,23 +5,11 @@ use Crater\Models\EstimateItem;
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;
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->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('tax belongs to tax type', function () {
@ -36,6 +24,12 @@ test('tax belongs to invoice', function () {
$this->assertTrue($tax->invoice()->exists());
});
test('tax belongs to recurring invoice', function () {
$tax = Tax::factory()->forRecurringInvoice()->create();
$this->assertTrue($tax->recurringInvoice()->exists());
});
test('tax belongs to estimate', function () {
$tax = Tax::factory()->forEstimate()->create();

View File

@ -1,23 +1,11 @@
<?php
use Crater\Models\TaxType;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::where('role', 'super admin')->first();
$this->withHeaders([
'company' => $user->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('tax type has many taxes', function () {

View File

@ -12,7 +12,7 @@ beforeEach(function () {
$user = User::where('role', 'super admin')->first();
$this->withHeaders([
'company' => $user->company_id,
'company' => $user->companies()->first()->id,
]);
Sanctum::actingAs(
$user,
@ -23,7 +23,6 @@ beforeEach(function () {
test('unit has many items', function () {
$unit = Unit::factory()->hasItems(5)->create();
$this->assertCount(5, $unit->items);
$this->assertTrue($unit->items()->exists());
});

View File

@ -4,27 +4,10 @@ use Crater\Models\Address;
use Crater\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$user = User::where('role', 'super admin')->first();
$this->withHeaders([
'company' => $user->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('user has many estimates', function () {
$user = User::factory()->hasEstimates(5)->create();
$this->assertCount(5, $user->estimates);
$this->assertTrue($user->estimates()->exists());
});
test('user belongs to currency', function () {
@ -33,23 +16,16 @@ test('user belongs to currency', function () {
$this->assertTrue($user->currency()->exists());
});
test('user belongs to company', function () {
$user = User::factory()->forCompany()->create();
$this->assertTrue($user->company()->exists());
});
test('user has many addresses', function () {
$user = User::factory()->hasAddresses(2)->create();
$this->assertTrue($user->addresses()->exists());
});
it('user has many expenses', function () {
$user = User::factory()->hasExpenses(5)->create();
test('user belongs to many companies', function () {
$user = User::factory()->hasCompanies(5)->create();
$this->assertCount(5, $user->expenses);
$this->assertTrue($user->expenses()->exists());
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $user->companies);
});
it('user has one billing address', function () {
@ -68,20 +44,6 @@ it('user has one shipping address', function () {
$this->assertTrue($user->shippingAddress()->exists());
});
test('user has many payments', function () {
$user = User::factory()->hasPayments(5)->create();
$this->assertCount(5, $user->payments);
$this->assertTrue($user->payments()->exists());
});
test('user has many invoices', function () {
$user = User::factory()->hasInvoices(5)->create();
$this->assertCount(5, $user->invoices);
$this->assertTrue($user->invoices()->exists());
});
test('create customer', function () {
$customer = User::factory()->raw([
'role' => 'customer',

View File

@ -1,73 +0,0 @@
<?php
use Crater\Models\Payment;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
use Laravel\Sanctum\Sanctum;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'UnitSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'PaymentMethodSeeder', '--force' => true]);
$user = User::where('role', 'super admin')->first();
$this->withHeaders([
'company' => $user->company_id,
]);
Sanctum::actingAs(
$user,
['*']
);
});
test('payment belongs to invoice', function () {
$payment = Payment::factory()->forInvoice()->create();
$this->assertTrue($payment->invoice()->exists());
});
test('payment belongs to user', function () {
$payment = Payment::factory()->create();
$this->assertTrue($payment->user()->exists());
});
test('payment belongs to payment method', function () {
$payment = Payment::factory()->forPaymentMethod()->create();
$this->assertTrue($payment->paymentMethod()->exists());
});
test('get payment num attribute', function () {
$payment = Payment::factory()->create();
$num_attribute = $payment->getPaymentNumAttribute();
$prefix_attribute = $payment->getPaymentPrefixAttribute();
$this->assertEquals($prefix_attribute.'-'.$num_attribute, $payment['payment_number']);
});
test('get payment prefix attribute', function () {
$payment = Payment::factory()->create();
$num_attribute = $payment->getPaymentNumAttribute();
$prefix_attribute = $payment->getPaymentPrefixAttribute();
$this->assertEquals($prefix_attribute.'-'.$num_attribute, $payment['payment_number']);
});
test('get next payment number', function () {
$payment = Payment::factory()->create();
$prefix_attribute = $payment->getPaymentPrefixAttribute();
$next_payment_number = $payment->getNextPaymentNumber($prefix_attribute);
$payment2 = Payment::factory()->create();
$this->assertEquals($prefix_attribute.'-'.$next_payment_number, $payment2['payment_number']);
});

View File

@ -0,0 +1,50 @@
<?php
use Crater\Http\Requests\CompaniesRequest;
test('companies request validation rules', function () {
$request = new CompaniesRequest();
$this->assertEquals(
[
'name' => [
'required',
'string'
],
'address.name' => [
'nullable',
],
'address.address_street_1' => [
'nullable',
],
'address.address_street_2' => [
'nullable',
],
'address.city' => [
'nullable',
],
'address.state' => [
'nullable',
],
'address.country_id' => [
'nullable',
],
'address.zip' => [
'nullable',
],
'address.phone' => [
'nullable',
],
'address.fax' => [
'nullable',
],
],
$request->rules()
);
});
test('companies request authorize', function () {
$request = new CompaniesRequest();
$this->assertTrue($request->authorize());
});

View File

@ -0,0 +1,25 @@
<?php
use Crater\Http\Requests\CompanyRequest;
test('company request validation rules', function () {
$request = new CompanyRequest();
$this->assertEquals(
[
'name' => [
'required',
],
'country_id' => [
'required',
],
],
$request->rules()
);
});
test('company request authorize', function () {
$request = new CompanyRequest();
$this->assertTrue($request->authorize());
});

View File

@ -2,53 +2,97 @@
use Crater\Http\Requests\CustomerRequest;
test('customer request post validation rules', function () {
test('customer request validation rules', function () {
$request = new CustomerRequest();
$request->setMethod('POST');
$this->assertEquals(
[
'name' => [
'required',
],
'addresses.*.address_street_1' => [
'max:255',
],
'addresses.*.address_street_2' => [
'max:255',
],
'email' => [
'email',
'nullable',
'unique:users,email',
'unique:customers,email',
],
],
$request->rules()
);
});
test('customer request put validation rules', function () {
$request = new CustomerRequest();
$request->setMethod('PUT');
$this->assertEquals(
[
'name' => [
'required',
],
'addresses.*.address_street_1' => [
'max:255',
],
'addresses.*.address_street_2' => [
'max:255',
],
'email' => [
'email',
'password' => [
'nullable',
'unique:users,email',
],
'phone' => [
'nullable',
],
'company_name' => [
'nullable',
],
'contact_name' => [
'nullable',
],
'website' => [
'nullable',
],
'prefix' => [
'nullable',
],
'enable_portal' => [
'nullable',
],
'currency_id' => [
'nullable',
],
'billing.name' => [
'nullable',
],
'billing.address_street_1' => [
'nullable',
],
'billing.address_street_2' => [
'nullable',
],
'billing.city' => [
'nullable',
],
'billing.state' => [
'nullable',
],
'billing.country_id' => [
'nullable',
],
'billing.zip' => [
'nullable',
],
'billing.phone' => [
'nullable',
],
'billing.fax' => [
'nullable',
],
'shipping.name' => [
'nullable',
],
'shipping.address_street_1' => [
'nullable',
],
'shipping.address_street_2' => [
'nullable',
],
'shipping.city' => [
'nullable',
],
'shipping.state' => [
'nullable',
],
'shipping.country_id' => [
'nullable',
],
'shipping.zip' => [
'nullable',
],
'shipping.phone' => [
'nullable',
],
'shipping.fax' => [
'nullable',
]
],
$request->rules()
);

View File

@ -1,8 +1,7 @@
<?php
use Crater\Http\Requests\EstimatesRequest;
use Crater\Models\Estimate;
use Crater\Rules\UniqueNumber;
use Illuminate\Validation\Rule;
test('estimate request validation rules', function () {
$request = new EstimatesRequest();
@ -13,10 +12,14 @@ test('estimate request validation rules', function () {
'required',
],
'expiry_date' => [
'nullable',
],
'customer_id' => [
'required',
],
'user_id' => [
'estimate_number' => [
'required',
Rule::unique('estimates')->where('company_id', null)
],
'discount' => [
'required',
@ -41,7 +44,7 @@ test('estimate request validation rules', function () {
'array',
],
'items.*.description' => [
'max:255',
'nullable',
],
'items.*' => [
'required',
@ -56,10 +59,6 @@ test('estimate request validation rules', function () {
'items.*.price' => [
'required',
],
'estimate_number' => [
'required',
new UniqueNumber(Estimate::class),
],
],
$request->rules()
);

View File

@ -16,7 +16,7 @@ test('expense request validation rules', function () {
'amount' => [
'required',
],
'user_id' => [
'customer_id' => [
'nullable',
],
'notes' => [

View File

@ -1,8 +1,7 @@
<?php
use Crater\Http\Requests\InvoicesRequest;
use Crater\Models\Invoice;
use Crater\Rules\UniqueNumber;
use Illuminate\Validation\Rule;
test('invoice request validation rules', function () {
$request = new InvoicesRequest();
@ -13,10 +12,14 @@ test('invoice request validation rules', function () {
'required',
],
'due_date' => [
'nullable',
],
'customer_id' => [
'required',
],
'user_id' => [
'invoice_number' => [
'required',
Rule::unique('invoices')->where('company_id', null)
],
'discount' => [
'required',
@ -45,7 +48,7 @@ test('invoice request validation rules', function () {
'max:255',
],
'items.*.description' => [
'max:255',
'nullable',
],
'items.*.name' => [
'required',
@ -56,10 +59,6 @@ test('invoice request validation rules', function () {
'items.*.price' => [
'required',
],
'invoice_number' => [
'required',
new UniqueNumber(Invoice::class),
],
],
$request->rules()
);

View File

@ -1,6 +1,7 @@
<?php
use Crater\Http\Requests\PaymentMethodRequest;
use Illuminate\Validation\Rule;
test('payment method request validation rules', function () {
$request = new PaymentMethodRequest();
@ -9,7 +10,8 @@ test('payment method request validation rules', function () {
[
'name' => [
'required',
'unique:payment_methods,name',
Rule::unique('units')
->where('payment_methods', $request->header('company')),
],
],
$request->rules()

View File

@ -1,8 +1,7 @@
<?php
use Crater\Http\Requests\PaymentRequest;
use Crater\Models\Payment;
use Crater\Rules\UniqueNumber;
use Illuminate\Validation\Rule;
test('payment request validation rules', function () {
$request = new PaymentRequest();
@ -12,7 +11,7 @@ test('payment request validation rules', function () {
'payment_date' => [
'required',
],
'user_id' => [
'customer_id' => [
'required',
],
'amount' => [
@ -20,7 +19,7 @@ test('payment request validation rules', function () {
],
'payment_number' => [
'required',
new UniqueNumber(Payment::class),
Rule::unique('payments')->where('company_id', null)
],
'invoice_id' => [
'nullable',

View File

@ -0,0 +1,68 @@
<?php
use Crater\Http\Requests\RecurringInvoiceRequest;
test('recurring invoice request validation rules', function () {
$request = new RecurringInvoiceRequest();
$this->assertEquals(
[
'starts_at' => [
'required'
],
'send_automatically' => [
'required',
'boolean'
],
'customer_id' => [
'required'
],
'discount' => [
'required',
],
'discount_val' => [
'required',
],
'sub_total' => [
'required',
],
'total' => [
'required',
],
'tax' => [
'required',
],
'status' => [
'required'
],
'exchange_rate' => [
'nullable'
],
'frequency' => [
'required'
],
'limit_by' => [
'required'
],
'limit_count' => [
'required_if:limit_by,COUNT',
],
'limit_date' => [
'required_if:limit_by,DATE',
],
'items' => [
'required'
],
'items.*' => [
'required'
]
],
$request->rules()
);
});
test('recurring invoice request authorize', function () {
$request = new RecurringInvoiceRequest();
$this->assertTrue($request->authorize());
});

View File

@ -1,6 +1,7 @@
<?php
use Crater\Http\Requests\UnitRequest;
use Illuminate\Validation\Rule;
test('unit request validation rules', function () {
$request = new UnitRequest();
@ -9,7 +10,8 @@ test('unit request validation rules', function () {
[
'name' => [
'required',
'unique:units,name',
Rule::unique('units')
->where('company_id', $request->header('company')),
],
],
$request->rules()

View File

@ -10,9 +10,6 @@ test('update settings request rules', function () {
'settings' => [
'required',
],
'settings.*' => [
'required',
],
],
$request->rules()
);