mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
Merge branch 'fix-tests-master' into 'master'
Fix tests master See merge request mohit.panjvani/crater-web!1413
This commit is contained in:
@ -46,7 +46,7 @@ class ExpensesController extends Controller
|
||||
public function show(Company $company, $id)
|
||||
{
|
||||
$expense = $company->expenses()
|
||||
->whereCustomer(Auth::guard('customer')->id())
|
||||
->whereUser(Auth::guard('customer')->id())
|
||||
->where('id', $id)
|
||||
->first();
|
||||
|
||||
|
||||
@ -56,29 +56,37 @@ Route::get('/{company:slug}/customer/logout', function () {
|
||||
Auth::guard('customer')->logout();
|
||||
});
|
||||
|
||||
|
||||
Route::middleware('auth:sanctum')->prefix('reports')->group(function () {
|
||||
|
||||
// sales report by customer
|
||||
//----------------------------------
|
||||
Route::get('/sales/customers/{hash}', CustomerSalesReportController::class);
|
||||
|
||||
// sales report by items
|
||||
//----------------------------------
|
||||
Route::get('/sales/items/{hash}', ItemSalesReportController::class);
|
||||
|
||||
// report for expenses
|
||||
//----------------------------------
|
||||
Route::get('/expenses/{hash}', ExpensesReportController::class);
|
||||
|
||||
// report for tax summary
|
||||
//----------------------------------
|
||||
Route::get('/tax-summary/{hash}', TaxSummaryReportController::class);
|
||||
|
||||
// report for profit and loss
|
||||
//----------------------------------
|
||||
Route::get('/profit-loss/{hash}', ProfitLossReportController::class);
|
||||
|
||||
|
||||
// download expense receipt
|
||||
// -------------------------------------------------
|
||||
Route::get('/expenses/{expense}/download-receipt', DownloadReceiptController::class);
|
||||
Route::get('/expenses/{expense}/receipt', ShowReceiptController::class);
|
||||
});
|
||||
|
||||
Route::middleware('pdf-auth')->group(function () {
|
||||
Route::prefix('reports')->group(function () {
|
||||
|
||||
// sales report by customer
|
||||
//----------------------------------
|
||||
Route::get('/sales/customers/{hash}', CustomerSalesReportController::class);
|
||||
|
||||
// sales report by items
|
||||
//----------------------------------
|
||||
Route::get('/sales/items/{hash}', ItemSalesReportController::class);
|
||||
|
||||
// report for expenses
|
||||
//----------------------------------
|
||||
Route::get('/expenses/{hash}', ExpensesReportController::class);
|
||||
|
||||
// report for tax summary
|
||||
//----------------------------------
|
||||
Route::get('/tax-summary/{hash}', TaxSummaryReportController::class);
|
||||
|
||||
// report for profit and loss
|
||||
//----------------------------------
|
||||
Route::get('/profit-loss/{hash}', ProfitLossReportController::class);
|
||||
});
|
||||
|
||||
// invoice pdf
|
||||
// -------------------------------------------------
|
||||
@ -91,14 +99,10 @@ Route::middleware('pdf-auth')->group(function () {
|
||||
// payment pdf
|
||||
// -------------------------------------------------
|
||||
Route::get('/payments/pdf/{payment:unique_hash}', PaymentPdfController::class);
|
||||
|
||||
// download expense receipt
|
||||
// -------------------------------------------------
|
||||
Route::get('/expenses/{expense}/download-receipt', DownloadReceiptController::class);
|
||||
Route::get('/expenses/{expense}/receipt', ShowReceiptController::class);
|
||||
});
|
||||
|
||||
|
||||
|
||||
// customer pdf endpoints for invoice, estimate and Payment
|
||||
// -------------------------------------------------
|
||||
|
||||
|
||||
@ -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();
|
||||
});
|
||||
|
||||
@ -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', [
|
||||
|
||||
@ -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);
|
||||
});
|
||||
|
||||
@ -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();
|
||||
});
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -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();
|
||||
});
|
||||
|
||||
@ -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',
|
||||
],
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -35,7 +35,7 @@ test('customer request validation rules', function () {
|
||||
'nullable',
|
||||
],
|
||||
'enable_portal' => [
|
||||
'nullable',
|
||||
'boolean',
|
||||
],
|
||||
'currency_id' => [
|
||||
'nullable',
|
||||
|
||||
@ -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' => [
|
||||
|
||||
Reference in New Issue
Block a user