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-25 11:54:47 +02:00
|
|
|
use Domain\Models\ValueObjects\WarningThresholdQuantity;
|
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 {
|
|
|
|
|
it('creates a valid campaign coupon', function (): void {
|
|
|
|
|
// GIVEN
|
2026-09-29 17:12:16 +02:00
|
|
|
$processingCode = new ProcessingCode('PC1');
|
|
|
|
|
$quantity = new CouponQuantity(10);
|
2026-09-29 18:26:18 +02:00
|
|
|
$availableIn = Country::FRANCE;
|
2026-09-29 17:12:16 +02:00
|
|
|
$warningThresholdQuantity = new WarningThresholdQuantity(100);
|
|
|
|
|
$printRules = new PrintRules(maxPerCustomer: 3);
|
2026-09-23 13:13:49 +02:00
|
|
|
|
|
|
|
|
// WHEN
|
2026-09-29 17:12:16 +02:00
|
|
|
$campaignCoupon = new CampaignCoupon($processingCode, $quantity, $availableIn, $warningThresholdQuantity, $printRules);
|
2026-09-23 13:13:49 +02:00
|
|
|
|
|
|
|
|
// THEN
|
2026-09-29 17:12:16 +02:00
|
|
|
expect($campaignCoupon->processingCode)->toBe($processingCode)
|
|
|
|
|
->and($campaignCoupon->quantity)->toBe($quantity)
|
|
|
|
|
->and($campaignCoupon->availableIn)->toBe($availableIn)
|
|
|
|
|
->and($campaignCoupon->warningThresholdQuantity)->toBe($warningThresholdQuantity)
|
|
|
|
|
->and($campaignCoupon->printRules)->toBe($printRules);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('creates a valid campaign coupon whitout warning threshold quantity', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$processingCode = new ProcessingCode('PC1');
|
|
|
|
|
$quantity = new CouponQuantity(10);
|
2026-09-29 18:26:18 +02:00
|
|
|
$availableIn = Country::FRANCE;
|
2026-09-29 17:12:16 +02:00
|
|
|
$printRules = new PrintRules(maxPerCustomer: 3);
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$campaignCoupon = new CampaignCoupon(
|
|
|
|
|
processingCode: $processingCode,
|
|
|
|
|
quantity: $quantity,
|
|
|
|
|
availableIn: $availableIn,
|
|
|
|
|
printRules: $printRules
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($campaignCoupon->processingCode)->toBe($processingCode)
|
|
|
|
|
->and($campaignCoupon->quantity)->toBe($quantity)
|
|
|
|
|
->and($campaignCoupon->availableIn)->toBe($availableIn)
|
|
|
|
|
->and($campaignCoupon->printRules)->toBe($printRules);
|
2026-09-23 13:13:49 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('creates a valid campaign coupon whitout print rules', function (): void {
|
|
|
|
|
// GIVEN
|
2026-09-29 17:12:16 +02:00
|
|
|
$processingCode = new ProcessingCode('PC1');
|
|
|
|
|
$quantity = new CouponQuantity(10);
|
2026-09-29 18:26:18 +02:00
|
|
|
$availableIn = Country::FRANCE;
|
2026-09-29 17:12:16 +02:00
|
|
|
$warningThresholdQuantity = new WarningThresholdQuantity(100);
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$campaignCoupon = new CampaignCoupon(
|
|
|
|
|
processingCode: $processingCode,
|
|
|
|
|
quantity: $quantity,
|
|
|
|
|
availableIn: $availableIn,
|
|
|
|
|
warningThresholdQuantity: $warningThresholdQuantity
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($campaignCoupon->processingCode)->toBe($processingCode)
|
|
|
|
|
->and($campaignCoupon->quantity)->toBe($quantity)
|
|
|
|
|
->and($campaignCoupon->availableIn)->toBe($availableIn)
|
|
|
|
|
->and($campaignCoupon->warningThresholdQuantity)->toBe($warningThresholdQuantity);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('creates a valid campaign coupon whitout warning threshold quantity and print rules', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$processingCode = new ProcessingCode('PC1');
|
|
|
|
|
$quantity = new CouponQuantity(10);
|
2026-09-29 18:26:18 +02:00
|
|
|
$availableIn = Country::FRANCE;
|
2026-09-23 13:13:49 +02:00
|
|
|
|
|
|
|
|
// WHEN
|
2026-09-29 17:12:16 +02:00
|
|
|
$campaignCoupon = new CampaignCoupon(processingCode: $processingCode, quantity: $quantity, availableIn: $availableIn);
|
2026-09-23 13:13:49 +02:00
|
|
|
|
|
|
|
|
// THEN
|
2026-09-29 17:12:16 +02:00
|
|
|
expect($campaignCoupon->processingCode)->toBe($processingCode)
|
|
|
|
|
->and($campaignCoupon->quantity)->toBe($quantity)
|
|
|
|
|
->and($campaignCoupon->availableIn)->toBe($availableIn);
|
2026-09-23 13:13:49 +02:00
|
|
|
});
|
|
|
|
|
});
|