mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-31 21:51:10 -04:00
v5.0.0 update
This commit is contained in:
@ -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());
|
||||
});
|
||||
@ -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());
|
||||
});
|
||||
@ -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);
|
||||
});
|
||||
@ -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 () {
|
||||
@ -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());
|
||||
});
|
||||
@ -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 () {
|
||||
78
tests/Unit/Model/CustomerTest.php
Normal file
78
tests/Unit/Model/CustomerTest.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Address;
|
||||
use Crater\Models\Customer;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('customer has many estimates', function () {
|
||||
$customer = Customer::factory()->hasEstimates(5)->create();
|
||||
|
||||
$this->assertCount(5, $customer->estimates);
|
||||
|
||||
$this->assertTrue($customer->estimates()->exists());
|
||||
});
|
||||
|
||||
test('customer has many expenses', function () {
|
||||
$customer = Customer::factory()->hasExpenses(5)->create();
|
||||
|
||||
$this->assertCount(5, $customer->expenses);
|
||||
|
||||
$this->assertTrue($customer->expenses()->exists());
|
||||
});
|
||||
|
||||
test('customer has many invoices', function () {
|
||||
$customer = Customer::factory()->hasInvoices(5)->create();
|
||||
|
||||
$this->assertCount(5, $customer->invoices);
|
||||
|
||||
$this->assertTrue($customer->invoices()->exists());
|
||||
});
|
||||
|
||||
test('customer has many payments', function () {
|
||||
$customer = Customer::factory()->hasPayments(5)->create();
|
||||
|
||||
$this->assertCount(5, $customer->payments);
|
||||
|
||||
$this->assertTrue($customer->payments()->exists());
|
||||
});
|
||||
|
||||
test('customer has many addresses', function () {
|
||||
$customer = Customer::factory()->hasAddresses(5)->create();
|
||||
|
||||
$this->assertCount(5, $customer->addresses);
|
||||
|
||||
$this->assertTrue($customer->addresses()->exists());
|
||||
});
|
||||
|
||||
test('customer belongs to currency', function () {
|
||||
$customer = Customer::factory()->create();
|
||||
|
||||
$this->assertTrue($customer->currency()->exists());
|
||||
});
|
||||
|
||||
test('customer belongs to company', function () {
|
||||
$customer = Customer::factory()->forCompany()->create();
|
||||
|
||||
$this->assertTrue($customer->company()->exists());
|
||||
});
|
||||
|
||||
it('customer has one billing address', function () {
|
||||
$customer = Customer::factory()->has(Address::factory()->state([
|
||||
'type' => Address::BILLING_TYPE,
|
||||
]))->create();
|
||||
|
||||
$this->assertTrue($customer->billingAddress()->exists());
|
||||
});
|
||||
|
||||
it('customer has one shipping address', function () {
|
||||
$customer = Customer::factory()->has(Address::factory()->state([
|
||||
'type' => Address::SHIPPING_TYPE,
|
||||
]))->create();
|
||||
|
||||
$this->assertTrue($customer->shippingAddress()->exists());
|
||||
});
|
||||
@ -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 () {
|
||||
@ -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);
|
||||
|
||||
26
tests/Unit/Model/ExchangeRateLogTest.php
Normal file
26
tests/Unit/Model/ExchangeRateLogTest.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\ExchangeRateLog;
|
||||
use Crater\Models\Expense;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('an exchange rate log belongs to company', function () {
|
||||
$exchangeRateLog = ExchangeRateLog::factory()->forCompany()->create();
|
||||
|
||||
$this->assertTrue($exchangeRateLog->company->exists());
|
||||
});
|
||||
|
||||
test('add exchange rate log', function () {
|
||||
$expense = Expense::factory()->create();
|
||||
$response = ExchangeRateLog::addExchangeRateLog($expense, $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,
|
||||
]);
|
||||
});
|
||||
@ -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 () {
|
||||
@ -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());
|
||||
});
|
||||
@ -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 () {
|
||||
@ -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,
|
||||
@ -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 () {
|
||||
@ -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 () {
|
||||
29
tests/Unit/Model/PaymentTest.php
Normal file
29
tests/Unit/Model/PaymentTest.php
Normal 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());
|
||||
});
|
||||
39
tests/Unit/Model/RecurringInvoiceTest.php
Normal file
39
tests/Unit/Model/RecurringInvoiceTest.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\RecurringInvoice;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('recurring invoice has many invoices', function () {
|
||||
$recurringInvoice = RecurringInvoice::factory()->hasInvoices(5)->create();
|
||||
|
||||
$this->assertCount(5, $recurringInvoice->invoices);
|
||||
|
||||
$this->assertTrue($recurringInvoice->invoices()->exists());
|
||||
});
|
||||
|
||||
test('recurring invoice has many invoice items', function () {
|
||||
$recurringInvoice = RecurringInvoice::factory()->hasItems(5)->create();
|
||||
|
||||
$this->assertCount(5, $recurringInvoice->items);
|
||||
|
||||
$this->assertTrue($recurringInvoice->items()->exists());
|
||||
});
|
||||
|
||||
test('recurring invoice has many taxes', function () {
|
||||
$recurringInvoice = RecurringInvoice::factory()->hasTaxes(5)->create();
|
||||
|
||||
$this->assertCount(5, $recurringInvoice->taxes);
|
||||
|
||||
$this->assertTrue($recurringInvoice->taxes()->exists());
|
||||
});
|
||||
|
||||
test('recurring invoice belongs to customer', function () {
|
||||
$recurringInvoice = RecurringInvoice::factory()->forCustomer()->create();
|
||||
|
||||
$this->assertTrue($recurringInvoice->customer()->exists());
|
||||
});
|
||||
@ -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);
|
||||
});
|
||||
@ -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();
|
||||
|
||||
@ -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 () {
|
||||
@ -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());
|
||||
});
|
||||
|
||||
@ -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',
|
||||
@ -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']);
|
||||
});
|
||||
50
tests/Unit/Request/CompaniesTest.php
Normal file
50
tests/Unit/Request/CompaniesTest.php
Normal 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());
|
||||
});
|
||||
25
tests/Unit/Request/CompanyTest.php
Normal file
25
tests/Unit/Request/CompanyTest.php
Normal 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());
|
||||
});
|
||||
@ -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()
|
||||
);
|
||||
|
||||
@ -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()
|
||||
);
|
||||
|
||||
@ -16,7 +16,7 @@ test('expense request validation rules', function () {
|
||||
'amount' => [
|
||||
'required',
|
||||
],
|
||||
'user_id' => [
|
||||
'customer_id' => [
|
||||
'nullable',
|
||||
],
|
||||
'notes' => [
|
||||
|
||||
@ -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()
|
||||
);
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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',
|
||||
|
||||
68
tests/Unit/Request/RecurringInvoiceTest.php
Normal file
68
tests/Unit/Request/RecurringInvoiceTest.php
Normal 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());
|
||||
});
|
||||
@ -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()
|
||||
|
||||
@ -10,9 +10,6 @@ test('update settings request rules', function () {
|
||||
'settings' => [
|
||||
'required',
|
||||
],
|
||||
'settings.*' => [
|
||||
'required',
|
||||
],
|
||||
],
|
||||
$request->rules()
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user