1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/tests/Feature/Bank/YodleeBankTransactionTest.php

108 lines
3.5 KiB
PHP
Raw Normal View History

2022-08-12 07:25:18 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace Tests\Feature\Bank;
use App\Models\BankTransaction;
use App\Models\Invoice;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\MockAccountData;
use Tests\TestCase;
class YodleeBankTransactionTest extends TestCase
{
use DatabaseTransactions;
use MockAccountData;
protected function setUp() :void
{
parent::setUp();
2023-02-16 02:36:09 +01:00
if (!config('ninja.yodlee.client_id')) {
2022-08-12 07:25:18 +02:00
$this->markTestSkipped('Skip test no Yodlee API credentials found');
2023-02-16 02:36:09 +01:00
}
2022-08-12 07:25:18 +02:00
$this->makeTestData();
$this->withoutMiddleware(
ThrottleRequests::class
);
}
public function testDataMatching1()
{
$this->invoice->number = "super-funk-1234";
$this->invoice->save();
$bank_transaction = BankTransaction::where('company_id', $this->company->id)->first();
$bank_transaction->description = "super-funk-1234";
$bank_transaction->save();
$this->assertNotNull($this->invoice);
$this->assertNotNull($bank_transaction);
$invoices = Invoice::where('company_id', $this->company->id)->get();
BankTransaction::where('company_id', $this->company->id)
2022-09-21 09:00:49 +02:00
->where('status_id', BankTransaction::STATUS_UNMATCHED)
2022-08-12 07:25:18 +02:00
->cursor()
2023-02-16 02:36:09 +01:00
->each(function ($bt) use ($invoices) {
$invoice = $invoices->first(function ($value, $key) use ($bt) {
return str_contains($value->number, $bt->description);
});
if ($invoice) {
$bt->invoice_ids = $invoice->hashed_id;
$bt->status_id = BankTransaction::STATUS_MATCHED;
$bt->save();
}
2022-08-12 07:25:18 +02:00
});
2022-09-21 09:00:49 +02:00
$this->assertTrue(BankTransaction::where('invoice_ids', $this->invoice->hashed_id)->exists());
2022-08-12 07:25:18 +02:00
}
public function testDataMatching2()
{
$this->invoice->number = "super-funk-1234";
$this->invoice->save();
$bank_transaction = BankTransaction::where('company_id', $this->company->id)->first();
$bank_transaction->description = "super-funk-123";
$bank_transaction->save();
$this->assertNotNull($this->invoice);
$this->assertNotNull($bank_transaction);
$invoices = Invoice::where('company_id', $this->company->id)->get();
BankTransaction::where('company_id', $this->company->id)
2022-09-21 09:00:49 +02:00
->where('status_id', BankTransaction::STATUS_UNMATCHED)
2022-08-12 07:25:18 +02:00
->cursor()
2023-02-16 02:36:09 +01:00
->each(function ($bt) use ($invoices) {
$invoice = $invoices->first(function ($value, $key) use ($bt) {
return str_contains($value->number, $bt->description);
});
if ($invoice) {
$bt->invoice_ids = $invoice->hashed_id;
$bt->status_id = BankTransaction::STATUS_MATCHED;
$bt->save();
}
2022-08-12 07:25:18 +02:00
});
2022-09-21 09:00:49 +02:00
$this->assertTrue(BankTransaction::where('invoice_ids', $this->invoice->hashed_id)->exists());
2022-08-12 07:25:18 +02:00
}
2023-02-16 02:36:09 +01:00
}