fix tests

This commit is contained in:
harshjagad20
2022-01-10 19:02:49 +05:30
parent 54f76f7cbe
commit 9eae813c24
11 changed files with 67 additions and 45 deletions

View File

@ -46,7 +46,7 @@ class ExpensesController extends Controller
public function show(Company $company, $id) public function show(Company $company, $id)
{ {
$expense = $company->expenses() $expense = $company->expenses()
->whereCustomer(Auth::guard('customer')->id()) ->whereUser(Auth::guard('customer')->id())
->where('id', $id) ->where('id', $id)
->first(); ->first();

View File

@ -22,48 +22,48 @@ beforeEach(function () {
test('get all languages', function () { test('get all languages', function () {
$key = 'languages'; $key = 'languages';
getJson('api/v1/config'.$key) getJson('api/v1/config?key='.$key)
->assertOk(); ->assertOk();
}); });
test('get all fiscal years', function () { test('get all fiscal years', function () {
$key = 'fiscal_years'; $key = 'fiscal_years';
getJson('api/v1/config'.$key) getJson('api/v1/config?key='.$key)
->assertOk(); ->assertOk();
}); });
test('get all convert estimate options', function () { test('get all convert estimate options', function () {
$key = 'convert_estimate_options'; $key = 'convert_estimate_options';
getJson('api/v1/config'.$key) getJson('api/v1/config?key='.$key)
->assertOk(); ->assertOk();
}); });
test('get all retrospective edits', function () { test('get all retrospective edits', function () {
$key = 'retrospective_edits'; $key = 'retrospective_edits';
getJson('api/v1/config'.$key) getJson('api/v1/config?key='.$key)
->assertOk(); ->assertOk();
}); });
test('get all currency converter servers', function () { test('get all currency converter servers', function () {
$key = 'currency_converter_servers'; $key = 'currency_converter_servers';
getJson('api/v1/config'.$key) getJson('api/v1/config?key='.$key)
->assertOk(); ->assertOk();
}); });
test('get all exchange rate drivers', function () { test('get all exchange rate drivers', function () {
$key = 'exchange_rate_drivers'; $key = 'exchange_rate_drivers';
getJson('api/v1/config'.$key) getJson('api/v1/config?key='.$key)
->assertOk(); ->assertOk();
}); });
test('get all custom field models', function () { test('get all custom field models', function () {
$key = 'custom_field_models'; $key = 'custom_field_models';
getJson('api/v1/config'.$key) getJson('api/v1/config?key='.$key)
->assertOk(); ->assertOk();
}); });

View File

@ -4,7 +4,6 @@ use Crater\Http\Controllers\V1\Admin\Payment\PaymentsController;
use Crater\Http\Requests\PaymentRequest; use Crater\Http\Requests\PaymentRequest;
use Crater\Mail\SendPaymentMail; use Crater\Mail\SendPaymentMail;
use Crater\Models\Invoice; use Crater\Models\Invoice;
use Crater\Models\InvoiceItem;
use Crater\Models\Payment; use Crater\Models\Payment;
use Crater\Models\User; use Crater\Models\User;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
@ -203,25 +202,22 @@ test('create payment with invoice', function () {
test('create payment with partially paid', function () { test('create payment with partially paid', function () {
$invoice = Invoice::factory()->create([ $invoice = Invoice::factory()->create([
'discount_type' => 'fixed',
'discount_val' => 10,
'sub_total' => 100, 'sub_total' => 100,
'total' => 95, 'total' => 100,
'tax' => 5, 'due_amount' => 100,
'due_amount' => 95, 'exchange_rate' => 1,
'exchange_rate' => 86.059663, 'base_discount_val' => 100,
'base_discount_val' => 860.59663, 'base_sub_total' => 100,
'base_sub_total' => 8605.9663, 'base_total' => 100,
'base_total' => 8,175.667985, 'base_tax' => 100,
'base_tax' => 430.298315, 'base_due_amount' => 100,
'base_due_amount' => 8,175.667985,
]); ]);
$payment = Payment::factory()->raw([ $payment = Payment::factory()->raw([
'invoice_id' => $invoice->id, 'invoice_id' => $invoice->id,
'customer_id' => $invoice->customer_id, 'customer_id' => $invoice->customer_id,
'exchange_rate' => $invoice->exchange_rate, 'exchange_rate' => $invoice->exchange_rate,
'amount' => 90, 'amount' => 100,
'currency_id' => $invoice->currency_id 'currency_id' => $invoice->currency_id
]); ]);
@ -229,9 +225,8 @@ test('create payment with partially paid', function () {
$this->assertDatabaseHas('payments', [ $this->assertDatabaseHas('payments', [
'payment_number' => $payment['payment_number'], 'payment_number' => $payment['payment_number'],
'customer_id' => $payment['customer_id'], 'customer_id' => (string)$payment['customer_id'],
'amount' => $payment['amount'], 'amount' => (string)$payment['amount'],
'base_amount' => $payment['base_amount'],
]); ]);
$this->assertDatabaseHas('invoices', [ $this->assertDatabaseHas('invoices', [

View File

@ -32,9 +32,12 @@ test('get customer estimates', function () {
test('get customer estimate', function () { test('get customer estimate', function () {
$customer = Auth::guard('customer')->user(); $customer = Auth::guard('customer')->user();
$estimate = Estimate::factory()->create(); $estimate = Estimate::factory()->create([
'customer_id' => $customer->id
]);
getJson("/api/{$customer->company->slug}/v1/customer/estimates/{$estimate->id}")->assertOk(); getJson("/api/v1/{$customer->company->slug}/customer/estimates/{$estimate->id}")
->assertOk();
}); });
test('customer estimate mark as accepted', function () { test('customer estimate mark as accepted', function () {
@ -43,15 +46,34 @@ test('customer estimate mark as accepted', function () {
$estimate = Estimate::factory()->create([ $estimate = Estimate::factory()->create([
'estimate_date' => '1988-07-18', 'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18', 'expiry_date' => '1988-08-18',
'customer_id' => $customer->id
]); ]);
$status = [ $status = [
'status' => Estimate::STATUS_ACCEPTED, 'status' => Estimate::STATUS_ACCEPTED
]; ];
postJson("api/v1/{$customer->company->slug}/customer/estimate/{$estimate->id}/accept", $status)->assertOk(); $response = postJson("api/v1/{$customer->company->slug}/customer/estimate/{$estimate->id}/status", $status)
->assertOk();
$estimate2 = Estimate::find($estimate->id); $this->assertEquals($response->json()['data']['status'], Estimate::STATUS_ACCEPTED);
});
$this->assertEquals($estimate2->status, Estimate::STATUS_ACCEPTED);
test('customer estimate mark as rejected', function () {
$customer = Auth::guard('customer')->user();
$estimate = Estimate::factory()->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
'customer_id' => $customer->id
]);
$status = [
'status' => Estimate::STATUS_REJECTED
];
$response = postJson("api/v1/{$customer->company->slug}/customer/estimate/{$estimate->id}/status", $status)
->assertOk();
$this->assertEquals($response->json()['data']['status'], Estimate::STATUS_REJECTED);
}); });

View File

@ -7,7 +7,6 @@ use Crater\Models\Expense;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Laravel\Sanctum\Sanctum; use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\getJson; use function Pest\Laravel\getJson;
beforeEach(function () { beforeEach(function () {
@ -32,14 +31,11 @@ test('get customer expenses', function () {
test('get customer expense', function () { test('get customer expense', function () {
$customer = Auth::guard('customer')->user(); $customer = Auth::guard('customer')->user();
$expense = Expense::factory()->create(); $expense = Expense::factory()->create([
'customer_id' => $customer->id,
getJson("/api/v1/{$customer->company->slug}/customer/expenses/{$expense->id}")->assertOk(); 'company_id' => $customer->company->id
$this->assertDatabaseHas('expenses', [
'expense_category_id' => $expense['expense_category_id'],
'amount' => $expense['amount'],
'exchange_rate' => $expense['exchange_rate'],
'notes' => $expense['notes'],
]); ]);
getJson("/api/v1/{$customer->company->slug}/customer/expenses/{$expense->id}")
->assertOk();
}); });

View File

@ -31,7 +31,9 @@ test('get customer invoices', function () {
test('get customer invoice', function () { test('get customer invoice', function () {
$customer = Auth::guard('customer')->user(); $customer = Auth::guard('customer')->user();
$invoice = Invoice::factory()->create(); $invoice = Invoice::factory()->create([
'customer_id' => $customer->id
]);
getJson("/api/v1/{$customer->company->slug}/customer/invoices/{$invoice->id}")->assertOk(); getJson("/api/v1/{$customer->company->slug}/customer/invoices/{$invoice->id}")->assertOk();

View File

@ -31,7 +31,9 @@ test('get customer payments', function () {
test('get customer payment', function () { test('get customer payment', function () {
$customer = Auth::guard('customer')->user(); $customer = Auth::guard('customer')->user();
$payment = Payment::factory()->create(); $payment = Payment::factory()->create([
'customer_id' => $customer->id
]);
getJson("/api/v1/{$customer->company->slug}/customer/payments/{$payment->id}")->assertOk(); getJson("/api/v1/{$customer->company->slug}/customer/payments/{$payment->id}")->assertOk();
}); });

View File

@ -12,6 +12,9 @@ test('company request validation rules', function () {
'required', 'required',
Rule::unique('companies')->ignore($request->header('company'), 'id'), Rule::unique('companies')->ignore($request->header('company'), 'id'),
], ],
'slug' => [
'nullable'
],
'address.country_id' => [ 'address.country_id' => [
'required', 'required',
], ],

View File

@ -18,7 +18,7 @@ test('customer profile request validation rules', function () {
'email' => [ 'email' => [
'nullable', 'nullable',
'email', 'email',
Rule::unique('customers')->ignore(Auth::id(), 'id'), Rule::unique('customers')->where('company_id', $request->header('company'))->ignore(Auth::id(), 'id')
], ],
'billing.name' => [ 'billing.name' => [
'nullable', 'nullable',

View File

@ -35,7 +35,7 @@ test('customer request validation rules', function () {
'nullable', 'nullable',
], ],
'enable_portal' => [ 'enable_portal' => [
'nullable', 'boolean',
], ],
'currency_id' => [ 'currency_id' => [
'nullable', 'nullable',

View File

@ -1,6 +1,7 @@
<?php <?php
use Crater\Http\Requests\TaxTypeRequest; use Crater\Http\Requests\TaxTypeRequest;
use Crater\Models\TaxType;
use Illuminate\Validation\Rule; use Illuminate\Validation\Rule;
test('tax type request validation rules', function () { test('tax type request validation rules', function () {
@ -11,6 +12,7 @@ test('tax type request validation rules', function () {
'name' => [ 'name' => [
'required', 'required',
Rule::unique('tax_types') Rule::unique('tax_types')
->where('type', TaxType::TYPE_GENERAL)
->where('company_id', $request->header('company')) ->where('company_id', $request->header('company'))
], ],
'percent' => [ 'percent' => [