mirror of
https://github.com/crater-invoice/crater.git
synced 2025-12-16 02:12:54 -05:00
v5.0.0 update
This commit is contained in:
27
tests/Unit/Model/AddressTest.php
Normal file
27
tests/Unit/Model/AddressTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Address;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('an address belongs to user', function () {
|
||||
$address = Address::factory()->forUser()->create();
|
||||
|
||||
$this->assertTrue($address->user->exists());
|
||||
});
|
||||
|
||||
test('an address belongs to country', function () {
|
||||
$address = Address::factory()->create();
|
||||
|
||||
$this->assertTrue($address->country->exists());
|
||||
});
|
||||
|
||||
test('an address belongs to customer', function () {
|
||||
$address = Address::factory()->forCustomer()->create();
|
||||
|
||||
$this->assertTrue($address->customer()->exists());
|
||||
});
|
||||
45
tests/Unit/Model/CompanySettingTest.php
Normal file
45
tests/Unit/Model/CompanySettingTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Company;
|
||||
use Crater\Models\CompanySetting;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use function Pest\Faker\faker;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('company setting belongs to company', function () {
|
||||
$setting = CompanySetting::factory()->create();
|
||||
|
||||
$this->assertTrue($setting->company()->exists());
|
||||
});
|
||||
|
||||
test('set settings', function () {
|
||||
$key = faker()->name;
|
||||
|
||||
$value = faker()->word;
|
||||
|
||||
$company = Company::factory()->create();
|
||||
|
||||
CompanySetting::setSettings([$key => $value], $company->id);
|
||||
|
||||
$response = CompanySetting::getSetting($key, $company->id);
|
||||
|
||||
$this->assertEquals($value, $response);
|
||||
});
|
||||
|
||||
test('get settings', function () {
|
||||
$key = faker()->name;
|
||||
|
||||
$value = faker()->word;
|
||||
|
||||
$company = Company::factory()->create();
|
||||
|
||||
CompanySetting::setSettings([$key => $value], $company->id);
|
||||
|
||||
$response = CompanySetting::getSettings([$key], $company->id);
|
||||
|
||||
$this->assertEquals([$key => $value], $response->toArray());
|
||||
});
|
||||
29
tests/Unit/Model/CompanyTest.php
Normal file
29
tests/Unit/Model/CompanyTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Company;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('company has one customer', function () {
|
||||
$company = Company::factory()->hasCustomer()->create();
|
||||
|
||||
$this->assertTrue($company->customer()->exists());
|
||||
});
|
||||
|
||||
test('company has many company setings', function () {
|
||||
$company = Company::factory()->hasSettings(5)->create();
|
||||
|
||||
$this->assertCount(5, $company->settings);
|
||||
|
||||
$this->assertTrue($company->settings()->exists());
|
||||
});
|
||||
|
||||
test('a company belongs to many users', function () {
|
||||
$company = Company::factory()->hasUsers(5)->create();
|
||||
|
||||
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $company->users);
|
||||
});
|
||||
20
tests/Unit/Model/CountryTest.php
Normal file
20
tests/Unit/Model/CountryTest.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Address;
|
||||
use Crater\Models\Country;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('country has many addresses', function () {
|
||||
$country = Country::find(1);
|
||||
|
||||
$address = Address::factory()->count(5)->create([
|
||||
'country_id' => $country->id,
|
||||
]);
|
||||
|
||||
$this->assertTrue($country->address()->exists());
|
||||
});
|
||||
23
tests/Unit/Model/CustomFieldTest.php
Normal file
23
tests/Unit/Model/CustomFieldTest.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\CustomField;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('custom field belongs to company', function () {
|
||||
$customField = CustomField::factory()->create();
|
||||
|
||||
$this->assertTrue($customField->company()->exists());
|
||||
});
|
||||
|
||||
test('custom field has many custom field value', function () {
|
||||
$customField = CustomField::factory()->hasCustomFieldValues(5)->create();
|
||||
|
||||
$this->assertCount(5, $customField->customFieldValues);
|
||||
|
||||
$this->assertTrue($customField->customFieldValues()->exists());
|
||||
});
|
||||
21
tests/Unit/Model/CustomFieldValueTest.php
Normal file
21
tests/Unit/Model/CustomFieldValueTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\CustomFieldValue;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('custom field value belongs to company', function () {
|
||||
$fieldValue = CustomFieldValue::factory()->create();
|
||||
|
||||
$this->assertTrue($fieldValue->company()->exists());
|
||||
});
|
||||
|
||||
test('custom field value belongs to custom field', function () {
|
||||
$fieldValue = CustomFieldValue::factory()->forCustomField()->create();
|
||||
|
||||
$this->assertTrue($fieldValue->customField()->exists());
|
||||
});
|
||||
78
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());
|
||||
});
|
||||
37
tests/Unit/Model/EstimateItemTest.php
Normal file
37
tests/Unit/Model/EstimateItemTest.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Models\EstimateItem;
|
||||
use Crater\Models\Item;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('estimate item belongs to estimate', function () {
|
||||
$estimateItem = EstimateItem::factory()->forEstimate()->create();
|
||||
|
||||
$this->assertTrue($estimateItem->estimate()->exists());
|
||||
});
|
||||
|
||||
test('estimate item belongs to item', function () {
|
||||
$estimateItem = EstimateItem::factory()->create([
|
||||
'item_id' => Item::factory(),
|
||||
'estimate_id' => Estimate::factory(),
|
||||
]);
|
||||
|
||||
$this->assertTrue($estimateItem->item()->exists());
|
||||
});
|
||||
|
||||
|
||||
test('estimate item has many taxes', function () {
|
||||
$estimateItem = EstimateItem::factory()->hasTaxes(5)->create([
|
||||
'estimate_id' => Estimate::factory(),
|
||||
]);
|
||||
|
||||
$this->assertCount(5, $estimateItem->taxes);
|
||||
|
||||
$this->assertTrue($estimateItem->taxes()->exists());
|
||||
});
|
||||
184
tests/Unit/Model/EstimateTest.php
Normal file
184
tests/Unit/Model/EstimateTest.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Requests\EstimatesRequest;
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Models\EstimateItem;
|
||||
use Crater\Models\Tax;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('estimate has many estimate items', function () {
|
||||
$estimate = Estimate::factory()->create();
|
||||
|
||||
$estimate = Estimate::factory()->hasItems(5)->create();
|
||||
|
||||
$this->assertCount(5, $estimate->items);
|
||||
|
||||
$this->assertTrue($estimate->items()->exists());
|
||||
});
|
||||
|
||||
test('estimate belongs to customer', function () {
|
||||
$estimate = Estimate::factory()->forCustomer()->create();
|
||||
|
||||
$this->assertTrue($estimate->customer()->exists());
|
||||
});
|
||||
|
||||
test('estimate has many taxes', function () {
|
||||
$estimate = Estimate::factory()->hasTaxes(5)->create();
|
||||
|
||||
$this->assertCount(5, $estimate->taxes);
|
||||
|
||||
$this->assertTrue($estimate->taxes()->exists());
|
||||
});
|
||||
|
||||
test('create estimate', function () {
|
||||
$estimate = Estimate::factory()->raw();
|
||||
|
||||
$item = EstimateItem::factory()->raw();
|
||||
|
||||
$estimate['items'] = [];
|
||||
array_push($estimate['items'], $item);
|
||||
|
||||
$estimate['taxes'] = [];
|
||||
array_push($estimate['taxes'], Tax::factory()->raw());
|
||||
|
||||
$request = new EstimatesRequest();
|
||||
|
||||
$request->replace($estimate);
|
||||
|
||||
$response = Estimate::createEstimate($request);
|
||||
|
||||
$this->assertDatabaseHas('estimate_items', [
|
||||
'estimate_id' => $response->id,
|
||||
'name' => $item['name'],
|
||||
'description' => $item['description'],
|
||||
'price' => $item['price'],
|
||||
'quantity' => $item['quantity'],
|
||||
'total' => $item['total'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('estimates', [
|
||||
'estimate_number' => $estimate['estimate_number'],
|
||||
'customer_id' => $estimate['customer_id'],
|
||||
'template_name' => $estimate['template_name'],
|
||||
'sub_total' => $estimate['sub_total'],
|
||||
'total' => $estimate['total'],
|
||||
'discount' => $estimate['discount'],
|
||||
'discount_type' => $estimate['discount_type'],
|
||||
'discount_val' => $estimate['discount_val'],
|
||||
'tax' => $estimate['tax'],
|
||||
'notes' => $estimate['notes'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('update estimate', function () {
|
||||
$estimate = Estimate::factory()->hasItems()->hasTaxes()->create();
|
||||
|
||||
$newEstimate = Estimate::factory()->raw();
|
||||
|
||||
$item = EstimateItem::factory()->raw([
|
||||
'estimate_id' => $estimate->id,
|
||||
]);
|
||||
|
||||
$newEstimate['items'] = [];
|
||||
$newEstimate['taxes'] = [];
|
||||
|
||||
array_push($newEstimate['items'], $item);
|
||||
array_push($newEstimate['taxes'], Tax::factory()->raw());
|
||||
|
||||
$request = new EstimatesRequest();
|
||||
|
||||
$request->replace($newEstimate);
|
||||
|
||||
$estimate_number = explode("-", $newEstimate['estimate_number']);
|
||||
|
||||
$number_attributes['estimate_number'] = $estimate_number[0].'-'.sprintf('%06d', intval($estimate_number[1]));
|
||||
|
||||
$estimate->updateEstimate($request);
|
||||
|
||||
$this->assertDatabaseHas('estimate_items', [
|
||||
'estimate_id' => $estimate->id,
|
||||
'name' => $item['name'],
|
||||
'description' => $item['description'],
|
||||
'price' => $item['price'],
|
||||
'total' => $item['total'],
|
||||
'quantity' => $item['quantity'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('estimates', [
|
||||
'estimate_number' => $newEstimate['estimate_number'],
|
||||
'customer_id' => $newEstimate['customer_id'],
|
||||
'template_name' => $newEstimate['template_name'],
|
||||
'sub_total' => $newEstimate['sub_total'],
|
||||
'total' => $newEstimate['total'],
|
||||
'discount' => $newEstimate['discount'],
|
||||
'discount_type' => $newEstimate['discount_type'],
|
||||
'discount_val' => $newEstimate['discount_val'],
|
||||
'tax' => $newEstimate['tax'],
|
||||
'notes' => $newEstimate['notes'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('create items', function () {
|
||||
$estimate = Estimate::factory()->create();
|
||||
|
||||
$items = [];
|
||||
|
||||
$item = EstimateItem::factory()->raw([
|
||||
'invoice_id' => $estimate->id,
|
||||
]);
|
||||
|
||||
array_push($items, $item);
|
||||
|
||||
$request = new Request();
|
||||
|
||||
$request->replace(['items' => $items ]);
|
||||
|
||||
Estimate::createItems($estimate, $request, $estimate->exchange_rate);
|
||||
|
||||
$this->assertDatabaseHas('estimate_items', [
|
||||
'estimate_id' => $estimate->id,
|
||||
'description' => $item['description'],
|
||||
'price' => $item['price'],
|
||||
'tax' => $item['tax'],
|
||||
'quantity' => $item['quantity'],
|
||||
'total' => $item['total'],
|
||||
]);
|
||||
|
||||
$this->assertCount(1, $estimate->items);
|
||||
});
|
||||
|
||||
test('create taxes', function () {
|
||||
$estimate = Estimate::factory()->create();
|
||||
$taxes = [];
|
||||
|
||||
$tax1 = Tax::factory()->raw([
|
||||
'estimate_id' => $estimate->id,
|
||||
]);
|
||||
|
||||
$tax2 = Tax::factory()->raw([
|
||||
'estimate_id' => $estimate->id,
|
||||
]);
|
||||
|
||||
array_push($taxes, $tax1);
|
||||
array_push($taxes, $tax2);
|
||||
|
||||
$request = new Request();
|
||||
|
||||
$request->replace(['taxes' => $taxes ]);
|
||||
|
||||
Estimate::createTaxes($estimate, $request, $estimate->exchange_rate);
|
||||
|
||||
$this->assertCount(2, $estimate->taxes);
|
||||
|
||||
$this->assertDatabaseHas('taxes', [
|
||||
'estimate_id' => $estimate->id,
|
||||
'name' => $tax1['name'],
|
||||
'amount' => $tax1['amount'],
|
||||
]);
|
||||
});
|
||||
26
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,
|
||||
]);
|
||||
});
|
||||
16
tests/Unit/Model/ExpenseCategoryTest.php
Normal file
16
tests/Unit/Model/ExpenseCategoryTest.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\ExpenseCategory;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('expense category has many expenses', function () {
|
||||
$category = ExpenseCategory::factory()->hasExpenses(5)->create();
|
||||
|
||||
$this->assertCount(5, $category->expenses);
|
||||
$this->assertTrue($category->expenses()->exists());
|
||||
});
|
||||
27
tests/Unit/Model/ExpenseTest.php
Normal file
27
tests/Unit/Model/ExpenseTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Expense;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('expense belongs to category', function () {
|
||||
$expense = Expense::factory()->forCategory()->create();
|
||||
|
||||
$this->assertTrue($expense->category()->exists());
|
||||
});
|
||||
|
||||
test('expense belongs to customer', function () {
|
||||
$expense = Expense::factory()->forCustomer()->create();
|
||||
|
||||
$this->assertTrue($expense->customer()->exists());
|
||||
});
|
||||
|
||||
test('expense belongs to company', function () {
|
||||
$expense = Expense::factory()->forCompany()->create();
|
||||
|
||||
$this->assertTrue($expense->company()->exists());
|
||||
});
|
||||
37
tests/Unit/Model/InvoiceItemTest.php
Normal file
37
tests/Unit/Model/InvoiceItemTest.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\InvoiceItem;
|
||||
use Crater\Models\Item;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('invoice item belongs to invoice', function () {
|
||||
$invoiceItem = InvoiceItem::factory()->forInvoice()->create();
|
||||
|
||||
$this->assertTrue($invoiceItem->invoice()->exists());
|
||||
});
|
||||
|
||||
test('invoice item belongs to item', function () {
|
||||
$invoiceItem = InvoiceItem::factory()->create([
|
||||
'item_id' => Item::factory(),
|
||||
'invoice_id' => Invoice::factory(),
|
||||
]);
|
||||
|
||||
$this->assertTrue($invoiceItem->item()->exists());
|
||||
});
|
||||
|
||||
|
||||
test('invoice item has many taxes', function () {
|
||||
$invoiceItem = InvoiceItem::factory()->hasTaxes(5)->create([
|
||||
'invoice_id' => Invoice::factory(),
|
||||
]);
|
||||
|
||||
$this->assertCount(5, $invoiceItem->taxes);
|
||||
|
||||
$this->assertTrue($invoiceItem->taxes()->exists());
|
||||
});
|
||||
198
tests/Unit/Model/InvoiceTest.php
Normal file
198
tests/Unit/Model/InvoiceTest.php
Normal file
@@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
use Crater\Http\Requests\InvoicesRequest;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\InvoiceItem;
|
||||
use Crater\Models\Tax;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'UnitSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'PaymentMethodSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('invoice has many invoice items', function () {
|
||||
$invoice = Invoice::factory()->hasItems(5)->create();
|
||||
|
||||
$this->assertCount(5, $invoice->items);
|
||||
|
||||
$this->assertTrue($invoice->items()->exists());
|
||||
});
|
||||
|
||||
test('invoice has many taxes', function () {
|
||||
$invoice = Invoice::factory()->hasTaxes(5)->create();
|
||||
|
||||
$this->assertCount(5, $invoice->taxes);
|
||||
|
||||
$this->assertTrue($invoice->taxes()->exists());
|
||||
});
|
||||
|
||||
test('invoice has many payments', function () {
|
||||
$invoice = Invoice::factory()->hasPayments(5)->create();
|
||||
|
||||
$this->assertCount(5, $invoice->payments);
|
||||
|
||||
$this->assertTrue($invoice->payments()->exists());
|
||||
});
|
||||
|
||||
test('invoice belongs to customer', function () {
|
||||
$invoice = Invoice::factory()->forCustomer()->create();
|
||||
|
||||
$this->assertTrue($invoice->customer()->exists());
|
||||
});
|
||||
|
||||
test('get previous status', function () {
|
||||
$invoice = Invoice::factory()->create();
|
||||
|
||||
$status = $invoice->getPreviousStatus();
|
||||
|
||||
$this->assertEquals('OVERDUE', $status);
|
||||
});
|
||||
|
||||
|
||||
test('create invoice', function () {
|
||||
$invoice = Invoice::factory()->raw();
|
||||
|
||||
$item = InvoiceItem::factory()->raw();
|
||||
|
||||
$invoice['items'] = [];
|
||||
array_push($invoice['items'], $item);
|
||||
|
||||
$invoice['taxes'] = [];
|
||||
array_push($invoice['taxes'], Tax::factory()->raw());
|
||||
|
||||
$request = new InvoicesRequest();
|
||||
|
||||
$request->replace($invoice);
|
||||
|
||||
$invoice_number = explode("-", $invoice['invoice_number']);
|
||||
$number_attributes['invoice_number'] = $invoice_number[0].'-'.sprintf('%06d', intval($invoice_number[1]));
|
||||
|
||||
$response = Invoice::createInvoice($request);
|
||||
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'invoice_id' => $response->id,
|
||||
'name' => $item['name'],
|
||||
'description' => $item['description'],
|
||||
'total' => $item['total'],
|
||||
'quantity' => $item['quantity'],
|
||||
'discount' => $item['discount'],
|
||||
'price' => $item['price'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'invoice_number' => $invoice['invoice_number'],
|
||||
'sub_total' => $invoice['sub_total'],
|
||||
'total' => $invoice['total'],
|
||||
'tax' => $invoice['tax'],
|
||||
'discount' => $invoice['discount'],
|
||||
'notes' => $invoice['notes'],
|
||||
'customer_id' => $invoice['customer_id'],
|
||||
'template_name' => $invoice['template_name'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('update invoice', function () {
|
||||
$invoice = Invoice::factory()->create();
|
||||
|
||||
$newInvoice = Invoice::factory()->raw();
|
||||
|
||||
$item = InvoiceItem::factory()->raw([
|
||||
'invoice_id' => $invoice->id,
|
||||
]);
|
||||
|
||||
$tax = Tax::factory()->raw([
|
||||
'invoice_id' => $invoice->id,
|
||||
]);
|
||||
|
||||
$newInvoice['items'] = [];
|
||||
$newInvoice['taxes'] = [];
|
||||
|
||||
array_push($newInvoice['items'], $item);
|
||||
array_push($newInvoice['taxes'], $tax);
|
||||
|
||||
$request = new Request();
|
||||
|
||||
$request->replace($newInvoice);
|
||||
|
||||
$invoice_number = explode("-", $newInvoice['invoice_number']);
|
||||
|
||||
$number_attributes['invoice_number'] = $invoice_number[0].'-'.sprintf('%06d', intval($invoice_number[1]));
|
||||
|
||||
$response = $invoice->updateInvoice($request);
|
||||
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'invoice_id' => $response->id,
|
||||
'name' => $item['name'],
|
||||
'description' => $item['description'],
|
||||
'total' => $item['total'],
|
||||
'quantity' => $item['quantity'],
|
||||
'discount' => $item['discount'],
|
||||
'price' => $item['price'],
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('invoices', [
|
||||
'invoice_number' => $newInvoice['invoice_number'],
|
||||
'sub_total' => $newInvoice['sub_total'],
|
||||
'total' => $newInvoice['total'],
|
||||
'tax' => $newInvoice['tax'],
|
||||
'discount' => $newInvoice['discount'],
|
||||
'notes' => $newInvoice['notes'],
|
||||
'customer_id' => $newInvoice['customer_id'],
|
||||
'template_name' => $newInvoice['template_name'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('create items', function () {
|
||||
$invoice = Invoice::factory()->create();
|
||||
|
||||
$items = [];
|
||||
|
||||
$item = InvoiceItem::factory()->raw([
|
||||
'invoice_id' => $invoice->id,
|
||||
]);
|
||||
|
||||
array_push($items, $item);
|
||||
|
||||
$request = new InvoicesRequest();
|
||||
|
||||
$request->replace(['items' => $items ]);
|
||||
|
||||
Invoice::createItems($invoice, $request, $invoice->exchange_rate);
|
||||
|
||||
$this->assertDatabaseHas('invoice_items', [
|
||||
'invoice_id' => $invoice->id,
|
||||
'description' => $item['description'],
|
||||
'price' => $item['price'],
|
||||
'tax' => $item['tax'],
|
||||
'quantity' => $item['quantity'],
|
||||
'total' => $item['total'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('create taxes', function () {
|
||||
$invoice = Invoice::factory()->create();
|
||||
|
||||
$taxes = [];
|
||||
|
||||
$tax = Tax::factory()->raw([
|
||||
'invoice_id' => $invoice->id,
|
||||
]);
|
||||
|
||||
array_push($taxes, $tax);
|
||||
|
||||
$request = new Request();
|
||||
|
||||
$request->replace(['taxes' => $taxes ]);
|
||||
|
||||
Invoice::createTaxes($invoice, $request, $invoice->exchange_rate);
|
||||
|
||||
$this->assertDatabaseHas('taxes', [
|
||||
'invoice_id' => $invoice->id,
|
||||
'name' => $tax['name'],
|
||||
'amount' => $tax['amount'],
|
||||
]);
|
||||
});
|
||||
50
tests/Unit/Model/ItemTest.php
Normal file
50
tests/Unit/Model/ItemTest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Models\EstimateItem;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\InvoiceItem;
|
||||
use Crater\Models\Item;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'UnitSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('an item belongs to unit', function () {
|
||||
$item = Item::factory()->forUnit()->create();
|
||||
|
||||
$this->assertTrue($item->unit()->exists());
|
||||
});
|
||||
|
||||
test('an item has many taxes', function () {
|
||||
$item = Item::factory()->hasTaxes(5)->create();
|
||||
|
||||
$this->assertCount(5, $item->taxes);
|
||||
$this->assertTrue($item->taxes()->exists());
|
||||
});
|
||||
|
||||
test('an item has many invoice items', function () {
|
||||
$item = Item::factory()->has(InvoiceItem::factory()->count(5)->state([
|
||||
'invoice_id' => Invoice::factory(),
|
||||
]))->create();
|
||||
|
||||
$this->assertCount(5, $item->invoiceItems);
|
||||
|
||||
$this->assertTrue($item->invoiceItems()->exists());
|
||||
});
|
||||
|
||||
test('an item has many estimate items', function () {
|
||||
$item = Item::factory()->has(EstimateItem::factory()
|
||||
->count(5)
|
||||
->state([
|
||||
'estimate_id' => Estimate::factory(),
|
||||
]))
|
||||
->create();
|
||||
|
||||
$this->assertCount(5, $item->estimateItems);
|
||||
|
||||
$this->assertTrue($item->estimateItems()->exists());
|
||||
});
|
||||
25
tests/Unit/Model/PaymentMethodTest.php
Normal file
25
tests/Unit/Model/PaymentMethodTest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\PaymentMethod;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'UnitSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'PaymentMethodSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('payment method has many payment', function () {
|
||||
$method = PaymentMethod::factory()->hasPayments(5)->create();
|
||||
|
||||
$this->assertCount(5, $method->payments);
|
||||
|
||||
$this->assertTrue($method->payments()->exists());
|
||||
});
|
||||
|
||||
test('payment method belongs to company', function () {
|
||||
$method = PaymentMethod::factory()->create();
|
||||
|
||||
$this->assertTrue($method->company()->exists());
|
||||
});
|
||||
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());
|
||||
});
|
||||
22
tests/Unit/Model/SettingTest.php
Normal file
22
tests/Unit/Model/SettingTest.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Setting;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use function Pest\Faker\faker;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('set setting', function () {
|
||||
$key = faker()->name;
|
||||
|
||||
$value = faker()->word;
|
||||
|
||||
Setting::setSetting($key, $value);
|
||||
|
||||
$response = Setting::getSetting($key);
|
||||
|
||||
$this->assertEquals($value, $response);
|
||||
});
|
||||
59
tests/Unit/Model/TaxTest.php
Normal file
59
tests/Unit/Model/TaxTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Estimate;
|
||||
use Crater\Models\EstimateItem;
|
||||
use Crater\Models\Invoice;
|
||||
use Crater\Models\InvoiceItem;
|
||||
use Crater\Models\Tax;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('tax belongs to tax type', function () {
|
||||
$tax = Tax::factory()->create();
|
||||
|
||||
$this->assertTrue($tax->taxType->exists());
|
||||
});
|
||||
|
||||
test('tax belongs to invoice', function () {
|
||||
$tax = Tax::factory()->forInvoice()->create();
|
||||
|
||||
$this->assertTrue($tax->invoice()->exists());
|
||||
});
|
||||
|
||||
test('tax belongs to recurring invoice', function () {
|
||||
$tax = Tax::factory()->forRecurringInvoice()->create();
|
||||
|
||||
$this->assertTrue($tax->recurringInvoice()->exists());
|
||||
});
|
||||
|
||||
test('tax belongs to estimate', function () {
|
||||
$tax = Tax::factory()->forEstimate()->create();
|
||||
|
||||
$this->assertTrue($tax->estimate()->exists());
|
||||
});
|
||||
|
||||
test('tax belongs to invoice item', function () {
|
||||
$tax = Tax::factory()->for(InvoiceItem::factory()->state([
|
||||
'invoice_id' => Invoice::factory(),
|
||||
]))->create();
|
||||
|
||||
$this->assertTrue($tax->invoiceItem()->exists());
|
||||
});
|
||||
|
||||
test('tax belongs to estimate item', function () {
|
||||
$tax = Tax::factory()->for(EstimateItem::factory()->state([
|
||||
'estimate_id' => Estimate::factory(),
|
||||
]))->create();
|
||||
|
||||
$this->assertTrue($tax->estimateItem()->exists());
|
||||
});
|
||||
|
||||
test('tax belongs to item', function () {
|
||||
$tax = Tax::factory()->forItem()->create();
|
||||
|
||||
$this->assertTrue($tax->item()->exists());
|
||||
});
|
||||
16
tests/Unit/Model/TaxTypeTest.php
Normal file
16
tests/Unit/Model/TaxTypeTest.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\TaxType;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('tax type has many taxes', function () {
|
||||
$taxtype = TaxType::factory()->hasTaxes(4)->create();
|
||||
|
||||
$this->assertCount(4, $taxtype->taxes);
|
||||
$this->assertTrue($taxtype->taxes()->exists());
|
||||
});
|
||||
33
tests/Unit/Model/UnitTest.php
Normal file
33
tests/Unit/Model/UnitTest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Unit;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'UnitSeeder', '--force' => true]);
|
||||
|
||||
$user = User::where('role', 'super admin')->first();
|
||||
$this->withHeaders([
|
||||
'company' => $user->companies()->first()->id,
|
||||
]);
|
||||
Sanctum::actingAs(
|
||||
$user,
|
||||
['*']
|
||||
);
|
||||
});
|
||||
|
||||
test('unit has many items', function () {
|
||||
$unit = Unit::factory()->hasItems(5)->create();
|
||||
|
||||
$this->assertTrue($unit->items()->exists());
|
||||
});
|
||||
|
||||
test('unit belongs to company', function () {
|
||||
$unit = Unit::factory()->create();
|
||||
|
||||
$this->assertTrue($unit->company()->exists());
|
||||
});
|
||||
88
tests/Unit/Model/UserTest.php
Normal file
88
tests/Unit/Model/UserTest.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\Address;
|
||||
use Crater\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
beforeEach(function () {
|
||||
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
|
||||
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
|
||||
});
|
||||
|
||||
test('user belongs to currency', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->assertTrue($user->currency()->exists());
|
||||
});
|
||||
|
||||
test('user has many addresses', function () {
|
||||
$user = User::factory()->hasAddresses(2)->create();
|
||||
|
||||
$this->assertTrue($user->addresses()->exists());
|
||||
});
|
||||
|
||||
test('user belongs to many companies', function () {
|
||||
$user = User::factory()->hasCompanies(5)->create();
|
||||
|
||||
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $user->companies);
|
||||
});
|
||||
|
||||
it('user has one billing address', function () {
|
||||
$user = User::factory()->has(Address::factory()->state([
|
||||
'type' => Address::BILLING_TYPE,
|
||||
]))->create();
|
||||
|
||||
$this->assertTrue($user->billingAddress()->exists());
|
||||
});
|
||||
|
||||
it('user has one shipping address', function () {
|
||||
$user = User::factory()->has(Address::factory()->state([
|
||||
'type' => Address::SHIPPING_TYPE,
|
||||
]))->create();
|
||||
|
||||
$this->assertTrue($user->shippingAddress()->exists());
|
||||
});
|
||||
|
||||
test('create customer', function () {
|
||||
$customer = User::factory()->raw([
|
||||
'role' => 'customer',
|
||||
]);
|
||||
|
||||
$request = new Request();
|
||||
|
||||
$request->replace($customer);
|
||||
|
||||
$response = User::createCustomer($request);
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'name' => $customer['name'],
|
||||
'email' => $customer['email'],
|
||||
'role' => $customer['role'],
|
||||
]);
|
||||
});
|
||||
|
||||
test('update customer', function () {
|
||||
$customer = User::factory()->create([
|
||||
'role' => 'customer',
|
||||
]);
|
||||
|
||||
$customer2 = User::factory()->raw([
|
||||
'role' => 'customer',
|
||||
]);
|
||||
|
||||
$request = new Request();
|
||||
|
||||
$request->replace($customer2);
|
||||
|
||||
$updateCustomer = User::updateCustomer($request, $customer);
|
||||
|
||||
$newCustomer = User::find($customer->id);
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $customer->id,
|
||||
'name' => $customer2['name'],
|
||||
'email' => $customer2['email'],
|
||||
'role' => $customer2['role'],
|
||||
]);
|
||||
});
|
||||
Reference in New Issue
Block a user