Skip to content

Commit

Permalink
Showing dates in a more readable way
Browse files Browse the repository at this point in the history
  • Loading branch information
manelgavalda committed Nov 5, 2023
1 parent caee98b commit 36a1f53
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
7 changes: 2 additions & 5 deletions app/Http/Controllers/ViewDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
7 changes: 6 additions & 1 deletion app/Services/WiseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Services;

use Carbon\Carbon;
use Illuminate\Support\Facades\Http;

class WiseService
Expand All @@ -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)
Expand Down
19 changes: 10 additions & 9 deletions tests/Unit/WiseServiceTest.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<?php

use Carbon\Carbon;
use App\Services\WiseService;
use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http;

uses()->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(
Expand All @@ -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())
Expand All @@ -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('<strong>Test Transaction</strong>');
});

0 comments on commit 36a1f53

Please sign in to comment.