mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Tests for account summary DTOP
This commit is contained in:
parent
a9dffb335e
commit
9b187cc6fb
@ -17,94 +17,94 @@ use Spatie\LaravelData\Attributes\MapOutputName;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* {#2983
|
||||
* [
|
||||
"account": [
|
||||
{#2979
|
||||
[
|
||||
"CONTAINER": "bank",
|
||||
"providerAccountId": 10058190,
|
||||
"accountName": "Business Trans Acct",
|
||||
"providerAccountId": 1005,
|
||||
"accountName": "Business Acct",
|
||||
"accountStatus": "ACTIVE",
|
||||
"accountNumber": "1011 4402",
|
||||
"accountNumber": "1011",
|
||||
"aggregationSource": "USER",
|
||||
"isAsset": true,
|
||||
"balance": {#2978
|
||||
"balance": [
|
||||
"currency": "AUD",
|
||||
"amount": 308544.98,
|
||||
},
|
||||
"amount": 304.98,
|
||||
],
|
||||
"id": 10139315,
|
||||
"includeInNetWorth": true,
|
||||
"providerId": "3857",
|
||||
"providerName": "Commonwealth Bank",
|
||||
"providerName": "Bank",
|
||||
"isManual": false,
|
||||
"availableBalance": {#2966
|
||||
"currency": "AUD",
|
||||
"amount": 309044.98,
|
||||
},
|
||||
"currentBalance": {#2982
|
||||
"amount": 304.98,
|
||||
],
|
||||
"currentBalance": [
|
||||
"currency": "AUD",
|
||||
"amount": 308544.98,
|
||||
},
|
||||
"amount": 3044.98,
|
||||
],
|
||||
"accountType": "CHECKING",
|
||||
"displayedName": "after David",
|
||||
"createdDate": "2023-01-10T08:29:07Z",
|
||||
"classification": "SMALL_BUSINESS",
|
||||
"lastUpdated": "2023-08-01T23:50:13Z",
|
||||
"nickname": "Business Trans Acct",
|
||||
"nickname": "Business ",
|
||||
"bankTransferCode": [
|
||||
{#2976
|
||||
"id": "062020",
|
||||
[
|
||||
"id": "062",
|
||||
"type": "BSB",
|
||||
},
|
||||
],
|
||||
],
|
||||
"dataset": [
|
||||
{#2971
|
||||
[
|
||||
"name": "BASIC_AGG_DATA",
|
||||
"additionalStatus": "AVAILABLE_DATA_RETRIEVED",
|
||||
"updateEligibility": "ALLOW_UPDATE",
|
||||
"lastUpdated": "2023-08-01T23:49:53Z",
|
||||
"lastUpdateAttempt": "2023-08-01T23:49:53Z",
|
||||
"nextUpdateScheduled": "2023-08-03T14:45:14Z",
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
],
|
||||
],
|
||||
}
|
||||
];
|
||||
*/
|
||||
class AccountSummary extends Data
|
||||
{
|
||||
public ?int $id;
|
||||
|
||||
#[MapInputName('CONTAINER')]
|
||||
public ?string $account_type;
|
||||
public ?string $account_type = '';
|
||||
|
||||
#[MapInputName('accountName')]
|
||||
public ?string $account_name;
|
||||
public ?string $account_name = '';
|
||||
|
||||
#[MapInputName('accountStatus')]
|
||||
public ?string $account_status;
|
||||
public ?string $account_status = '';
|
||||
|
||||
#[MapInputName('accountNumber')]
|
||||
public ?string $account_number;
|
||||
public ?string $account_number = '';
|
||||
|
||||
#[MapInputName('providerAccountId')]
|
||||
public int $provider_account_id;
|
||||
|
||||
#[MapInputName('providerId')]
|
||||
public ?string $provider_id;
|
||||
public ?string $provider_id = '';
|
||||
|
||||
#[MapInputName('providerName')]
|
||||
public ?string $provider_name;
|
||||
public ?string $provider_name = '';
|
||||
|
||||
public ?string $nickname;
|
||||
public ?string $nickname = '';
|
||||
|
||||
public ?float $current_balance;
|
||||
public ?string $account_currency;
|
||||
public ?float $current_balance = 0;
|
||||
public ?string $account_currency = '';
|
||||
|
||||
public static function prepareForPipeline(Collection $properties) : Collection
|
||||
{
|
||||
|
||||
$properties->put('current_balance', (array)$properties['currentBalance']['amount'] ?? '');
|
||||
$properties->put('account_currency', (array)$properties['currentBalance']['currency'] ?? '');
|
||||
$properties->put('current_balance', $properties['currentBalance']['amount'] ?? 0);
|
||||
$properties->put('account_currency', $properties['currentBalance']['currency'] ?? 0);
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
144
tests/Integration/DTO/AccountSummaryTest.php
Normal file
144
tests/Integration/DTO/AccountSummaryTest.php
Normal file
@ -0,0 +1,144 @@
|
||||
<?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\Integration\DTO;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
class AccountSummaryTest extends TestCase
|
||||
{
|
||||
|
||||
private $data = [
|
||||
[
|
||||
"CONTAINER"=> "bank",
|
||||
"providerAccountId"=> 330,
|
||||
"accountName"=> "Business Acct",
|
||||
"accountStatus"=> "ACTIVE",
|
||||
"accountNumber"=> "1012",
|
||||
"aggregationSource"=> "USER",
|
||||
"isAsset"=> true,
|
||||
"balance"=> [
|
||||
"currency"=> "AUD",
|
||||
"amount"=> 44.98,
|
||||
],
|
||||
"id"=> 19315,
|
||||
"includeInNetWorth"=> true,
|
||||
"providerId"=> "3857",
|
||||
"providerName"=> "Bank",
|
||||
"isManual"=> false,
|
||||
"availableBalance"=> [
|
||||
"currency"=> "AUD",
|
||||
"amount"=> 34.98,
|
||||
],
|
||||
"currentBalance"=> [
|
||||
"currency"=> "AUD",
|
||||
"amount"=> 344.98,
|
||||
],
|
||||
"accountType"=> "CHECKING",
|
||||
"displayedName"=> "after David",
|
||||
"createdDate"=> "2023-01-10T08=>29=>07Z",
|
||||
"classification"=> "",
|
||||
"lastUpdated"=> "2023-08-01T23=>50=>13Z",
|
||||
"nickname"=> "Busines Acct",
|
||||
"bankTransferCode"=> [
|
||||
[
|
||||
"id"=> "062",
|
||||
"type"=> "BSB",
|
||||
],
|
||||
],
|
||||
"dataset"=> [
|
||||
[
|
||||
"name"=> "BASIC_AGG_DATA",
|
||||
"additionalStatus"=> "AVAILABLE_DATA_RETRIEVED",
|
||||
"updateEligibility"=> "ALLOW_UPDATE",
|
||||
"lastUpdated"=> "2023-08-01T23=>49=>53Z",
|
||||
"lastUpdateAttempt"=> "2023-08-01T23=>49=>53Z",
|
||||
"nextUpdateScheduled"=> "2023-08-03T14=>45=>14Z",
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
private $bad_data = [
|
||||
[
|
||||
"CONTAINER"=> "bank",
|
||||
"providerAccountId"=> 10090,
|
||||
"accountName"=> "Business Trans Acct",
|
||||
// "accountStatus"=> "ACTIVE",
|
||||
"accountNumber"=> "4402",
|
||||
"aggregationSource"=> "USER",
|
||||
"isAsset"=> true,
|
||||
"balance"=> [
|
||||
"currency"=> "AUD",
|
||||
"amount"=> 34.98,
|
||||
],
|
||||
"id"=> 19315,
|
||||
"includeInNetWorth"=> true,
|
||||
"providerId"=> "37",
|
||||
"providerName"=> "Bank",
|
||||
"isManual"=> false,
|
||||
// "availableBalance"=> [
|
||||
// "currency"=> "AUD",
|
||||
// "amount"=> 7.98,
|
||||
// ],
|
||||
"currentBalance"=> [
|
||||
"currency"=> "AUD",
|
||||
"amount"=> 344.98,
|
||||
],
|
||||
"accountType"=> "CHECKING",
|
||||
"displayedName"=> "after David",
|
||||
"createdDate"=> "2023-01-10T08=>29=>07Z",
|
||||
"classification"=> "SMALL_BUSINESS",
|
||||
"lastUpdated"=> "2023-08-01T23=>50=>13Z",
|
||||
"nickname"=> "Busines Acct",
|
||||
"bankTransferCode"=> [
|
||||
[
|
||||
"id"=> "060",
|
||||
"type"=> "BSB",
|
||||
],
|
||||
],
|
||||
"dataset"=> [
|
||||
[
|
||||
"name"=> "BASIC_AGG_DATA",
|
||||
"additionalStatus"=> "AVAILABLE_DATA_RETRIEVED",
|
||||
"updateEligibility"=> "ALLOW_UPDATE",
|
||||
"lastUpdated"=> "2023-08-01T23=>49=>53Z",
|
||||
"lastUpdateAttempt"=> "2023-08-01T23=>49=>53Z",
|
||||
"nextUpdateScheduled"=> "2023-08-03T14=>45=>14Z",
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
|
||||
protected function setUp() :void
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testWithBadDataTransformations()
|
||||
{
|
||||
$dtox = \App\Helpers\Bank\Yodlee\DTO\AccountSummary::from($this->bad_data[0]);
|
||||
$this->assertEquals(19315, $dtox->id);
|
||||
$this->assertEquals('', $dtox->account_status);
|
||||
}
|
||||
|
||||
public function testTransform()
|
||||
{
|
||||
$dto = \App\Helpers\Bank\Yodlee\DTO\AccountSummary::from($this->data[0]);
|
||||
$this->assertEquals($dto->id, 19315);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user