chore: code style
This commit is contained in:
+10
-10
@@ -2,18 +2,19 @@
|
||||
|
||||
namespace Tests\Api;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User;
|
||||
use App\Models\Holding;
|
||||
use App\Models\Portfolio;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class HoldingsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected User $user;
|
||||
|
||||
protected Portfolio $portfolio;
|
||||
|
||||
protected function setUp(): void
|
||||
@@ -29,14 +30,14 @@ class HoldingsTest extends TestCase
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Transaction::factory(10)->create();
|
||||
|
||||
|
||||
$this->actingAs($this->user)
|
||||
->getJson(route('api.holding.index', ['page' => 1, 'itemsPerPage' => 5]))
|
||||
->assertOk()
|
||||
->assertJsonStructure([
|
||||
'data' => [['id', 'symbol', 'portfolio_id', 'total_market_value', 'dividends_earned']],
|
||||
'meta' => ['current_page', 'last_page', 'total'],
|
||||
'links' => ['first', 'last', 'prev', 'next']
|
||||
'links' => ['first', 'last', 'prev', 'next'],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -45,7 +46,7 @@ class HoldingsTest extends TestCase
|
||||
// create transactions with existing user
|
||||
$this->actingAs($this->user);
|
||||
Transaction::factory(10)->create();
|
||||
|
||||
|
||||
// Create a new user
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
Transaction::factory(1)->create();
|
||||
@@ -88,14 +89,14 @@ class HoldingsTest extends TestCase
|
||||
$transaction = Transaction::factory()->create();
|
||||
|
||||
$data = [
|
||||
'reinvest_dividends' => true
|
||||
'reinvest_dividends' => true,
|
||||
];
|
||||
|
||||
$this->actingAs($this->user)
|
||||
->putJson(route('api.holding.update', ['portfolio' => $transaction->portfolio_id, 'symbol' => $transaction->symbol]), $data)
|
||||
->assertOk()
|
||||
->assertJsonFragment([
|
||||
'reinvest_dividends' => true
|
||||
'reinvest_dividends' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -105,7 +106,7 @@ class HoldingsTest extends TestCase
|
||||
$transaction = Transaction::factory()->create();
|
||||
|
||||
$data = [
|
||||
'reinvest_dividends' => true
|
||||
'reinvest_dividends' => true,
|
||||
];
|
||||
|
||||
$otherUser = User::factory()->create();
|
||||
@@ -113,5 +114,4 @@ class HoldingsTest extends TestCase
|
||||
->putJson(route('api.holding.update', ['portfolio' => $transaction->portfolio_id, 'symbol' => $transaction->symbol]), $data)
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,16 +2,17 @@
|
||||
|
||||
namespace Tests\Api;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User;
|
||||
use App\Models\Portfolio;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PortfoliosTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected User $user;
|
||||
|
||||
protected Portfolio $portfolio;
|
||||
|
||||
protected function setUp(): void
|
||||
@@ -27,14 +28,14 @@ class PortfoliosTest extends TestCase
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Portfolio::factory(10)->create();
|
||||
|
||||
|
||||
$this->actingAs($this->user)
|
||||
->getJson(route('api.portfolio.index', ['page' => 1, 'itemsPerPage' => 5]))
|
||||
->assertOk()
|
||||
->assertJsonStructure([
|
||||
'data' => [['id', 'title', 'owner', 'holdings', 'transactions']],
|
||||
'meta' => ['current_page', 'last_page', 'total'],
|
||||
'links' => ['first', 'last', 'prev', 'next']
|
||||
'links' => ['first', 'last', 'prev', 'next'],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ class PortfoliosTest extends TestCase
|
||||
// create portfolios with existing user
|
||||
$this->actingAs($this->user);
|
||||
Portfolio::factory(10)->create();
|
||||
|
||||
|
||||
// Create a new user
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
Portfolio::factory(1)->create();
|
||||
@@ -61,12 +62,12 @@ class PortfoliosTest extends TestCase
|
||||
public function test_can_create_a_portfolio()
|
||||
{
|
||||
$data = Portfolio::factory()->make()->toArray();
|
||||
|
||||
|
||||
$this->actingAs($this->user)
|
||||
->postJson(route('api.portfolio.store'), $data)
|
||||
->assertCreated()
|
||||
->assertJsonStructure(['id', 'title', 'owner']);
|
||||
|
||||
|
||||
$this->assertDatabaseHas('portfolios', ['title' => $data['title']]);
|
||||
}
|
||||
|
||||
@@ -102,12 +103,12 @@ class PortfoliosTest extends TestCase
|
||||
|
||||
$this->actingAs($this->user);
|
||||
$portfolio = Portfolio::factory()->create();
|
||||
|
||||
|
||||
$this->actingAs($this->user)
|
||||
->putJson(route('api.portfolio.update', $portfolio), $updatedData)
|
||||
->assertOk()
|
||||
->assertJson($updatedData);
|
||||
|
||||
|
||||
$this->assertDatabaseHas('portfolios', $updatedData);
|
||||
}
|
||||
|
||||
@@ -126,7 +127,7 @@ class PortfoliosTest extends TestCase
|
||||
->putJson(route('api.portfolio.update', $portfolio), ['title' => 'A brand new updated title'])
|
||||
->assertOk()
|
||||
->assertJsonFragment([
|
||||
'title' => 'A brand new updated title'
|
||||
'title' => 'A brand new updated title',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -185,7 +186,7 @@ class PortfoliosTest extends TestCase
|
||||
$this->actingAs($this->user)
|
||||
->deleteJson(route('api.portfolio.destroy', $portfolio))
|
||||
->assertNoContent();
|
||||
|
||||
|
||||
$this->assertDatabaseMissing('portfolios', ['id' => $portfolio->id]);
|
||||
}
|
||||
|
||||
@@ -199,4 +200,4 @@ class PortfoliosTest extends TestCase
|
||||
->deleteJson(route('api.portfolio.destroy', $portfolio))
|
||||
->assertForbidden();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,17 +2,18 @@
|
||||
|
||||
namespace Tests\Api;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Models\User;
|
||||
use App\Models\Portfolio;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TransactionsTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected User $user;
|
||||
|
||||
protected Portfolio $portfolio;
|
||||
|
||||
protected function setUp(): void
|
||||
@@ -21,7 +22,7 @@ class TransactionsTest extends TestCase
|
||||
|
||||
// make user
|
||||
$this->user = User::factory()->create();
|
||||
|
||||
|
||||
// make portfolio
|
||||
$this->portfolio = Portfolio::factory()->makeOne();
|
||||
$this->portfolio->setOwnerIdAttribute($this->user->id);
|
||||
@@ -33,14 +34,14 @@ class TransactionsTest extends TestCase
|
||||
$this->actingAs($this->user);
|
||||
|
||||
Transaction::factory(10)->create();
|
||||
|
||||
|
||||
$this->actingAs($this->user)
|
||||
->getJson(route('api.transaction.index', ['page' => 1, 'itemsPerPage' => 5]))
|
||||
->assertOk()
|
||||
->assertJsonStructure([
|
||||
'data' => [['id', 'symbol', 'transaction_type', 'portfolio_id', 'date']],
|
||||
'meta' => ['current_page', 'last_page', 'total'],
|
||||
'links' => ['first', 'last', 'prev', 'next']
|
||||
'links' => ['first', 'last', 'prev', 'next'],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -49,7 +50,7 @@ class TransactionsTest extends TestCase
|
||||
// create transactions with existing user
|
||||
$this->actingAs($this->user);
|
||||
Transaction::factory(10)->create();
|
||||
|
||||
|
||||
// Create a new user
|
||||
$this->actingAs($user = User::factory()->create());
|
||||
Transaction::factory(1)->create();
|
||||
@@ -88,7 +89,7 @@ class TransactionsTest extends TestCase
|
||||
'quantity',
|
||||
'date',
|
||||
'cost_basis',
|
||||
'sale_price'
|
||||
'sale_price',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -97,7 +98,7 @@ class TransactionsTest extends TestCase
|
||||
$this->actingAs($this->user)
|
||||
->postJson(route('api.transaction.store'), [
|
||||
'portfolio_id' => $this->portfolio->id,
|
||||
'symbol' => null
|
||||
'symbol' => null,
|
||||
])
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors(['symbol']);
|
||||
@@ -133,7 +134,7 @@ class TransactionsTest extends TestCase
|
||||
'symbol' => 'ZZZ',
|
||||
'transaction_type' => 'BUY',
|
||||
'cost_basis' => 200.19,
|
||||
'quantity' => 5
|
||||
'quantity' => 5,
|
||||
];
|
||||
|
||||
$this->actingAs($this->user)
|
||||
@@ -162,7 +163,7 @@ class TransactionsTest extends TestCase
|
||||
->putJson(route('api.transaction.update', $transaction), ['symbol' => 'ZZZ'])
|
||||
->assertOk()
|
||||
->assertJsonFragment([
|
||||
'symbol' => 'ZZZ'
|
||||
'symbol' => 'ZZZ',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -198,4 +199,4 @@ class TransactionsTest extends TestCase
|
||||
->deleteJson(route('api.transaction.destroy', $transaction))
|
||||
->assertForbidden();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user