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

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

View File

@ -4,7 +4,6 @@ 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;
@ -203,25 +202,22 @@ test('create payment with invoice', function () {
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,
'total' => 100,
'due_amount' => 100,
'exchange_rate' => 1,
'base_discount_val' => 100,
'base_sub_total' => 100,
'base_total' => 100,
'base_tax' => 100,
'base_due_amount' => 100,
]);
$payment = Payment::factory()->raw([
'invoice_id' => $invoice->id,
'customer_id' => $invoice->customer_id,
'exchange_rate' => $invoice->exchange_rate,
'amount' => 90,
'amount' => 100,
'currency_id' => $invoice->currency_id
]);
@ -229,9 +225,8 @@ test('create payment with partially paid', function () {
$this->assertDatabaseHas('payments', [
'payment_number' => $payment['payment_number'],
'customer_id' => $payment['customer_id'],
'amount' => $payment['amount'],
'base_amount' => $payment['base_amount'],
'customer_id' => (string)$payment['customer_id'],
'amount' => (string)$payment['amount'],
]);
$this->assertDatabaseHas('invoices', [

View File

@ -32,9 +32,12 @@ test('get customer estimates', function () {
test('get customer estimate', function () {
$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 () {
@ -43,15 +46,34 @@ test('customer estimate mark as accepted', function () {
$estimate = Estimate::factory()->create([
'estimate_date' => '1988-07-18',
'expiry_date' => '1988-08-18',
'customer_id' => $customer->id
]);
$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($estimate2->status, Estimate::STATUS_ACCEPTED);
$this->assertEquals($response->json()['data']['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\Auth;
use Laravel\Sanctum\Sanctum;
use function Pest\Laravel\getJson;
beforeEach(function () {
@ -32,14 +31,11 @@ test('get customer expenses', function () {
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'],
$expense = Expense::factory()->create([
'customer_id' => $customer->id,
'company_id' => $customer->company->id
]);
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 () {
$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();

View File

@ -31,7 +31,9 @@ test('get customer payments', function () {
test('get customer payment', function () {
$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();
});

View File

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

View File

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

View File

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

View File

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