Skip to content

Commit c0df115

Browse files
committed
Pass tests payment description/notes
1 parent 4d1b5db commit c0df115

File tree

8 files changed

+43
-16
lines changed

8 files changed

+43
-16
lines changed

src/Interfaces/WalletOperations.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public function getWalletBalanceByType(string $walletType);
1010

1111
public function hasSufficientBalance($value): bool;
1212

13-
public function pay(int|float $orderValue);
13+
public function pay(int|float $orderValue, ?string $notes = null);
1414

15-
public function deposit(string $type, int|float $amount): bool;
15+
public function deposit(string $type, int|float $amount, ?string $notes = null): bool;
1616
}

src/Models/WalletsLog.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class WalletsLog extends Model
1616
use HasFactory;
1717

1818
protected $fillable = [
19-
'from', 'to', 'type', 'ip', 'value', 'wallet_name',
19+
'from', 'to', 'type', 'ip', 'value', 'wallet_name', 'notes',
2020
];
2121

2222
public function loggable(): MorphTo

src/Services/PocketServices.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
class PocketServices
66
{
7-
public function deposit($user, $type, $amount)
7+
public function deposit($user, $type, $amount, $notes = null)
88
{
9-
return $user->deposit($type, $amount);
9+
return $user->deposit($type, $amount, $notes);
1010
}
1111

12-
public function pay($user, $orderValue)
12+
public function pay($user, $orderValue, $notes = null)
1313
{
14-
return $user->pay($orderValue);
14+
return $user->pay($orderValue, $notes);
1515
}
1616

1717
public function checkBalance($user)

src/Traits/HandlesDeposit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait HandlesDeposit
1515
/**
1616
* Deposit an amount to the user's wallet of a specific type.
1717
*/
18-
public function deposit(string $type, int|float $amount, $notes = null): bool
18+
public function deposit(string $type, int|float $amount, ?string $notes = null): bool
1919
{
2020
$depositable = $this->getDepositableTypes();
2121

src/Traits/HandlesPayment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trait HandlesPayment
1313
*
1414
* @throws InsufficientBalanceException
1515
*/
16-
public function pay(int|float $orderValue, $notes = null): void
16+
public function pay(int|float $orderValue, ?string $notes = null): void
1717
{
1818
if (! $this->hasSufficientBalance($orderValue)) {
1919
throw new InsufficientBalanceException('Insufficient balance to cover the order.');

tests/OperationsWithFacadeTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use HPWebdeveloper\LaravelPayPocket\Facades\LaravelPayPocket;
4+
use HPWebdeveloper\LaravelPayPocket\Models\WalletsLog;
45
use HPWebdeveloper\LaravelPayPocket\Tests\Models\User;
56

67
it('can test', function () {
@@ -96,7 +97,18 @@
9697
expect(LaravelPayPocket::checkBalance($user))->toBeFloat(0.12);
9798
});
9899

99-
test('description can be added during payment', function () {
100+
test('notes can be added during deposit', function () {
101+
$user = User::factory()->create();
102+
103+
$type = 'wallet_2';
104+
105+
$description = \Illuminate\Support\Str::random();
106+
LaravelPayPocket::deposit($user, $type, 234.56, $description);
107+
108+
expect(WalletsLog::where('notes', $description)->exists())->toBe(true);
109+
});
110+
111+
test('notes can be added during payment', function () {
100112
$user = User::factory()->create();
101113

102114
$type = 'wallet_2';

tests/OperationsWithoutFacadeTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use HPWebdeveloper\LaravelPayPocket\Models\WalletsLog;
34
use HPWebdeveloper\LaravelPayPocket\Tests\Models\User;
45

56
it('can test', function () {
@@ -97,7 +98,18 @@
9798
expect($user->walletBalance)->toBeFloat(0.12);
9899
});
99100

100-
test('description can be added during payment', function () {
101+
test('notes can be added during deposit', function () {
102+
$user = User::factory()->create();
103+
104+
$type = 'wallet_2';
105+
106+
$description = \Illuminate\Support\Str::random();
107+
$user->deposit($type, 234.56, $description);
108+
109+
expect(WalletsLog::where('notes', $description)->exists())->toBe(true);
110+
});
111+
112+
test('notes can be added during payment', function () {
101113
$user = User::factory()->create();
102114

103115
$type = 'wallet_2';

tests/TestCase.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ protected function setUp(): void
2222
*/
2323

2424
Factory::guessFactoryNamesUsing(
25-
fn (string $modelName) => 'HPWebdeveloper\\LaravelPayPocket\\Tests\\Database\\Factories\\'.class_basename(
25+
fn (string $modelName) => 'HPWebdeveloper\\LaravelPayPocket\\Tests\\Database\\Factories\\' . class_basename(
2626
$modelName
27-
).'Factory'
27+
) . 'Factory'
2828
);
2929
}
3030

@@ -46,13 +46,16 @@ public function getEnvironmentSetUp($app)
4646
$migration->up();
4747
*/
4848

49-
$migration = include __DIR__.'/database/migrations/create_users_tables.php';
49+
$migration = include __DIR__ . '/database/migrations/create_users_tables.php';
5050
$migration->up();
5151

52-
$migration = include __DIR__.'/../database/migrations/create_wallets_logs_table.php.stub';
52+
$migration = include __DIR__ . '/../database/migrations/create_wallets_logs_table.php.stub';
5353
$migration->up();
5454

55-
$migration = include __DIR__.'/../database/migrations/create_wallets_table.php.stub';
55+
$migration = include __DIR__ . '/../database/migrations/create_wallets_table.php.stub';
56+
$migration->up();
57+
58+
$migration = include __DIR__ . '/../database/migrations/update_wallets_logs_table.php.stub';
5659
$migration->up();
5760
}
5861
}

0 commit comments

Comments
 (0)