diff --git a/app/Http/Controllers/ViewDashboard.php b/app/Http/Controllers/ViewDashboard.php index 77927e3..5ee02e2 100644 --- a/app/Http/Controllers/ViewDashboard.php +++ b/app/Http/Controllers/ViewDashboard.php @@ -8,11 +8,8 @@ class ViewDashboard extends Controller { public function __invoke() { - $supabaseConfig = config('supabase'); - $databaseService = new DatabaseService($supabaseConfig['api_key'], $supabaseConfig['url']); - - $wiseConfig = config('wise'); - $wiseService = new WiseService($wiseConfig['api_token'], $wiseConfig['profile_id']); + $wiseService = new WiseService(config('wise.api_token'), config('wise.profile_id')); + $databaseService = new DatabaseService(config('supabase.api_key'), config('supabase.url')); return view('dashboard', [ 'balance' => $wiseService->getBalance(), diff --git a/app/Services/WiseService.php b/app/Services/WiseService.php index da18459..aee552e 100644 --- a/app/Services/WiseService.php +++ b/app/Services/WiseService.php @@ -2,6 +2,7 @@ namespace App\Services; +use Carbon\Carbon; use Illuminate\Support\Facades\Http; class WiseService @@ -22,7 +23,11 @@ public function getLatestTransactions() { return collect( $this->getResult('activities', 1)->activities - ); + )->map(function ($activity) { + $activity->createdOn = Carbon::parse($activity->createdOn)->diffForHumans(); + + return $activity; + }); } protected function getResult($uri, $version) diff --git a/tests/Unit/WiseServiceTest.php b/tests/Unit/WiseServiceTest.php index 16ac63e..5788eb3 100644 --- a/tests/Unit/WiseServiceTest.php +++ b/tests/Unit/WiseServiceTest.php @@ -1,5 +1,6 @@ group('wise'); -beforeEach(function () { - $this->wiseService = new WiseService('fake_api_token', 'fake_profile_id'); -}); +beforeEach(fn () => + $this->wiseService = new WiseService('fake_api_token', 'fake_profile_id') +); -afterEach(function () { - Http::assertSent(fn (Request $request) => - $request->hasHeader('Authorization', 'Bearer fake_api_token') - ); -}); +afterEach(fn () => Http::assertSent(fn (Request $request) => + $request->hasHeader('Authorization', 'Bearer fake_api_token') +)); function fakeRequest($uri, $version, $file) { Http::fake(["https://api.transferwise.com/v{$version}/profiles/fake_profile_id/{$uri}" => Http::response( @@ -30,6 +29,8 @@ function fakeRequest($uri, $version, $file) { }); test('you_can_get_your_latest_transactions', function () { + Carbon::setTestNow('2023-01-02'); + fakeRequest('activities', 1, 'latest_transactions'); expect($transactions = $this->wiseService->getLatestTransactions()) @@ -39,8 +40,8 @@ function fakeRequest($uri, $version, $file) { expect($transaction->status)->toBe('COMPLETED'); expect($transaction->type)->toBe('CARD_PAYMENT'); + expect($transaction->createdOn)->toBe('1 day ago'); expect($transaction->primaryAmount)->toBe('12 USD'); expect($transaction->secondaryAmount)->toBe('10 EUR'); - expect($transaction->createdOn)->toBe('2023-01-01T00:00:00.000Z'); expect($transaction->title)->toBe('Test Transaction'); });