Files
firefly-iii/tests/Api/V1/Controllers/AccountControllerTest.php

509 lines
20 KiB
PHP
Raw Normal View History

2018-02-17 14:46:12 +01:00
<?php
/**
* AccountControllerTest.php
2020-02-16 13:59:55 +01:00
* Copyright (c) 2019 james@firefly-iii.org
2018-02-17 14:46:12 +01:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-02-17 14:46:12 +01:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2018-02-17 14:46:12 +01:00
*
* This program is distributed in the hope that it will be useful,
2018-02-17 14:46:12 +01:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2018-02-17 14:46:12 +01:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-02-17 14:46:12 +01:00
*/
declare(strict_types=1);
namespace Tests\Api\V1\Controllers;
2019-04-11 06:06:25 +02:00
use Exception;
2018-02-17 14:46:12 +01:00
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
2018-12-16 13:55:19 +01:00
use FireflyIII\Transformers\AccountTransformer;
2018-02-17 14:46:12 +01:00
use Laravel\Passport\Passport;
2018-02-28 20:18:47 +01:00
use Log;
use Tests\TestCase;
2018-02-17 14:46:12 +01:00
/**
* Class AccountControllerTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2018-02-17 14:46:12 +01:00
*/
class AccountControllerTest extends TestCase
{
/**
*
*/
2018-07-01 18:31:02 +02:00
public function setUp(): void
2018-02-17 14:46:12 +01:00
{
parent::setUp();
Passport::actingAs($this->user());
2019-04-09 20:05:20 +02:00
Log::info(sprintf('Now in %s.', get_class($this)));
2018-02-17 14:46:12 +01:00
}
2018-02-17 19:56:45 +01:00
/**
2018-12-16 13:55:19 +01:00
* Opening balance without date.
2018-02-17 19:56:45 +01:00
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\AccountController
2019-06-09 08:26:23 +02:00
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
* @covers \FireflyIII\Api\V1\Requests\Request
2019-04-11 06:06:25 +02:00
* @throws Exception
2018-02-17 19:56:45 +01:00
*/
2018-12-16 13:55:19 +01:00
public function testStoreInvalidBalance(): void
2018-02-17 19:56:45 +01:00
{
// mock repositories
2018-12-21 16:38:10 +01:00
$repository = $this->mock(AccountRepositoryInterface::class);
2018-02-17 19:56:45 +01:00
// mock calls:
2018-12-16 13:55:19 +01:00
$repository->shouldReceive('setUser')->atLeast()->once();
2018-12-21 16:38:10 +01:00
2018-02-17 19:56:45 +01:00
// data to submit
$data = [
2019-06-16 13:16:46 +02:00
'name' => 'Some new asset account #' . $this->randomInt(),
2018-12-16 13:55:19 +01:00
'type' => 'asset',
'account_role' => 'defaultAsset',
'opening_balance' => '123.45',
2018-02-17 19:56:45 +01:00
];
// test API
2018-12-16 13:55:19 +01:00
$response = $this->post(route('api.v1.accounts.store'), $data, ['Accept' => 'application/json']);
2018-02-17 19:56:45 +01:00
$response->assertStatus(422);
$response->assertExactJson(
[
'message' => 'The given data was invalid.',
'errors' => [
2018-12-16 13:55:19 +01:00
'opening_balance_date' => ['The opening balance date field is required when opening balance is present.'],
2018-02-17 19:56:45 +01:00
],
]
);
$response->assertHeader('Content-Type', 'application/json');
}
2019-06-08 06:19:21 +02:00
/**
* @covers \FireflyIII\Api\V1\Controllers\AccountController
*/
public function testShow(): void
{
// mock repositories
$repository = $this->mock(AccountRepositoryInterface::class);
$transformer = $this->mock(AccountTransformer::class);
// mock calls:
$repository->shouldReceive('setUser')->atLeast()->once();
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
[
2019-06-09 08:26:23 +02:00
'id' => 1,
2019-06-08 06:19:21 +02:00
'attributes' => [
2019-06-09 08:26:23 +02:00
'name' => 'Account',
],
2019-06-08 06:19:21 +02:00
]);
$transformer->shouldReceive('setCurrentScope')->atLeast()->once();
$transformer->shouldReceive('getDefaultIncludes')->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('getAvailableIncludes')->atLeast()->once()->andReturn([]);
// getAccountType
$account = $this->getRandomAsset();
$response = $this->get(route('api.v1.accounts.show', [$account->id]));
$response->assertStatus(200);
}
2018-12-10 21:45:44 +01:00
/**
2018-12-16 13:55:19 +01:00
* Send correct data. Should call account repository store method.
2018-12-10 21:45:44 +01:00
*
* @covers \FireflyIII\Api\V1\Controllers\AccountController
2019-06-09 08:26:23 +02:00
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
* @covers \FireflyIII\Api\V1\Requests\Request
2019-04-11 06:06:25 +02:00
* @throws Exception
2018-12-10 21:45:44 +01:00
*/
2018-12-16 13:55:19 +01:00
public function testStoreLiability(): void
2018-12-10 21:45:44 +01:00
{
2018-12-16 13:55:19 +01:00
// mock repositories
2018-12-21 16:38:10 +01:00
$repository = $this->mock(AccountRepositoryInterface::class);
$transformer = $this->mock(AccountTransformer::class);
$account = $this->getRandomAsset();
2018-12-10 21:45:44 +01:00
// mock calls:
2018-12-16 13:55:19 +01:00
$repository->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('store')->atLeast()->once()->andReturn($account);
// mock calls to transformer:
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
2018-12-10 21:45:44 +01:00
2018-12-16 13:55:19 +01:00
// data to submit
$data = [
2019-06-16 13:16:46 +02:00
'name' => 'Some new liability account #' . $this->randomInt(),
2018-12-16 13:55:19 +01:00
'type' => 'liability',
'liability_amount' => '10000',
'liability_start_date' => '2016-01-01',
'liability_type' => 'mortgage',
'active' => true,
'interest' => '1',
'interest_period' => 'daily',
];
2018-12-10 21:45:44 +01:00
// test API
2018-12-16 13:55:19 +01:00
$response = $this->post(route('api.v1.accounts.store'), $data, ['Accept' => 'application/json']);
2018-12-10 21:45:44 +01:00
$response->assertStatus(200);
2018-12-16 13:55:19 +01:00
$response->assertJson(['data' => ['type' => 'accounts', 'links' => true],]);
2018-12-10 21:45:44 +01:00
$response->assertHeader('Content-Type', 'application/vnd.api+json');
2018-12-16 13:55:19 +01:00
2018-12-10 21:45:44 +01:00
}
2018-02-17 19:56:45 +01:00
/**
2018-12-16 13:55:19 +01:00
* CC type present when account is a credit card.
2018-07-01 09:27:22 +02:00
*
* @covers \FireflyIII\Api\V1\Controllers\AccountController
2019-06-09 08:26:23 +02:00
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
* @covers \FireflyIII\Api\V1\Requests\Request
* @throws Exception
2018-02-17 19:56:45 +01:00
*/
2018-12-16 13:55:19 +01:00
public function testStoreNoCreditCardData(): void
2018-02-17 19:56:45 +01:00
{
2018-12-16 13:55:19 +01:00
// mock repositories
2019-06-09 08:26:23 +02:00
$repository = $this->mock(AccountRepositoryInterface::class);
$this->mock(AccountTransformer::class);
2018-02-17 19:56:45 +01:00
// mock calls:
2018-12-16 13:55:19 +01:00
$repository->shouldReceive('setUser')->atLeast()->once();
2018-12-21 16:38:10 +01:00
2018-03-24 06:08:50 +01:00
2018-12-16 13:55:19 +01:00
// data to submit
$data = [
2019-06-16 13:16:46 +02:00
'name' => 'Some new asset account #' . $this->randomInt(),
2018-12-16 13:55:19 +01:00
'type' => 'asset',
'account_role' => 'ccAsset',
];
2018-02-17 19:56:45 +01:00
// test API
2018-12-16 13:55:19 +01:00
$response = $this->post(route('api.v1.accounts.store'), $data, ['Accept' => 'application/json']);
$response->assertStatus(422);
$response->assertExactJson(
[
'message' => 'The given data was invalid.',
'errors' => [
'credit_card_type' => ['The credit card type field is required when account role is ccAsset.'],
'monthly_payment_date' => ['The monthly payment date field is required when account role is ccAsset.'],
],
]
);
$response->assertHeader('Content-Type', 'application/json');
2018-02-17 19:56:45 +01:00
}
/**
2018-12-16 13:55:19 +01:00
* No currency information (is allowed).
*
* @covers \FireflyIII\Api\V1\Controllers\AccountController
2019-06-09 08:26:23 +02:00
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
* @covers \FireflyIII\Api\V1\Requests\Request
2019-04-11 06:06:25 +02:00
* @throws Exception
*/
2018-12-16 13:55:19 +01:00
public function testStoreNoCurrencyInfo(): void
{
// mock repositories
2019-04-11 06:06:25 +02:00
$repository = $this->mock(AccountRepositoryInterface::class);
2018-12-21 16:38:10 +01:00
$transformer = $this->mock(AccountTransformer::class);
2018-12-16 13:55:19 +01:00
// mock calls to transformer:
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
// mock calls:
$repository->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('store')->once()->andReturn(new Account);
// data to submit
$data = [
2019-06-16 13:16:46 +02:00
'name' => 'Some new asset account #' . $this->randomInt(),
2018-12-16 13:55:19 +01:00
'type' => 'asset',
'account_role' => 'defaultAsset',
'include_net_worth' => false,
];
// test API
2018-12-16 13:55:19 +01:00
$response = $this->post(route('api.v1.accounts.store'), $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
$response->assertHeader('Content-Type', 'application/vnd.api+json');
}
2018-02-17 19:56:45 +01:00
/**
* Name already in use.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\AccountController
2019-06-09 08:26:23 +02:00
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
* @covers \FireflyIII\Api\V1\Requests\Request
2018-02-17 19:56:45 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testStoreNotUnique(): void
2018-02-17 19:56:45 +01:00
{
// mock repositories
2019-06-08 06:19:21 +02:00
$repository = $this->mock(AccountRepositoryInterface::class);
2018-02-17 19:56:45 +01:00
// mock calls:
2018-12-16 13:55:19 +01:00
$repository->shouldReceive('setUser')->atLeast()->once();
2018-12-21 16:38:10 +01:00
2018-02-17 19:56:45 +01:00
2018-12-16 13:55:19 +01:00
$account = $this->getRandomAsset();
2018-02-17 19:56:45 +01:00
// data to submit
$data = [
'name' => $account->name,
'currency_id' => 1,
'type' => 'asset',
'active' => 1,
'include_net_worth' => 1,
'account_role' => 'defaultAsset',
2018-02-17 19:56:45 +01:00
];
// test API
2018-12-16 13:55:19 +01:00
$response = $this->post(route('api.v1.accounts.store'), $data, ['Accept' => 'application/json']);
2018-02-17 19:56:45 +01:00
$response->assertStatus(422);
$response->assertExactJson(
[
'message' => 'The given data was invalid.',
'errors' => [
2018-07-01 09:27:22 +02:00
'name' => ['This account name is already in use.'],
2018-02-17 19:56:45 +01:00
],
]
);
$response->assertHeader('Content-Type', 'application/json');
}
/**
* Send correct data. Should call account repository store method.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\AccountController
2019-06-09 08:26:23 +02:00
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
* @covers \FireflyIII\Api\V1\Requests\Request
2019-04-11 06:06:25 +02:00
* @throws Exception
2018-02-17 19:56:45 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testStoreValid(): void
2018-02-17 19:56:45 +01:00
{
// mock repositories
2019-04-11 06:06:25 +02:00
$repository = $this->mock(AccountRepositoryInterface::class);
2018-12-21 16:38:10 +01:00
$transformer = $this->mock(AccountTransformer::class);
$account = $this->getRandomAsset();
2018-02-17 19:56:45 +01:00
2018-12-16 13:55:19 +01:00
// mock calls:
$repository->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('store')->atLeast()->once()->andReturn($account);
// mock calls to transformer:
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
2018-03-24 06:08:50 +01:00
2018-02-17 19:56:45 +01:00
// data to submit
$data = [
2019-06-16 13:16:46 +02:00
'name' => 'Some new asset account #' . $this->randomInt(),
2018-12-16 13:55:19 +01:00
'type' => 'asset',
'account_role' => 'defaultAsset',
2018-02-17 19:56:45 +01:00
];
// test API
2018-12-16 13:55:19 +01:00
$response = $this->post(route('api.v1.accounts.store'), $data, ['Accept' => 'application/json']);
2018-02-17 19:56:45 +01:00
$response->assertStatus(200);
$response->assertJson(['data' => ['type' => 'accounts', 'links' => true],]);
$response->assertHeader('Content-Type', 'application/vnd.api+json');
}
/**
* Send correct data. Should call account repository store method.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\AccountController
2019-06-09 08:26:23 +02:00
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
* @covers \FireflyIII\Api\V1\Requests\Request
2019-04-11 06:06:25 +02:00
* @throws Exception
2018-02-17 19:56:45 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testStoreWithCurrencyCode(): void
2018-02-17 19:56:45 +01:00
{
// mock repositories
2019-04-11 06:06:25 +02:00
$repository = $this->mock(AccountRepositoryInterface::class);
2018-12-21 16:38:10 +01:00
$transformer = $this->mock(AccountTransformer::class);
$account = $this->getRandomAsset();
2018-02-17 19:56:45 +01:00
// mock calls:
2018-12-16 13:55:19 +01:00
$repository->shouldReceive('setUser')->atLeast()->once();
2018-12-21 16:38:10 +01:00
2018-12-16 13:55:19 +01:00
$repository->shouldReceive('store')->atLeast()->once()->andReturn($account);
// mock calls to transformer:
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
2018-02-17 19:56:45 +01:00
// data to submit
$data = [
2019-06-16 13:16:46 +02:00
'name' => 'Some new asset account #' . $this->randomInt(),
2018-12-16 13:55:19 +01:00
'currency_code' => 'EUR',
'type' => 'asset',
'account_role' => 'defaultAsset',
2018-02-17 19:56:45 +01:00
];
// test API
2018-12-16 13:55:19 +01:00
$response = $this->post(route('api.v1.accounts.store'), $data, ['Accept' => 'application/json']);
2018-02-17 19:56:45 +01:00
$response->assertStatus(200);
$response->assertJson(['data' => ['type' => 'accounts', 'links' => true],]);
$response->assertHeader('Content-Type', 'application/vnd.api+json');
2018-12-10 21:45:44 +01:00
}
2018-02-17 19:56:45 +01:00
/**
* Update first asset account we find. Name can be the same as it was.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\AccountController
2019-06-09 08:26:23 +02:00
* @covers \FireflyIII\Api\V1\Requests\AccountUpdateRequest
* @covers \FireflyIII\Api\V1\Requests\Request
2018-02-17 19:56:45 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testUpdate(): void
2018-02-17 19:56:45 +01:00
{
// mock repositories
2019-06-08 06:19:21 +02:00
$repository = $this->mock(AccountRepositoryInterface::class);
2018-12-21 16:38:10 +01:00
$transformer = $this->mock(AccountTransformer::class);
2018-02-17 19:56:45 +01:00
// mock calls:
2018-12-16 13:55:19 +01:00
$repository->shouldReceive('setUser')->atLeast()->once();
2018-12-21 16:38:10 +01:00
2018-12-16 13:55:19 +01:00
$repository->shouldReceive('update')->atLeast()->once();
// mock calls to transformer:
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
$account = $this->getRandomAsset();
2018-02-17 19:56:45 +01:00
// data to submit
$data = [
2019-04-11 06:06:25 +02:00
'active' => true,
'include_net_worth' => true,
'name' => $account->name,
'type' => 'asset',
'account_role' => 'defaultAsset',
2018-02-17 19:56:45 +01:00
];
// test API
2018-12-16 13:55:19 +01:00
$response = $this->put(route('api.v1.accounts.update', [$account->id]), $data, ['Accept' => 'application/json']);
2018-02-17 19:56:45 +01:00
$response->assertStatus(200);
$response->assertJson(['data' => ['type' => 'accounts', 'links' => true],]);
$response->assertHeader('Content-Type', 'application/vnd.api+json');
}
/**
* Update first asset account we find. Name can be the same as it was.
*
2018-07-01 09:27:22 +02:00
* @covers \FireflyIII\Api\V1\Controllers\AccountController
2019-06-09 08:26:23 +02:00
* @covers \FireflyIII\Api\V1\Requests\AccountUpdateRequest
* @covers \FireflyIII\Api\V1\Requests\Request
2018-02-17 19:56:45 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testUpdateCurrencyCode(): void
2018-02-17 19:56:45 +01:00
{
// mock repositories
2018-12-21 16:38:10 +01:00
$repository = $this->mock(AccountRepositoryInterface::class);
$transformer = $this->mock(AccountTransformer::class);
2018-02-17 19:56:45 +01:00
// mock calls:
2018-12-16 13:55:19 +01:00
$repository->shouldReceive('setUser')->atLeast()->once();
2018-12-21 16:38:10 +01:00
2018-12-16 13:55:19 +01:00
$repository->shouldReceive('update')->atLeast()->once();
2018-02-17 19:56:45 +01:00
2018-12-16 13:55:19 +01:00
// mock calls to transformer:
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
2018-03-24 06:08:50 +01:00
2018-12-16 13:55:19 +01:00
$account = $this->getRandomAsset();
2018-02-17 19:56:45 +01:00
// data to submit
$data = [
2018-12-16 13:55:19 +01:00
'name' => $account->name,
'type' => 'asset',
'currency_code' => 'EUR',
'account_role' => 'defaultAsset',
2018-02-17 19:56:45 +01:00
];
// test API
2018-12-16 13:55:19 +01:00
$response = $this->put(route('api.v1.accounts.update', [$account->id]), $data, ['Accept' => 'application/json']);
2018-02-17 19:56:45 +01:00
$response->assertStatus(200);
$response->assertJson(['data' => ['type' => 'accounts', 'links' => true],]);
$response->assertHeader('Content-Type', 'application/vnd.api+json');
}
2019-04-11 06:06:25 +02:00
/**
* Update a liability
*
* @covers \FireflyIII\Api\V1\Controllers\AccountController
2019-06-09 08:26:23 +02:00
* @covers \FireflyIII\Api\V1\Requests\AccountUpdateRequest
* @covers \FireflyIII\Api\V1\Requests\Request
2019-04-11 06:06:25 +02:00
*/
public function testUpdateLiability(): void
{
// mock repositories
$repository = $this->mock(AccountRepositoryInterface::class);
$transformer = $this->mock(AccountTransformer::class);
// mock calls:
$repository->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('update')->atLeast()->once();
// mock calls to transformer:
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
$account = $this->getRandomAsset();
// data to submit
$data = [
'active' => true,
'include_net_worth' => true,
'name' => $account->name,
'type' => 'liability',
'liability_type' => 'loan',
'liability_amount' => '100',
'interest' => '1',
'interest_period' => 'yearly',
'liability_start_date' => '2019-01-01',
'account_role' => 'defaultAsset',
];
// test API
$response = $this->put(route('api.v1.accounts.update', [$account->id]), $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
$response->assertJson(['data' => ['type' => 'accounts', 'links' => true],]);
$response->assertHeader('Content-Type', 'application/vnd.api+json');
}
2018-02-17 14:46:12 +01:00
2018-03-04 15:14:29 +01:00
}