|
15 | 15 | use Bavix\Wallet\Models\Transfer; |
16 | 16 | use Bavix\Wallet\Services\BookkeeperServiceInterface; |
17 | 17 | use Bavix\Wallet\Services\RegulatorServiceInterface; |
| 18 | +use Bavix\Wallet\Test\Infra\Exceptions\PriceNotSetException; |
18 | 19 | use Bavix\Wallet\Test\Infra\Factories\ItemFactory; |
| 20 | +use Bavix\Wallet\Test\Infra\Factories\ItemMultiPriceFactory; |
19 | 21 | use Bavix\Wallet\Test\Infra\Factories\UserCashierFactory; |
20 | 22 | use Bavix\Wallet\Test\Infra\Factories\UserMultiFactory; |
21 | 23 | use Bavix\Wallet\Test\Infra\Helpers\Config; |
22 | 24 | use Bavix\Wallet\Test\Infra\Models\Item; |
| 25 | +use Bavix\Wallet\Test\Infra\Models\ItemMultiPrice; |
23 | 26 | use Bavix\Wallet\Test\Infra\Models\UserCashier; |
24 | 27 | use Bavix\Wallet\Test\Infra\Models\UserMulti; |
25 | 28 | use Bavix\Wallet\Test\Infra\PackageModels\Wallet; |
@@ -545,6 +548,65 @@ public function testPay(): void |
545 | 548 | self::assertSame($b->balanceInt, $product->getAmountProduct($b)); |
546 | 549 | } |
547 | 550 |
|
| 551 | + public function testPayItemMultiPrice(): void |
| 552 | + { |
| 553 | + /** @var UserMulti $user */ |
| 554 | + $user = UserMultiFactory::new()->create(); |
| 555 | + |
| 556 | + $usd = $user->createWallet([ |
| 557 | + 'name' => 'Dollar USA', |
| 558 | + 'meta' => [ |
| 559 | + 'currency' => 'USD', |
| 560 | + ], |
| 561 | + ]); |
| 562 | + |
| 563 | + /** @var ItemMultiPrice $product */ |
| 564 | + $product = ItemMultiPriceFactory::new()->create([ |
| 565 | + 'quantity' => 1, |
| 566 | + ]); |
| 567 | + |
| 568 | + self::assertSame(0, $usd->balanceInt); |
| 569 | + |
| 570 | + $usd->deposit($product->getAmountProduct($usd)); |
| 571 | + self::assertSame($usd->balanceInt, $product->getAmountProduct($usd)); |
| 572 | + |
| 573 | + $transfer = $usd->pay($product); |
| 574 | + $paidTransfer = $usd->paid($product); |
| 575 | + self::assertNotNull($paidTransfer); |
| 576 | + self::assertTrue((bool) $paidTransfer); |
| 577 | + self::assertSame($transfer->getKey(), $paidTransfer->getKey()); |
| 578 | + self::assertInstanceOf(UserMulti::class, $paidTransfer->withdraw->payable); |
| 579 | + self::assertSame($user->getKey(), $paidTransfer->withdraw->payable->getKey()); |
| 580 | + self::assertSame($transfer->from->getKey(), $usd->getKey()); |
| 581 | + self::assertSame($transfer->to->getKey(), $product->wallet->getKey()); |
| 582 | + self::assertSame($transfer->status, Transfer::STATUS_PAID); |
| 583 | + self::assertSame($usd->balanceInt, 0); |
| 584 | + self::assertSame($product->balanceInt, $product->getAmountProduct($usd)); |
| 585 | + } |
| 586 | + |
| 587 | + public function testPayItemMultiPricePriceNotSetException(): void |
| 588 | + { |
| 589 | + $this->expectExceptionMessageStrict('Price not set for TRY currency'); |
| 590 | + $this->expectException(PriceNotSetException::class); |
| 591 | + |
| 592 | + /** @var UserMulti $user */ |
| 593 | + $user = UserMultiFactory::new()->create(); |
| 594 | + $try = $user->createWallet([ |
| 595 | + 'name' => 'Turkish lira', |
| 596 | + 'meta' => [ |
| 597 | + 'currency' => 'TRY', |
| 598 | + ], |
| 599 | + ]); |
| 600 | + |
| 601 | + /** @var ItemMultiPrice $product */ |
| 602 | + $product = ItemMultiPriceFactory::new()->create([ |
| 603 | + 'quantity' => 1, |
| 604 | + ]); |
| 605 | + |
| 606 | + self::assertSame(0, $try->balanceInt); |
| 607 | + $product->getAmountProduct($try); |
| 608 | + } |
| 609 | + |
548 | 610 | public function testUserCashier(): void |
549 | 611 | { |
550 | 612 | /** @var UserCashier $user */ |
|
0 commit comments