87 lines
3.0 KiB
PHP
87 lines
3.0 KiB
PHP
<?php
|
|
|
|
use App\Enums\BankingConnectionStatus;
|
|
use App\Models\BankingConnection;
|
|
use App\Models\User;
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
|
|
|
use function Pest\Laravel\actingAs;
|
|
|
|
test('guests receive null auth user in shared props', function () {
|
|
$response = $this->withoutVite()->get(route('home'));
|
|
|
|
$response->assertInertia(fn (Assert $page) => $page
|
|
->where('auth.user', null)
|
|
);
|
|
});
|
|
|
|
test('authenticated users receive auth user in shared props', function () {
|
|
$user = User::factory()->create(['timezone' => 'Europe/Madrid']);
|
|
|
|
$response = actingAs($user)->withoutVite()->get(route('home'));
|
|
|
|
$response->assertInertia(fn (Assert $page) => $page
|
|
->where('auth.user.id', $user->id)
|
|
->where('auth.user.email', $user->email)
|
|
->where('auth.user.timezone', 'Europe/Madrid')
|
|
);
|
|
});
|
|
|
|
test('all pages receive app url in shared props', function () {
|
|
$response = $this->withoutVite()->get(route('home'));
|
|
|
|
$response->assertInertia(fn (Assert $page) => $page
|
|
->where('appUrl', config('app.url'))
|
|
);
|
|
});
|
|
|
|
test('shared feature flags do not include coinbase flag', function () {
|
|
$response = $this->withoutVite()->get(route('home'));
|
|
|
|
$props = $response->viewData('page')['props'];
|
|
|
|
expect($props['features'])->toBe([
|
|
'cashflow' => true,
|
|
]);
|
|
});
|
|
|
|
test('authenticated users receive expired banking connection reconnect links', function () {
|
|
$user = User::factory()->onboarded()->create();
|
|
$expiredConnection = BankingConnection::factory()->create([
|
|
'user_id' => $user->id,
|
|
'aspsp_name' => 'Santander',
|
|
'status' => BankingConnectionStatus::Active,
|
|
'valid_until' => now()->subDay(),
|
|
]);
|
|
BankingConnection::factory()->create([
|
|
'user_id' => $user->id,
|
|
'aspsp_name' => 'Fresh Bank',
|
|
'status' => BankingConnectionStatus::Active,
|
|
'valid_until' => now()->addDay(),
|
|
]);
|
|
|
|
$response = actingAs($user)->withoutVite()->get(route('dashboard'));
|
|
|
|
$response->assertInertia(fn (Assert $page) => $page
|
|
->has('expiredBankingConnections', 1)
|
|
->where('expiredBankingConnections.0.id', $expiredConnection->id)
|
|
->where('expiredBankingConnections.0.aspsp_name', 'Santander')
|
|
->where('expiredBankingConnections.0.reconnect_url', route('open-banking.reconnect', $expiredConnection))
|
|
);
|
|
});
|
|
|
|
test('shared currency options split profile and account currencies', function () {
|
|
$response = $this->withoutVite()->get(route('home'));
|
|
|
|
$response->assertInertia(fn (Assert $page) => $page
|
|
->where('currencies.profile.0.code', 'USD')
|
|
->where('currencies.accounts.0.code', 'USD')
|
|
);
|
|
|
|
$props = $response->viewData('page')['props'];
|
|
|
|
expect(collect($props['currencies']['profile'])->pluck('code'))->toContain('ARS');
|
|
expect(collect($props['currencies']['profile'])->pluck('code'))->not->toContain('BTC');
|
|
expect(collect($props['currencies']['accounts'])->pluck('code'))->toContain('BTC');
|
|
});
|