geschenkgutscheine implementiert ("Paket verschenken"). Neuer Upload-Provider: Sparkbooth.
This commit is contained in:
83
tests/Unit/GiftVoucherServiceTest.php
Normal file
83
tests/Unit/GiftVoucherServiceTest.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Enums\CouponType;
|
||||
use App\Jobs\SyncCouponToPaddle;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\GiftVoucher;
|
||||
use App\Models\Package;
|
||||
use App\Services\GiftVouchers\GiftVoucherService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Tests\TestCase;
|
||||
|
||||
class GiftVoucherServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_it_issues_voucher_and_coupon_from_paddle_payload(): void
|
||||
{
|
||||
$package = Package::factory()->create([
|
||||
'type' => 'endcustomer',
|
||||
'paddle_price_id' => 'pri_pkg_001',
|
||||
'price' => 59,
|
||||
]);
|
||||
|
||||
$payload = [
|
||||
'id' => 'txn_123',
|
||||
'event_type' => 'transaction.completed',
|
||||
'currency_code' => 'EUR',
|
||||
'totals' => [
|
||||
'grand_total' => [
|
||||
'amount' => 5900,
|
||||
],
|
||||
],
|
||||
'metadata' => [
|
||||
'type' => 'gift_card',
|
||||
'purchaser_email' => 'buyer@example.com',
|
||||
'recipient_email' => 'friend@example.com',
|
||||
'recipient_name' => 'Friend',
|
||||
'message' => 'Happy Day',
|
||||
],
|
||||
'checkout_id' => 'chk_abc',
|
||||
];
|
||||
|
||||
Bus::fake([SyncCouponToPaddle::class]);
|
||||
|
||||
$service = $this->app->make(GiftVoucherService::class);
|
||||
$voucher = $service->issueFromPaddle($payload);
|
||||
|
||||
$this->assertInstanceOf(GiftVoucher::class, $voucher);
|
||||
$this->assertSame(59.00, (float) $voucher->amount);
|
||||
$this->assertNotNull($voucher->coupon);
|
||||
$this->assertSame($voucher->code, $voucher->coupon->code);
|
||||
$this->assertTrue($voucher->expires_at->greaterThan(now()->addYears(4)));
|
||||
$this->assertTrue($voucher->coupon->packages()->whereKey($package->id)->exists());
|
||||
Bus::assertDispatched(SyncCouponToPaddle::class);
|
||||
}
|
||||
|
||||
public function test_redeeming_coupon_marks_voucher_redeemed(): void
|
||||
{
|
||||
$voucher = GiftVoucher::factory()->create([
|
||||
'status' => GiftVoucher::STATUS_ISSUED,
|
||||
'amount' => 29,
|
||||
]);
|
||||
|
||||
$coupon = Coupon::factory()->create([
|
||||
'code' => $voucher->code,
|
||||
'type' => CouponType::FLAT,
|
||||
'amount' => 29,
|
||||
'currency' => 'EUR',
|
||||
'paddle_discount_id' => null,
|
||||
]);
|
||||
|
||||
$voucher->coupon()->associate($coupon)->save();
|
||||
|
||||
$service = $this->app->make(GiftVoucherService::class);
|
||||
$service->markRedeemed($coupon, 'txn_999');
|
||||
|
||||
$this->assertSame(GiftVoucher::STATUS_REDEEMED, $voucher->refresh()->status);
|
||||
$this->assertNotNull($voucher->redeemed_at);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user