File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ class Transaction extends Model
2626 protected $ fillable = [
2727 'payable_type ' ,
2828 'payable_id ' ,
29+ 'wallet_id ' ,
2930 'uuid ' ,
3031 'type ' ,
3132 'amount ' ,
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ public function setNameAttribute(string $name): void
6868 */
6969 public function calculateBalance (): bool
7070 {
71- $ balance = $ this ->transactions ()
71+ $ balance = $ this ->holder -> transactions ()
7272 ->where ('wallet_id ' , $ this ->getKey ())
7373 ->where ('confirmed ' , true )
7474 ->sum ('amount ' );
Original file line number Diff line number Diff line change @@ -176,4 +176,27 @@ public function testConfirmed(): void
176176 $ this ->assertEquals ($ user ->balance , 0 );
177177 }
178178
179+ /**
180+ * @return void
181+ */
182+ public function testRecalculate (): void
183+ {
184+ /**
185+ * @var User $user
186+ */
187+ $ user = factory (User::class)->create ();
188+ $ this ->assertEquals ($ user ->balance , 0 );
189+
190+ $ user ->deposit (100 , null , false );
191+ $ this ->assertEquals ($ user ->balance , 0 );
192+
193+ $ user ->transactions ()->update (['confirmed ' => true ]);
194+ $ this ->assertEquals ($ user ->balance , 0 );
195+
196+ $ user ->wallet ->calculateBalance ();
197+ $ this ->assertEquals ($ user ->balance , 100 );
198+
199+ $ user ->withdraw ($ user ->balance );
200+ }
201+
179202}
You can’t perform that action at this time.
0 commit comments