feat: ✨ country enum is on coupon, and used as a backup

This commit is contained in:
K Muller 2026-09-29 09:02:22 +02:00 • committed by Corentin Huet
parent 2c693d9045
commit 44c65cf9f6
11 changed files with 36 additions and 38 deletions

View file

@ -45,7 +45,6 @@ final readonly class FindCampaignRequest implements UseCase
return new CampaignRequestFound(
brand: $brand,
applicant: $campaignRequest->applicant,
country: $campaignRequest->country,
campaignType: $campaignRequest->campaignType,
printRules: $campaignRequest->printRules,
requestedCoupon: $campaignRequest->requestedCoupon,

View file

@ -18,7 +18,6 @@ final readonly class CampaignRequestFound implements Output
public function __construct(
public Brand $brand,
public Applicant $applicant,
public CountryAuthorized $country,
public CampaignRequestType $campaignType,
public ?PrintRules $printRules,
public RequestedCoupon $requestedCoupon,

View file

@ -10,7 +10,6 @@ use Domain\Models\ValueObjects\Brand\BrandCode;
use Domain\Models\ValueObjects\CampaignRequest\CampaignRequestId;
use Domain\Models\ValueObjects\CampaignRequest\Applicant;
use Domain\Models\ValueObjects\CampaignRequest\RejectionReason;
use Domain\Models\ValueObjects\CountryAuthorized;
use Domain\Models\ValueObjects\PrintRules;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCoupon;
use Shared\DDD\Models\AggregateRoot;
@ -26,7 +25,6 @@ final readonly class CampaignRequest implements AggregateRoot, HasTimestampIdent
public CampaignRequestId $id,
public BrandCode $code,
public Applicant $applicant,
public CountryAuthorized $country,
public CampaignRequestType $campaignType,
public ?PrintRules $printRules,
public RequestedCoupon $requestedCoupon,
@ -63,7 +61,6 @@ final readonly class CampaignRequest implements AggregateRoot, HasTimestampIdent
CampaignRequestId $id,
BrandCode $code,
Applicant $applicant,
CountryAuthorized $country,
CampaignRequestType $campaignType,
?PrintRules $printRules,
RequestedCoupon $requestedCoupon,
@ -75,7 +72,6 @@ final readonly class CampaignRequest implements AggregateRoot, HasTimestampIdent
id: $id,
code: $code,
applicant: $applicant,
country: $country,
campaignType: $campaignType,
printRules: $printRules,
requestedCoupon: $requestedCoupon,
@ -95,7 +91,6 @@ final readonly class CampaignRequest implements AggregateRoot, HasTimestampIdent
id: $this->id,
code: $this->code,
applicant: $this->applicant,
country: $this->country,
campaignType: $this->campaignType,
printRules: $this->printRules,
requestedCoupon: $this->requestedCoupon,

View file

@ -11,17 +11,21 @@ use Shared\Enums\Country;
final readonly class CountryAuthorized implements \Stringable, Equatable
{
/** @var list<Country> */
private const array AUTHORIZED = [
Country::FRANCE,
Country::BELGIUM,
Country::LUXEMBOURG,
];
private static function authorized(): array
{
return [
Country::FRANCE,
...Country::benelux(),
];
}
public function __construct(
public Country $country,
) {
if (! in_array($this->country, self::AUTHORIZED, true)) {
throw new \DomainException(sprintf('Country "%s" is not authorized.', $this->country->name));
if (! in_array($this->country, self::authorized(), true)) {
throw new \DomainException(
sprintf('Country "%s" is not authorized.', $this->country->name)
);
}
}
@ -30,7 +34,10 @@ final readonly class CountryAuthorized implements \Stringable, Equatable
*/
public static function authorizedCountries(): array
{
return self::AUTHORIZED;
return [
Country::FRANCE,
...Country::benelux(),
];
}
#[Override]

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Domain\Models\ValueObjects\RequestedCoupon;
use Domain\Models\ValueObjects\CountryAuthorized;
use Domain\Models\ValueObjects\Coupon\CouponValidity;
use Domain\Models\ValueObjects\CouponName;
use Domain\Models\ValueObjects\CouponPicture;
@ -27,6 +28,7 @@ final readonly class RequestedCoupon
public CouponPicture $couponPicture,
public GS1 $gs1,
public CouponValidity $couponValidity,
public CountryAuthorized $country,
) {
}
}

View file

@ -583,4 +583,12 @@ enum Country: string
{
return self::ISOCODES;
}
public static function benelux(): array
{
return [
self::BELGIUM,
self::LUXEMBOURG
];
}
}

View file

@ -60,6 +60,7 @@ describe('find campaign request use case', function (): void {
new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg')),
new GS1('01234567890128', BarcodeFormat::EAN13),
new CouponValidity(30, new DateTime()),
new CountryAuthorized(Country::FRANCE)
);
});
@ -71,7 +72,6 @@ describe('find campaign request use case', function (): void {
$id,
$code,
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
new CountryAuthorized(Country::FRANCE),
CampaignRequestType::CLUB,
new PrintRules(maxPerCustomer: 3),
$this->requestedCoupon,
@ -101,7 +101,6 @@ describe('find campaign request use case', function (): void {
expect($result)->toBeInstanceOf(CampaignRequestFound::class)
->and($result->brand)->toBe($brand)
->and($result->applicant)->toBe($campaignRequest->applicant)
->and($result->country)->toBe($campaignRequest->country)
->and($result->campaignType)->toBe($campaignRequest->campaignType)
->and($result->printRules)->toBe($campaignRequest->printRules)
->and($result->requestedCoupon)->toBe($campaignRequest->requestedCoupon)
@ -118,7 +117,6 @@ describe('find campaign request use case', function (): void {
$id,
$code,
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
new CountryAuthorized(Country::FRANCE),
CampaignRequestType::CLUB,
new PrintRules(maxPerCustomer: 3),
$this->requestedCoupon,
@ -179,7 +177,6 @@ describe('find campaign request use case', function (): void {
$id,
$code,
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
new CountryAuthorized(Country::FRANCE),
CampaignRequestType::CLUB,
new PrintRules(maxPerCustomer: 3),
$this->requestedCoupon,

View file

@ -53,6 +53,7 @@ describe('list campaigns request use case', function (): void {
new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg')),
new GS1('01234567890128', BarcodeFormat::EAN13),
new CouponValidity(30, new DateTime()),
new CountryAuthorized(Country::FRANCE)
);
$this->couponB = new RequestedCoupon(
@ -66,6 +67,7 @@ describe('list campaigns request use case', function (): void {
new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg')),
new GS1('01234567890128', BarcodeFormat::EAN13),
new CouponValidity(30, new DateTime()),
new CountryAuthorized(Country::FRANCE)
);
});
@ -76,7 +78,6 @@ describe('list campaigns request use case', function (): void {
CampaignRequestId::generate(),
new BrandCode('AAA01'),
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
new CountryAuthorized(Country::FRANCE),
CampaignRequestType::CLUB,
new PrintRules(maxPerCustomer: 3),
$this->couponA,
@ -86,7 +87,6 @@ describe('list campaigns request use case', function (): void {
CampaignRequestId::generate(),
new BrandCode('AAA02'),
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
new CountryAuthorized(Country::FRANCE),
CampaignRequestType::CLUB,
new PrintRules(maxPerCustomer: 3),
$this->couponB,

View file

@ -58,6 +58,7 @@ describe('reject campaign request use case', function (): void {
new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg')),
new GS1('01234567890128', BarcodeFormat::EAN13),
new CouponValidity(30, new DateTime()),
new CountryAuthorized(Country::FRANCE)
);
});
@ -69,7 +70,6 @@ describe('reject campaign request use case', function (): void {
$id,
new BrandCode('AAA01'),
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
new CountryAuthorized(Country::FRANCE),
CampaignRequestType::CLUB,
new PrintRules(maxPerCustomer: 3),
$this->requestedCoupon,
@ -122,7 +122,6 @@ describe('reject campaign request use case', function (): void {
$id,
new BrandCode('AAA01'),
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
new CountryAuthorized(Country::FRANCE),
CampaignRequestType::CLUB,
new PrintRules(maxPerCustomer: 3),
$this->requestedCoupon,

View file

@ -53,6 +53,7 @@ describe('campaign request', function (): void {
new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg')),
new GS1('01234567890128', BarcodeFormat::EAN13),
new CouponValidity(30, new DateTime()),
new CountryAuthorized(Country::FRANCE)
);
});
@ -61,7 +62,6 @@ describe('campaign request', function (): void {
$id = CampaignRequestId::generate();
$code = new BrandCode('AAA01');
$applicant = new Applicant('John', 'Doe', new Email('john.doe@example.com'));
$country = new CountryAuthorized(Country::FRANCE);
$campaignType = CampaignRequestType::CLUB;
$printRules = new PrintRules(maxPerCustomer: 3);
$requestedCoupon = $this->requestedCoupon;
@ -72,7 +72,6 @@ describe('campaign request', function (): void {
$id,
$code,
$applicant,
$country,
$campaignType,
$printRules,
$requestedCoupon,
@ -83,7 +82,6 @@ describe('campaign request', function (): void {
expect($campaignRequest->id())->toBe($id)
->and($campaignRequest->code)->toBe($code)
->and($campaignRequest->applicant)->toBe($applicant)
->and($campaignRequest->country)->toBe($country)
->and($campaignRequest->campaignType)->toBe($campaignType)
->and($campaignRequest->printRules)->toBe($printRules)
->and($campaignRequest->requestedCoupon)->toBe($requestedCoupon)
@ -98,7 +96,6 @@ describe('campaign request', function (): void {
CampaignRequestId::generate(),
new BrandCode('AAA01'),
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
new CountryAuthorized(Country::FRANCE),
CampaignRequestType::CLUB,
null,
$this->requestedCoupon,
@ -118,7 +115,6 @@ describe('campaign request', function (): void {
CampaignRequestId::generate(),
new BrandCode('AAA01'),
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
new CountryAuthorized(Country::FRANCE),
CampaignRequestType::CLUB,
new PrintRules(maxPerCustomer: 3),
$this->requestedCoupon,
@ -141,7 +137,6 @@ describe('campaign request', function (): void {
CampaignRequestId::generate(),
new BrandCode('AAA01'),
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
new CountryAuthorized(Country::FRANCE),
CampaignRequestType::CLUB,
new PrintRules(maxPerCustomer: 3),
$this->requestedCoupon,
@ -160,7 +155,6 @@ describe('campaign request', function (): void {
CampaignRequestId::generate(),
new BrandCode('AAA01'),
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
new CountryAuthorized(Country::FRANCE),
CampaignRequestType::CLUB,
new PrintRules(maxPerCustomer: 3),
$this->requestedCoupon,
@ -180,7 +174,6 @@ describe('campaign request', function (): void {
CampaignRequestId::generate(),
new BrandCode('AAA01'),
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
new CountryAuthorized(Country::FRANCE),
CampaignRequestType::CLUB,
new PrintRules(maxPerCustomer: 3),
$this->requestedCoupon,
@ -202,7 +195,6 @@ describe('campaign request', function (): void {
CampaignRequestId::generate(),
new BrandCode('AAA01'),
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
new CountryAuthorized(Country::FRANCE),
CampaignRequestType::CLUB,
new PrintRules(maxPerCustomer: 3),
$this->requestedCoupon,
@ -219,7 +211,6 @@ describe('campaign request', function (): void {
->and($rejected->id())->toBe($campaignRequest->id())
->and($rejected->code)->toBe($campaignRequest->code)
->and($rejected->applicant)->toBe($campaignRequest->applicant)
->and($rejected->country)->toBe($campaignRequest->country)
->and($rejected->campaignType)->toBe($campaignRequest->campaignType)
->and($rejected->printRules)->toBe($campaignRequest->printRules)
->and($rejected->requestedCoupon)->toBe($campaignRequest->requestedCoupon)
@ -233,7 +224,6 @@ describe('campaign request', function (): void {
CampaignRequestId::generate(),
new BrandCode('AAA01'),
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
new CountryAuthorized(Country::FRANCE),
CampaignRequestType::CLUB,
new PrintRules(maxPerCustomer: 3),
$this->requestedCoupon,
@ -253,7 +243,6 @@ describe('campaign request', function (): void {
CampaignRequestId::generate(),
new BrandCode('AAA01'),
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
new CountryAuthorized(Country::FRANCE),
CampaignRequestType::CLUB,
new PrintRules(maxPerCustomer: 3),
$this->requestedCoupon,
@ -276,7 +265,6 @@ describe('campaign request', function (): void {
$id,
new BrandCode('AAA01'),
new Applicant('John', 'Doe', new Email('john.doe@example.com')),
new CountryAuthorized(Country::FRANCE),
CampaignRequestType::CLUB,
new PrintRules(maxPerCustomer: 3),
$this->requestedCoupon,

View file

@ -19,7 +19,9 @@ use Domain\Models\ValueObjects\RequestedCoupon\RequestedCouponQuantity;
use Domain\Models\ValueObjects\WarningThresholdQuantity;
use Shared\Enums\Currency;
use DateTime;
use Domain\Models\ValueObjects\CountryAuthorized;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCoupon;
use Shared\Enums\Country;
use Shared\ValueObjects\Money;
covers(RequestedCoupon::class);
@ -41,7 +43,7 @@ describe('requested coupon', function (): void {
$couponPicture = new CouponPicture(new PicturePath('coupons/product.jpg'), new PicturePath('coupons/thumbnail.jpg'));
$gs1 = new GS1('01234567890128', BarcodeFormat::EAN13);
$couponValidity = new CouponValidity(30, new DateTime());
$country = new CountryAuthorized(Country::FRANCE);
// WHEN
$coupon = new RequestedCoupon(
$name,
@ -54,6 +56,7 @@ describe('requested coupon', function (): void {
$couponPicture,
$gs1,
$couponValidity,
$country
);
// THEN
@ -66,6 +69,7 @@ describe('requested coupon', function (): void {
->and($coupon->processingCode)->toBe($processingCode)
->and($coupon->couponPicture)->toBe($couponPicture)
->and($coupon->gs1)->toBe($gs1)
->and($coupon->couponValidity)->toBe($couponValidity);
->and($coupon->couponValidity)->toBe($couponValidity)
->and($coupon->country)->toBe($country);
});
});