2026-09-23 13:13:49 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects\Campaign;
|
|
|
|
|
|
|
|
|
|
use Domain\Models\ValueObjects\Campaign\CampaignCoupon;
|
2026-09-29 17:12:16 +02:00
|
|
|
use Domain\Models\ValueObjects\Coupon\CouponQuantity;
|
2026-09-23 13:13:49 +02:00
|
|
|
use Domain\Models\ValueObjects\PrintRules;
|
|
|
|
|
use Domain\Models\ValueObjects\ProcessingCode;
|
2026-09-29 18:26:18 +02:00
|
|
|
use Shared\Enums\Country;
|
2026-09-23 13:13:49 +02:00
|
|
|
|
|
|
|
|
covers(CampaignCoupon::class);
|
|
|
|
|
|
|
|
|
|
describe('campaign coupon', function (): void {
|
2026-10-01 12:04:26 +02:00
|
|
|
beforeEach(function (): void {
|
2026-10-02 12:46:02 +02:00
|
|
|
$this->processingCode = new ProcessingCode('PC1');
|
|
|
|
|
$this->quantity = new CouponQuantity(10);
|
|
|
|
|
$this->availableIn = Country::FRANCE;
|
|
|
|
|
$this->printRules = new PrintRules(maxPerCustomer: 3);
|
2026-10-01 12:04:26 +02:00
|
|
|
});
|
2026-09-23 13:13:49 +02:00
|
|
|
|
2026-10-01 12:04:26 +02:00
|
|
|
it('creates a valid campaign coupon', function (): void {
|
|
|
|
|
// GIVEN / WHEN
|
|
|
|
|
$campaignCoupon = new CampaignCoupon(
|
|
|
|
|
$this->processingCode,
|
|
|
|
|
$this->quantity,
|
|
|
|
|
$this->availableIn,
|
|
|
|
|
$this->printRules
|
|
|
|
|
);
|
2026-09-23 13:13:49 +02:00
|
|
|
|
|
|
|
|
// THEN
|
2026-10-01 12:04:26 +02:00
|
|
|
expect($campaignCoupon->processingCode)->toBe($this->processingCode)
|
|
|
|
|
->and($campaignCoupon->quantity)->toBe($this->quantity)
|
|
|
|
|
->and($campaignCoupon->availableIn)->toBe($this->availableIn)
|
|
|
|
|
->and($campaignCoupon->printRules)->toBe($this->printRules);
|
2026-09-29 17:12:16 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('creates a valid campaign coupon whitout warning threshold quantity', function (): void {
|
2026-10-01 12:04:26 +02:00
|
|
|
// GIVEN / WHEN
|
2026-09-29 17:12:16 +02:00
|
|
|
$campaignCoupon = new CampaignCoupon(
|
2026-10-01 12:04:26 +02:00
|
|
|
processingCode: $this->processingCode,
|
|
|
|
|
quantity: $this->quantity,
|
|
|
|
|
availableIn: $this->availableIn,
|
|
|
|
|
printRules: $this->printRules
|
2026-09-29 17:12:16 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// THEN
|
2026-10-01 12:04:26 +02:00
|
|
|
expect($campaignCoupon->processingCode)->toBe($this->processingCode)
|
|
|
|
|
->and($campaignCoupon->quantity)->toBe($this->quantity)
|
|
|
|
|
->and($campaignCoupon->availableIn)->toBe($this->availableIn)
|
|
|
|
|
->and($campaignCoupon->printRules)->toBe($this->printRules);
|
2026-09-23 13:13:49 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('creates a valid campaign coupon whitout print rules', function (): void {
|
2026-10-01 12:04:26 +02:00
|
|
|
// GIVEN / WHEN
|
2026-09-29 17:12:16 +02:00
|
|
|
$campaignCoupon = new CampaignCoupon(
|
2026-10-01 12:04:26 +02:00
|
|
|
processingCode: $this->processingCode,
|
|
|
|
|
quantity: $this->quantity,
|
|
|
|
|
availableIn: $this->availableIn,
|
2026-09-29 17:12:16 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// THEN
|
2026-10-01 12:04:26 +02:00
|
|
|
expect($campaignCoupon->processingCode)->toBe($this->processingCode)
|
|
|
|
|
->and($campaignCoupon->quantity)->toBe($this->quantity)
|
2026-10-02 11:33:03 +02:00
|
|
|
->and($campaignCoupon->availableIn)->toBe($this->availableIn);
|
2026-09-29 17:12:16 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('creates a valid campaign coupon whitout warning threshold quantity and print rules', function (): void {
|
2026-10-01 12:04:26 +02:00
|
|
|
// GIVEN / WHEN
|
|
|
|
|
$campaignCoupon = new CampaignCoupon(
|
|
|
|
|
processingCode: $this->processingCode,
|
|
|
|
|
quantity: $this->quantity,
|
|
|
|
|
availableIn: $this->availableIn
|
|
|
|
|
);
|
2026-09-23 13:13:49 +02:00
|
|
|
|
|
|
|
|
// THEN
|
2026-10-01 12:04:26 +02:00
|
|
|
expect($campaignCoupon->processingCode)->toBe($this->processingCode)
|
|
|
|
|
->and($campaignCoupon->quantity)->toBe($this->quantity)
|
|
|
|
|
->and($campaignCoupon->availableIn)->toBe($this->availableIn);
|
2026-09-23 13:13:49 +02:00
|
|
|
});
|
|
|
|
|
});
|