Skip to content

Commit

Permalink
Merge branch 'fix-tests-master' into 'master'
Browse files Browse the repository at this point in the history
Fix tests master

See merge request mohit.panjvani/crater-web!1413
  • Loading branch information
mohitpanjwani committed Jan 10, 2022
2 parents 54f76f7 + b7c3441 commit 4ca56de
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function index(Request $request)
public function show(Company $company, $id)
{
$expense = $company->expenses()
->whereCustomer(Auth::guard('customer')->id())
->whereUser(Auth::guard('customer')->id())
->where('id', $id)
->first();

Expand Down
50 changes: 27 additions & 23 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,37 @@
Auth::guard('customer')->logout();
});

Route::middleware('pdf-auth')->group(function () {
Route::prefix('reports')->group(function () {

// sales report by customer
//----------------------------------
Route::get('/sales/customers/{hash}', CustomerSalesReportController::class);
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);

// sales report by items
//----------------------------------
Route::get('/sales/items/{hash}', ItemSalesReportController::class);
// report for expenses
//----------------------------------
Route::get('/expenses/{hash}', ExpensesReportController::class);

// report for expenses
//----------------------------------
Route::get('/expenses/{hash}', ExpensesReportController::class);
// report for tax summary
//----------------------------------
Route::get('/tax-summary/{hash}', TaxSummaryReportController::class);

// report for tax summary
//----------------------------------
Route::get('/tax-summary/{hash}', TaxSummaryReportController::class);
// report for profit and loss
//----------------------------------
Route::get('/profit-loss/{hash}', ProfitLossReportController::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 () {

// invoice pdf
// -------------------------------------------------
Expand All @@ -91,14 +99,10 @@
// 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
// -------------------------------------------------

Expand Down
14 changes: 7 additions & 7 deletions tests/Feature/Admin/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,48 @@
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();
});
27 changes: 11 additions & 16 deletions tests/Feature/Admin/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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;
Expand Down Expand Up @@ -203,35 +202,31 @@

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
]);

$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'],
'customer_id' => (string)$payment['customer_id'],
'amount' => (string)$payment['amount'],
]);

$this->assertDatabaseHas('invoices', [
Expand Down
34 changes: 28 additions & 6 deletions tests/Feature/Customer/EstimateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@
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 () {
Expand All @@ -43,15 +46,34 @@
$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();

$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
];

$estimate2 = Estimate::find($estimate->id);
$response = postJson("api/v1/{$customer->company->slug}/customer/estimate/{$estimate->id}/status", $status)
->assertOk();

$this->assertEquals($estimate2->status, Estimate::STATUS_ACCEPTED);
$this->assertEquals($response->json()['data']['status'], Estimate::STATUS_REJECTED);
});
16 changes: 6 additions & 10 deletions tests/Feature/Customer/ExpenseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Auth;
use Laravel\Sanctum\Sanctum;

use function Pest\Laravel\getJson;

beforeEach(function () {
Expand All @@ -32,14 +31,11 @@
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();
});
4 changes: 3 additions & 1 deletion tests/Feature/Customer/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
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();

Expand Down
4 changes: 3 additions & 1 deletion tests/Feature/Customer/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
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();
});
3 changes: 3 additions & 0 deletions tests/Unit/Request/CompanyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
'required',
Rule::unique('companies')->ignore($request->header('company'), 'id'),
],
'slug' => [
'nullable'
],
'address.country_id' => [
'required',
],
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Request/Customer/CustomerProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'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',
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Request/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
'nullable',
],
'enable_portal' => [
'nullable',
'boolean',
],
'currency_id' => [
'nullable',
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Request/TaxTypeTest.php
Original file line number Diff line number Diff line change
@@ -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 () {
Expand All @@ -11,6 +12,7 @@
'name' => [
'required',
Rule::unique('tax_types')
->where('type', TaxType::TYPE_GENERAL)
->where('company_id', $request->header('company'))
],
'percent' => [
Expand Down

0 comments on commit 4ca56de

Please sign in to comment.