Fixes for tests

This commit is contained in:
David Bomba 2024-06-18 13:57:09 +10:00
parent 13b557a4e7
commit e8f26ddbb2
2 changed files with 53 additions and 36 deletions

View File

@ -126,13 +126,12 @@ class MatchBankTransactions implements ShouldQueue
{ {
$collection = collect(); $collection = collect();
/** @array $invoices */
$invoices = explode(",", $invoice_hashed_ids); $invoices = explode(",", $invoice_hashed_ids);
if (count($invoices) >= 1) { foreach ($invoices as $invoice) {
foreach ($invoices as $invoice) { if (is_string($invoice) && strlen($invoice) > 1) {
if (is_string($invoice) && strlen($invoice) > 1) { $collection->push($this->decodePrimaryKey($invoice));
$collection->push($this->decodePrimaryKey($invoice));
}
} }
} }
@ -189,7 +188,7 @@ class MatchBankTransactions implements ShouldQueue
private function coalesceExpenses($expense): string private function coalesceExpenses($expense): string
{ {
if (!$this->bt->expense_id || strlen($this->bt->expense_id) < 1) { if (!$this->bt->expense_id || strlen($this->bt->expense_id ?? '') < 2) {
return $expense; return $expense;
} }
@ -233,11 +232,12 @@ class MatchBankTransactions implements ShouldQueue
$_invoices = Invoice::query() $_invoices = Invoice::query()
->withTrashed() ->withTrashed()
->where('company_id', $this->bt->company_id) ->where('company_id', $this->bt->company_id)
->whereIn('id', $this->getInvoices($input['invoice_ids'])); ->whereIn('id', $this->getInvoices($input['invoice_ids']))
->get();
$amount = $this->bt->amount; $amount = $this->bt->amount;
if ($_invoices && $this->checkPayable($_invoices)) { if ($_invoices->count() >0 && $this->checkPayable($_invoices)) {
$this->createPayment($_invoices, $amount); $this->createPayment($_invoices, $amount);
$this->bts->push($this->bt->id); $this->bts->push($this->bt->id);
@ -323,6 +323,7 @@ class MatchBankTransactions implements ShouldQueue
}); });
}, 2); }, 2);
// @phpstan-ignore-next-line
if (!$this->invoice) { if (!$this->invoice) {
return; return;
} }
@ -355,7 +356,7 @@ class MatchBankTransactions implements ShouldQueue
$this->setExchangeRate($payment); $this->setExchangeRate($payment);
/* Create a payment relationship to the invoice entity */ /* Create a payment relationship to the invoice entity */
foreach ($this->attachable_invoices as $attachable_invoice) { foreach ($this->attachable_invoices as $attachable_invoice) { // @phpstan-ignore-line
$payment->invoices()->attach($attachable_invoice['id'], [ $payment->invoices()->attach($attachable_invoice['id'], [
'amount' => $attachable_invoice['amount'], 'amount' => $attachable_invoice['amount'],
]); ]);

View File

@ -11,19 +11,20 @@
namespace Tests\Feature; namespace Tests\Feature;
use Tests\TestCase;
use App\Utils\Ninja;
use App\Models\Activity;
use Tests\MockAccountData;
use Illuminate\Support\Str;
use App\Models\PurchaseOrder;
use App\Utils\Traits\MakesHash;
use App\Models\PurchaseOrderInvitation;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Session;
use App\Repositories\ActivityRepository;
use App\Events\PurchaseOrder\PurchaseOrderWasCreated; use App\Events\PurchaseOrder\PurchaseOrderWasCreated;
use App\Events\PurchaseOrder\PurchaseOrderWasUpdated; use App\Events\PurchaseOrder\PurchaseOrderWasUpdated;
use App\Models\Activity;
use App\Models\PurchaseOrder;
use App\Repositories\ActivityRepository;
use App\Utils\Ninja;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Str;
use Tests\MockAccountData;
use Tests\TestCase;
class PurchaseOrderTest extends TestCase class PurchaseOrderTest extends TestCase
{ {
@ -97,24 +98,39 @@ class PurchaseOrderTest extends TestCase
public function testPurchaseOrderBulkActions() public function testPurchaseOrderBulkActions()
{ {
$this->purchase_order->service()->createInvitations()->save();
$i = $this->purchase_order->invitations->first(); $po = PurchaseOrder::factory()->create([
'user_id' => $this->user->id,
'company_id' => $this->company->id,
'vendor_id' => $this->vendor->id,
]);
// $data = [ // PurchaseOrderInvitation::factory()->create([
// 'ids' => [$this->purchase_order->hashed_id], // 'user_id' => $this->user->id,
// 'action' => 'download', // 'company_id' => $this->company->id,
// ]; // 'vendor_contact_id' => $this->vendor->contacts()->first()->id,
// 'purchase_order_id' => $po->id,
// ]);
// $response = $this->withHeaders([
// 'X-API-SECRET' => config('ninja.api_secret'), $po->service()->createInvitations()->save();
// 'X-API-TOKEN' => $this->token,
// ])->post("/api/v1/purchase_orders/bulk", $data) $i = $po->invitations->first();
// ->assertStatus(200);
$data = [
'ids' => [$po->hashed_id],
'action' => 'download',
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post("/api/v1/purchase_orders/bulk", $data)
->assertStatus(200);
$data = [ $data = [
'ids' =>[$this->purchase_order->hashed_id], 'ids' =>[$po->hashed_id],
'action' => 'archive', 'action' => 'archive',
]; ];
@ -125,7 +141,7 @@ class PurchaseOrderTest extends TestCase
->assertStatus(200); ->assertStatus(200);
$data = [ $data = [
'ids' =>[$this->purchase_order->hashed_id], 'ids' =>[$po->hashed_id],
'action' => 'restore', 'action' => 'restore',
]; ];
@ -136,7 +152,7 @@ class PurchaseOrderTest extends TestCase
->assertStatus(200); ->assertStatus(200);
$data = [ $data = [
'ids' =>[$this->purchase_order->hashed_id], 'ids' =>[$po->hashed_id],
'action' => 'delete', 'action' => 'delete',
]; ];
@ -148,7 +164,7 @@ class PurchaseOrderTest extends TestCase
$data = [ $data = [
'ids' =>[$this->purchase_order->hashed_id], 'ids' =>[$po->hashed_id],
'action' => 'restore', 'action' => 'restore',
]; ];
@ -171,7 +187,7 @@ class PurchaseOrderTest extends TestCase
->assertStatus(302); ->assertStatus(302);
$data = [ $data = [
'ids' =>[$this->purchase_order->hashed_id], 'ids' =>[$po->hashed_id],
'action' => '', 'action' => '',
]; ];
@ -183,7 +199,7 @@ class PurchaseOrderTest extends TestCase
$data = [ $data = [
'ids' =>[$this->purchase_order->hashed_id], 'ids' =>[$po->hashed_id],
'action' => 'molly', 'action' => 'molly',
]; ];