v6 update

This commit is contained in:
Mohit Panjwani
2022-01-10 16:06:17 +05:30
parent b770e6277f
commit bdea879273
722 changed files with 19047 additions and 9186 deletions

View File

@ -266,3 +266,181 @@ test('delete multiple estimates', function () {
test('get estimate templates', function () {
getJson('api/v1/estimates/templates')->assertStatus(200);
});
test('create estimate with tax per item', function () {
$estimate = Estimate::factory()->raw([
'estimate_number' => 'EST-000006',
'tax_per_item' => 'YES',
'items' => [
EstimateItem::factory()->raw([
'taxes' => [Tax::factory()->raw()],
]),
EstimateItem::factory()->raw([
'taxes' => [Tax::factory()->raw()],
]),
],
]);
postJson('api/v1/estimates', $estimate)
->assertStatus(201);
$this->assertDatabaseHas('estimates', [
'template_name' => $estimate['template_name'],
'estimate_number' => $estimate['estimate_number'],
'discount_type' => $estimate['discount_type'],
'discount_val' => $estimate['discount_val'],
'sub_total' => $estimate['sub_total'],
'discount' => $estimate['discount'],
'customer_id' => $estimate['customer_id'],
'total' => $estimate['total'],
'notes' => $estimate['notes'],
'tax' => $estimate['tax'],
]);
$this->assertDatabaseHas('estimate_items', [
'name' => $estimate['items'][0]['name'],
]);
$this->assertDatabaseHas('taxes', [
'tax_type_id' => $estimate['items'][0]['taxes'][0]['tax_type_id']
]);
});
test('create estimate with EUR currency', function () {
$estimate = Estimate::factory()
->raw([
'discount_type' => 'fixed',
'discount_val' => 20,
'sub_total' => 200,
'total' => 189,
'tax' => 9,
'exchange_rate' => 86.403538,
'base_discount_val' => 1728.07,
'base_sub_total' => 17280.71,
'base_total' => 16330.27,
'base_tax' => 777.63,
'taxes' => [Tax::factory()->raw([
'amount' => 9,
'percent' => 5,
'exchange_rate' => 86.403538,
'base_amount' => 777.63,
])],
'items' => [EstimateItem::factory()->raw([
'discount_type' => 'fixed',
'quantity' => 1,
'discount' => 0,
'discount_val' => 0,
'price' => 200,
'tax' => 0,
'total' => 200,
'exchange_rate' => 86.403538,
'base_discount_val' => 0,
'base_price' => 17280.71,
'base_tax' => 777.63,
'base_total' => 17280.71,
])],
]);
$response = postJson('api/v1/estimates', $estimate)->assertStatus(201);
$this->assertDatabaseHas('estimates', [
'template_name' => $estimate['template_name'],
'estimate_number' => $estimate['estimate_number'],
'discount_type' => $estimate['discount_type'],
'discount_val' => $estimate['discount_val'],
'sub_total' => $estimate['sub_total'],
'discount' => $estimate['discount'],
'customer_id' => $estimate['customer_id'],
'total' => $estimate['total'],
'notes' => $estimate['notes'],
'tax' => $estimate['tax'],
]);
$this->assertDatabaseHas('taxes', [
'tax_type_id' => $estimate['taxes'][0]['tax_type_id'],
'amount' => $estimate['tax']
]);
$this->assertDatabaseHas('estimate_items', [
'item_id' => $estimate['items'][0]['item_id'],
'name' => $estimate['items'][0]['name']
]);
});
test('update estimate with EUR currency', function () {
$estimate = Estimate::factory()
->hasItems(1)
->hasTaxes(1)
->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$estimate2 = Estimate::factory()
->raw([
'id' => $estimate->id,
'discount_type' => 'fixed',
'discount_val' => 20,
'sub_total' => 200,
'total' => 189,
'tax' => 9,
'exchange_rate' => 86.403538,
'base_discount_val' => 1728.07076,
'base_sub_total' => 17280.7076,
'base_total' => 16330.268682,
'base_tax' => 777.631842,
'taxes' => [Tax::factory()->raw([
'tax_type_id' => $estimate->taxes[0]->tax_type_id,
'amount' => 9,
'percent' => 5,
'exchange_rate' => 86.403538,
'base_amount' => 777.631842,
])],
'items' => [EstimateItem::factory()->raw([
'estimate_id' => $estimate->id,
'discount_type' => 'fixed',
'quantity' => 1,
'discount' => 0,
'discount_val' => 0,
'price' => 200,
'tax' => 0,
'total' => 200,
'exchange_rate' => 86.403538,
'base_discount_val' => 0,
'base_price' => 17280.7076,
'base_tax' => 777.631842,
'base_total' => 17280.7076,
])],
]);
$response = putJson('api/v1/estimates/'.$estimate->id, $estimate2);
$this->assertDatabaseHas('estimates', [
'id' => $estimate['id'],
'template_name' => $estimate2['template_name'],
'estimate_number' => $estimate2['estimate_number'],
'discount_type' => $estimate2['discount_type'],
'discount_val' => $estimate2['discount_val'],
'sub_total' => $estimate2['sub_total'],
'discount' => $estimate2['discount'],
'customer_id' => $estimate2['customer_id'],
'total' => $estimate2['total'],
'tax' => $estimate2['tax'],
'exchange_rate' => $estimate2['exchange_rate'],
'base_discount_val' => $estimate2['base_discount_val'],
'base_sub_total' => $estimate2['base_sub_total'],
'base_total' => $estimate2['base_total'],
'base_tax' => $estimate2['base_tax'],
]);
$this->assertDatabaseHas('estimate_items', [
'estimate_id' => $estimate2['items'][0]['estimate_id'],
'exchange_rate' => $estimate2['items'][0]['exchange_rate'],
'base_price' => $estimate2['items'][0]['base_price'],
'base_discount_val' => $estimate2['items'][0]['base_discount_val'],
'base_tax' => $estimate2['items'][0]['base_tax'],
'base_total' => $estimate2['items'][0]['base_total'],
]);
$response->assertStatus(200);
});

View File

@ -29,7 +29,11 @@ test('get expenses', function () {
});
test('create expense', function () {
$expense = Expense::factory()->raw();
$expense = Expense::factory()->raw([
'amount' => 150,
'exchange_rate' => 76.217498,
'base_amount' => 11432.6247,
]);
postJson('api/v1/expenses', $expense)->assertStatus(201);
@ -37,6 +41,8 @@ test('create expense', function () {
'notes' => $expense['notes'],
'expense_category_id' => $expense['expense_category_id'],
'amount' => $expense['amount'],
'exchange_rate' => $expense['exchange_rate'],
'base_amount' => $expense['base_amount'],
]);
});
@ -126,3 +132,25 @@ test('delete multiple expenses', function () {
$this->assertDeleted($expense);
}
});
test('update expense with EUR currency', function () {
$expense = Expense::factory()->create([
'expense_date' => '2019-02-05',
]);
$expense2 = Expense::factory()->raw([
'amount' => 150,
'exchange_rate' => 76.217498,
'base_amount' => 11432.6247,
]);
putJson('api/v1/expenses/'.$expense->id, $expense2)->assertOk();
$this->assertDatabaseHas('expenses', [
'id' => $expense->id,
'expense_category_id' => $expense2['expense_category_id'],
'amount' => $expense2['amount'],
'exchange_rate' => $expense2['exchange_rate'],
'base_amount' => $expense2['base_amount'],
]);
});

View File

@ -3,8 +3,10 @@
use Crater\Http\Controllers\V1\Admin\Invoice\InvoicesController;
use Crater\Http\Requests\InvoicesRequest;
use Crater\Mail\SendInvoiceMail;
use Crater\Models\Company;
use Crater\Models\Invoice;
use Crater\Models\InvoiceItem;
use Crater\Models\Item;
use Crater\Models\Tax;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
@ -286,3 +288,176 @@ test('create invoice with negative tax', function () {
'tax_type_id' => $invoice['taxes'][0]['tax_type_id']
]);
});
test('create invoice with tax per item', function () {
$invoice = Invoice::factory()
->raw([
'tax_per_item' => 'YES',
'items' => [
InvoiceItem::factory()->raw([
'taxes' => [Tax::factory()->raw()],
]),
InvoiceItem::factory()->raw([
'taxes' => [Tax::factory()->raw()],
]),
],
]);
$response = postJson('api/v1/invoices', $invoice);
$response->assertOk();
$this->assertDatabaseHas('invoices', [
'invoice_number' => $invoice['invoice_number'],
'sub_total' => $invoice['sub_total'],
'total' => $invoice['total'],
'tax' => $invoice['tax'],
'discount' => $invoice['discount'],
'customer_id' => $invoice['customer_id'],
]);
$this->assertDatabaseHas('invoice_items', [
'name' => $invoice['items'][0]['name'],
]);
$this->assertDatabaseHas('taxes', [
'tax_type_id' => $invoice['items'][0]['taxes'][0]['tax_type_id']
]);
});
test('create invoice with EUR currency', function () {
$invoice = Invoice::factory()
->raw([
'discount_type' => 'fixed',
'discount_val' => 20,
'sub_total' => 100,
'total' => 84,
'tax' => 4,
'due_amount' => 84,
'exchange_rate' => 86.403538,
'base_discount_val' => 1728.07,
'base_sub_total' => 8640.35,
'base_total' => 7257.90,
'base_tax' => 345.61,
'base_due_amount' => 7257.90,
'taxes' => [Tax::factory()->raw([
'amount' => 4,
'percent' => 5,
'base_amount' => 345.61,
])],
'items' => [InvoiceItem::factory()->raw([
'discount_type' => 'fixed',
'price' => 100,
'quantity' => 1,
'discount' => 0,
'discount_val' => 0,
'tax' => 0,
'total' => 100,
'base_price' => 8640.35,
'exchange_rate' => 86.403538,
'base_discount_val' => 0,
'base_tax' => 0,
'base_total' => 8640.35,
])],
]);
$response = postJson('api/v1/invoices', $invoice)->assertOk();
$this->assertDatabaseHas('invoices', [
'template_name' => $invoice['template_name'],
'invoice_number' => $invoice['invoice_number'],
'sub_total' => $invoice['sub_total'],
'discount' => $invoice['discount'],
'customer_id' => $invoice['customer_id'],
'total' => $invoice['total'],
'tax' => $invoice['tax'],
]);
$this->assertDatabaseHas('taxes', [
'tax_type_id' => $invoice['taxes'][0]['tax_type_id'],
'amount' => $invoice['tax']
]);
$this->assertDatabaseHas('invoice_items', [
'item_id' => $invoice['items'][0]['item_id'],
'name' => $invoice['items'][0]['name']
]);
});
test('update invoice with EUR currency', function () {
$invoice = Invoice::factory()
->hasItems(1)
->hasTaxes(1)
->create([
'invoice_date' => '1988-07-18',
'due_date' => '1988-08-18',
]);
$invoice2 = Invoice::factory()
->raw([
'id' => $invoice['id'],
'discount_type' => 'fixed',
'discount_val' => 20,
'sub_total' => 100,
'total' => 84,
'tax' => 4,
'due_amount' => 84,
'exchange_rate' => 86.403538,
'base_discount_val' => 1728.07,
'base_sub_total' => 8640.35,
'base_total' => 7257.897192,
'base_tax' => 345.614152,
'base_due_amount' => 7257.897192,
'taxes' => [Tax::factory()->raw([
'tax_type_id' => $invoice->taxes[0]->tax_type_id,
'amount' => 4,
'percent' => 5,
'base_amount' => 345.614152,
])],
'items' => [InvoiceItem::factory()->raw([
'invoice_id' => $invoice->id,
'discount_type' => 'fixed',
'price' => 100,
'quantity' => 1,
'discount' => 0,
'discount_val' => 0,
'tax' => 0,
'total' => 100,
'base_price' => 8640.3538,
'exchange_rate' => 86.403538,
'base_discount_val' => 0,
'base_tax' => 0,
'base_total' => 8640.3538,
])],
]);
putJson('api/v1/invoices/'.$invoice->id, $invoice2)->assertOk();
$this->assertDatabaseHas('invoices', [
'id' => $invoice['id'],
'invoice_number' => $invoice2['invoice_number'],
'sub_total' => $invoice2['sub_total'],
'total' => $invoice2['total'],
'tax' => $invoice2['tax'],
'discount' => $invoice2['discount'],
'customer_id' => $invoice2['customer_id'],
'template_name' => $invoice2['template_name'],
'exchange_rate' => $invoice2['exchange_rate'],
'base_total' => $invoice2['base_total'],
]);
$this->assertDatabaseHas('invoice_items', [
'invoice_id' => $invoice2['items'][0]['invoice_id'],
'item_id' => $invoice2['items'][0]['item_id'],
'name' => $invoice2['items'][0]['name'],
'exchange_rate' => $invoice2['items'][0]['exchange_rate'],
'base_price' => $invoice2['items'][0]['base_price'],
'base_total' => $invoice2['items'][0]['base_total'],
]);
$this->assertDatabaseHas('taxes', [
'amount' => $invoice2['taxes'][0]['amount'],
'name' => $invoice2['taxes'][0]['name'],
'base_amount' => $invoice2['taxes'][0]['base_amount'],
]);
});

View File

@ -4,6 +4,7 @@ use Crater\Http\Controllers\V1\Admin\Payment\PaymentsController;
use Crater\Http\Requests\PaymentRequest;
use Crater\Mail\SendPaymentMail;
use Crater\Models\Invoice;
use Crater\Models\InvoiceItem;
use Crater\Models\Payment;
use Crater\Models\User;
use Illuminate\Support\Facades\Artisan;
@ -159,3 +160,87 @@ test('delete payment', function () {
'success' => true,
]);
});
test('create payment without invoice', function () {
$payment = Payment::factory()->raw([
'payment_number' => "PAY-000001",
'exchange_rate' => 1
]);
postJson('api/v1/payments', $payment)->assertOk();
$this->assertDatabaseHas('payments', [
'payment_number' => $payment['payment_number'],
'customer_id' => $payment['customer_id'],
'amount' => $payment['amount'],
'company_id' => $payment['company_id'],
]);
});
test('create payment with invoice', function () {
$payment = Payment::factory()->raw([
'payment_number' => "PAY-000001",
]);
$invoice = Invoice::factory()->create();
$payment = Payment::factory()->raw([
'invoice_id' => $invoice->id,
'amount' => $invoice->due_amount,
'exchange_rate' => 1
]);
postJson('api/v1/payments', $payment)->assertOk();
$this->assertDatabaseHas('payments', [
'payment_number' => $payment['payment_number'],
'customer_id' => $payment['customer_id'],
'invoice_id' => $payment['invoice_id'],
'amount' => $payment['amount'],
'company_id' => $payment['company_id'],
]);
});
test('create payment with partially paid', function () {
$invoice = Invoice::factory()->create([
'discount_type' => 'fixed',
'discount_val' => 10,
'sub_total' => 100,
'total' => 95,
'tax' => 5,
'due_amount' => 95,
'exchange_rate' => 86.059663,
'base_discount_val' => 860.59663,
'base_sub_total' => 8605.9663,
'base_total' => 8,175.667985,
'base_tax' => 430.298315,
'base_due_amount' => 8,175.667985,
]);
$payment = Payment::factory()->raw([
'invoice_id' => $invoice->id,
'customer_id' => $invoice->customer_id,
'exchange_rate' => $invoice->exchange_rate,
'amount' => 90,
'currency_id' => $invoice->currency_id
]);
$response = postJson("api/v1/payments", $payment)->assertOk();
$this->assertDatabaseHas('payments', [
'payment_number' => $payment['payment_number'],
'customer_id' => $payment['customer_id'],
'amount' => $payment['amount'],
'base_amount' => $payment['base_amount'],
]);
$this->assertDatabaseHas('invoices', [
'id' => $invoice['id'],
'invoice_number' => $response['data']['invoice']['invoice_number'],
'total' => $response['data']['invoice']['total'],
'customer_id' => $response['data']['invoice']['customer_id'],
'exchange_rate' => $response['data']['invoice']['exchange_rate'],
'base_total' => $response['data']['invoice']['base_total'],
'paid_status' => $response['data']['invoice']['paid_status'],
]);
});

View File

@ -0,0 +1,28 @@
<?php
namespace Tests\Feature\Customer;
use Crater\Models\Customer;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Auth;
use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\getJson;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$customer = Customer::factory()->create();
Sanctum::actingAs(
$customer,
['*'],
'customer'
);
});
test('customer dashboard', function () {
$customer = Auth::guard('customer')->user();
getJson("api/v1/{$customer->company->slug}/customer/dashboard")->assertOk();
});

View File

@ -0,0 +1,57 @@
<?php
namespace Tests\Feature\Customer;
use Crater\Models\Customer;
use Crater\Models\Estimate;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Auth;
use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\getJson;
use function Pest\Laravel\postJson;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$customer = Customer::factory()->create();
Sanctum::actingAs(
$customer,
['*'],
'customer'
);
});
test('get customer estimates', function () {
$customer = Auth::guard('customer')->user();
getJson("api/v1/{$customer->company->slug}/customer/estimates?page=1")->assertOk();
});
test('get customer estimate', function () {
$customer = Auth::guard('customer')->user();
$estimate = Estimate::factory()->create();
getJson("/api/{$customer->company->slug}/v1/customer/estimates/{$estimate->id}")->assertOk();
});
test('customer estimate mark as accepted', function () {
$customer = Auth::guard('customer')->user();
$estimate = Estimate::factory()->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
]);
$status = [
'status' => Estimate::STATUS_ACCEPTED,
];
postJson("api/v1/{$customer->company->slug}/customer/estimate/{$estimate->id}/accept", $status)->assertOk();
$estimate2 = Estimate::find($estimate->id);
$this->assertEquals($estimate2->status, Estimate::STATUS_ACCEPTED);
});

View File

@ -0,0 +1,45 @@
<?php
namespace Tests\Feature\Customer;
use Crater\Models\Customer;
use Crater\Models\Expense;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Auth;
use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\getJson;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$customer = Customer::factory()->create();
Sanctum::actingAs(
$customer,
['*'],
'customer'
);
});
test('get customer expenses', function () {
$customer = Auth::guard('customer')->user();
getJson("api/v1/{$customer->company->slug}/customer/expenses?page=1")->assertOk();
});
test('get customer expense', function () {
$customer = Auth::guard('customer')->user();
$expense = Expense::factory()->create();
getJson("/api/v1/{$customer->company->slug}/customer/expenses/{$expense->id}")->assertOk();
$this->assertDatabaseHas('expenses', [
'expense_category_id' => $expense['expense_category_id'],
'amount' => $expense['amount'],
'exchange_rate' => $expense['exchange_rate'],
'notes' => $expense['notes'],
]);
});

View File

@ -0,0 +1,47 @@
<?php
namespace Tests\Feature\Customer;
use Crater\Models\Customer;
use Crater\Models\Invoice;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Auth;
use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\getJson;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$customer = Customer::factory()->create();
Sanctum::actingAs(
$customer,
['*'],
'customer'
);
});
test('get customer invoices', function () {
$customer = Auth::guard('customer')->user();
getJson("api/v1/{$customer->company->slug}/customer/invoices?page=1")->assertOk();
});
test('get customer invoice', function () {
$customer = Auth::guard('customer')->user();
$invoice = Invoice::factory()->create();
getJson("/api/v1/{$customer->company->slug}/customer/invoices/{$invoice->id}")->assertOk();
$this->assertDatabaseHas('invoices', [
'template_name' => $invoice['template_name'],
'invoice_number' => $invoice['invoice_number'],
'sub_total' => $invoice['sub_total'],
'discount' => $invoice['discount'],
'customer_id' => $invoice['customer_id'],
'total' => $invoice['total'],
'tax' => $invoice['tax'],
]);
});

View File

@ -0,0 +1,37 @@
<?php
namespace Tests\Feature\Customer;
use Crater\Models\Customer;
use Crater\Models\Payment;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Auth;
use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\getJson;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$customer = Customer::factory()->create();
Sanctum::actingAs(
$customer,
['*'],
'customer'
);
});
test('get customer payments', function () {
$customer = Auth::guard('customer')->user();
getJson("api/v1/{$customer->company->slug}/customer/payments?page=1")->assertOk();
});
test('get customer payment', function () {
$customer = Auth::guard('customer')->user();
$payment = Payment::factory()->create();
getJson("/api/v1/{$customer->company->slug}/customer/payments/{$payment->id}")->assertOk();
});

View File

@ -0,0 +1,61 @@
<?php
namespace Tests\Feature\Customer;
use Crater\Http\Controllers\V1\Customer\General\ProfileController;
use Crater\Http\Requests\Customer\CustomerProfileRequest;
use Crater\Models\Customer;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Auth;
use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\getJson;
use function Pest\Laravel\postJson;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
Artisan::call('db:seed', ['--class' => 'DemoSeeder', '--force' => true]);
$customer = Customer::factory()->create();
Sanctum::actingAs(
$customer,
['*'],
'customer'
);
});
test('update customer profile using a form request', function () {
$this->assertActionUsesFormRequest(
ProfileController::class,
'updateProfile',
CustomerProfileRequest::class
);
});
test('update customer profile', function () {
$customer = Auth::guard('customer')->user();
$newCustomer = Customer::factory()->raw([
'shipping' => [
'name' => 'newName',
'address_street_1' => 'address'
],
'billing' => [
'name' => 'newName',
'address_street_1' => 'address'
]
]);
postJson("api/v1/{$customer->company->slug}/customer/profile", $newCustomer)->assertOk();
$this->assertDatabaseHas('customers', [
'name' => $customer['name'],
'email' => $customer['email']
]);
});
test('get customer', function () {
$customer = Auth::guard('customer')->user();
getJson("api/v1/{$customer->company->slug}/customer/me")->assertOk();
});

View File

@ -14,7 +14,7 @@ test('company has many customers', function () {
$this->assertTrue($company->customers()->exists());
});
test('company has many company setings', function () {
test('company has many company settings', function () {
$company = Company::factory()->hasSettings(5)->create();
$this->assertCount(5, $company->settings);

View File

@ -0,0 +1,30 @@
<?php
use Crater\Http\Requests\BulkExchangeRateRequest;
test('bulk exchange rate request validation rules', function () {
$request = new BulkExchangeRateRequest();
$this->assertEquals(
[
'currencies' => [
'required'
],
'currencies.*.id' => [
'required',
'numeric'
],
'currencies.*.exchange_rate' => [
'required'
],
],
$request->rules()
);
});
test('bulk exchange rate request authorize', function () {
$request = new BulkExchangeRateRequest();
$this->assertTrue($request->authorize());
});

View File

@ -0,0 +1,27 @@
<?php
use Crater\Http\Requests\Customer\CustomerLoginRequest;
test('customer login request validation rules', function () {
$request = new CustomerLoginRequest();
$this->assertEquals(
[
'email' => [
'required',
'string'
],
'password' => [
'required',
'string'
],
],
$request->rules()
);
});
test('customer login request authorize', function () {
$request = new CustomerLoginRequest();
$this->assertTrue($request->authorize());
});

View File

@ -0,0 +1,86 @@
<?php
use Crater\Http\Requests\Customer\CustomerProfileRequest;
use Illuminate\Validation\Rule;
test('customer profile request validation rules', function () {
$request = new CustomerProfileRequest();
$this->assertEquals(
[
'name' => [
'nullable',
],
'password' => [
'nullable',
'min:8',
],
'email' => [
'nullable',
'email',
Rule::unique('customers')->ignore(Auth::id(), 'id'),
],
'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()
);
});
test('customer profile request authorize', function () {
$request = new CustomerProfileRequest();
$this->assertTrue($request->authorize());
});

View File

@ -0,0 +1,26 @@
<?php
use Crater\Http\Requests\ExchangeRateLogRequest;
test('exchange rate log request validation rules', function () {
$request = new ExchangeRateLogRequest();
$this->assertEquals(
[
'exchange_rate' => [
'required',
],
'currency_id' => [
'required'
],
],
$request->rules()
);
});
test('exchange rate log request authorize', function () {
$request = new ExchangeRateLogRequest();
$this->assertTrue($request->authorize());
});

View File

@ -0,0 +1,39 @@
<?php
use Crater\Http\Requests\ExchangeRateProviderRequest;
test('exchange rate provider request validation rules', function () {
$request = new ExchangeRateProviderRequest();
$this->assertEquals(
[
'driver' => [
'required'
],
'key' => [
'required',
],
'currencies' => [
'nullable',
],
'currencies.*' => [
'nullable',
],
'driver_config' => [
'nullable'
],
'active' => [
'nullable',
'boolean'
],
],
$request->rules()
);
});
test('exchange rate provider request authorize', function () {
$request = new ExchangeRateProviderRequest();
$this->assertTrue($request->authorize());
});

View File

@ -31,6 +31,12 @@ test('expense request validation rules', function () {
'currency_id' => [
'required'
],
'attachment_receipt' => [
'nullable',
'file',
'mimes:jpg,png,pdf,doc,docx,xls,xlsx,ppt,pptx',
'max:20000'
]
],
$request->rules()
);

View File

@ -0,0 +1,28 @@
<?php
use Crater\Http\Requests\LoginRequest;
test('login request validation rules', function () {
$request = new LoginRequest();
$this->assertEquals(
[
'username' => [
'required',
],
'password' => [
'required',
],
'device_name' => [
'required'
],
],
$request->rules()
);
});
test('login request authorize', function () {
$request = new LoginRequest();
$this->assertTrue($request->authorize());
});

View File

@ -0,0 +1,33 @@
<?php
use Crater\Http\Requests\NotesRequest;
use Illuminate\Validation\Rule;
test('note request validation rules', function () {
$request = new NotesRequest();
$this->assertEquals(
[
'type' => [
'required'
],
'name' => [
'required',
Rule::unique('notes')
->where('company_id', $request->header('company'))
->where('type', $request->type)
],
'notes' => [
'required'
],
],
$request->rules()
);
});
test('note request authorize', function () {
$request = new NotesRequest();
$this->assertTrue($request->authorize());
});

View File

@ -0,0 +1,33 @@
<?php
use Crater\Http\Requests\ProfileRequest;
use Illuminate\Validation\Rule;
test('profile request validation rules', function () {
$request = new ProfileRequest();
$this->assertEquals(
[
'name' => [
'required',
],
'password' => [
'nullable',
'min:8',
],
'email' => [
'required',
'email',
Rule::unique('users')->ignore(Auth::id(), 'id'),
],
],
$request->rules()
);
});
test('profile request authorize', function () {
$request = new ProfileRequest();
$this->assertTrue($request->authorize());
});

View File

@ -0,0 +1,31 @@
<?php
use Crater\Http\Requests\RoleRequest;
use Illuminate\Validation\Rule;
test('role request validation rules', function () {
$request = new RoleRequest();
$this->assertEquals(
[
'name' => [
'required',
'string',
Rule::unique('roles')->where('scope', $request->header('company'))
],
'abilities' => [
'required'
],
'abilities.*' => [
'required'
],
],
$request->rules()
);
});
test('role request authorize', function () {
$request = new RoleRequest();
$this->assertTrue($request->authorize());
});

View File

@ -0,0 +1,44 @@
<?php
use Crater\Http\Requests\UserRequest;
use Illuminate\Validation\Rule;
test('user request validation rules', function () {
$request = new UserRequest();
$this->assertEquals(
[
'name' => [
'required',
],
'email' => [
'required',
'email',
Rule::unique('users'),
],
'phone' => [
'nullable',
],
'password' => [
'required',
'min:8',
],
'companies' => [
'required',
],
'companies.*.id' => [
'required',
],
'companies.*.role' => [
'required',
],
],
$request->rules()
);
});
test('user request authorize', function () {
$request = new UserRequest();
$this->assertTrue($request->authorize());
});