66 lines
2.5 KiB
PHP
66 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\ValueObjects\Campaign;
|
|
|
|
use Domain\Models\ValueObjects\Campaign\CampaignCoupon;
|
|
use Domain\Models\ValueObjects\PrintRules;
|
|
use Domain\Models\ValueObjects\ProcessingCode;
|
|
|
|
covers(CampaignCoupon::class);
|
|
|
|
describe('campaign coupon', function (): void {
|
|
it('creates a valid campaign coupon', function (): void {
|
|
// GIVEN
|
|
$code = new ProcessingCode('PC1');
|
|
$qty = new StockId();
|
|
$printRules = new PrintRules(maxPerCustomer: 3);
|
|
$warningThresholdQty = 100;
|
|
|
|
// WHEN
|
|
$campaignCoupon = new CampaignCoupon(code: $code, qty: $qty, printRules: $printRules, warningThresholdQty: $warningThresholdQty);
|
|
|
|
// THEN
|
|
expect($campaignCoupon->code)->toBe($code)
|
|
->and($campaignCoupon->qty)->toBe($qty)
|
|
->and($campaignCoupon->printRules)->toBe($printRules)
|
|
->and($campaignCoupon->warningThresholdQty)->toBe($warningThresholdQty);
|
|
});
|
|
|
|
it('creates a valid campaign coupon whitout print rules', function (): void {
|
|
// GIVEN
|
|
$code = new ProcessingCode('PC1');
|
|
$qty = new StockId();
|
|
$warningThresholdQty = 100;
|
|
|
|
// WHEN
|
|
$campaignCoupon = new CampaignCoupon(code: $code, qty: $qty, warningThresholdQty: $warningThresholdQty);
|
|
|
|
// THEN
|
|
expect($campaignCoupon->code)->toBe($code)
|
|
->and($campaignCoupon->qty)->toBe($qty)
|
|
->and($campaignCoupon->warningThresholdQty)->toBe($warningThresholdQty);
|
|
});
|
|
|
|
it('rejects invalid campaign coupon', function (): void {
|
|
// GIVEN
|
|
$code = new ProcessingCode('PC1');
|
|
$qty = new StockId();
|
|
$printRules = new PrintRules(maxPerCustomer: 3);
|
|
$warningThresholdQty = -100;
|
|
|
|
// GIVEN / THEN
|
|
expect(fn (): CampaignCoupon => new CampaignCoupon(code: $code, qty: $qty, printRules: $printRules, warningThresholdQty: $warningThresholdQty))->toThrow(\DomainException::class);
|
|
});
|
|
|
|
it('rejects invalid campaign coupon whitout print rules', function (): void {
|
|
// GIVEN
|
|
$code = new ProcessingCode('PC1');
|
|
$qty = new StockId();
|
|
$warningThresholdQty = -100;
|
|
|
|
// GIVEN / THEN
|
|
expect(fn (): CampaignCoupon => new CampaignCoupon(code: $code, qty: $qty, warningThresholdQty: $warningThresholdQty))->toThrow(\DomainException::class);
|
|
});
|
|
});
|