fix: 🐛 restrict processing code to 13 digits

This commit is contained in:
Corentin Huet 2026-10-13 15:56:11 +02:00
parent 5a3815579d
commit e4a0ad5b73
11 changed files with 25 additions and 35 deletions

View file

@ -9,7 +9,7 @@ use Shared\Enums\Country;
final readonly class CouponProcessingCode implements \Stringable, Equatable
{
private const string PATTERN = '/^[A-Za-z0-9]{13}\z/';
private const string PATTERN = '/^\d{13}\z/';
public function __construct(
public string $value,
@ -17,7 +17,7 @@ final readonly class CouponProcessingCode implements \Stringable, Equatable
) {
if (preg_match(self::PATTERN, $this->value) !== 1) {
throw new \DomainException(
'Processing Code must be exactly 13 alphanumeric characters, e.g. ABC1234567890.',
'Processing Code must be exactly 13 numeric characters, e.g. 5425003944130.',
);
}
}

View file

@ -56,7 +56,7 @@ describe('create campaign request use case', function (): void {
new PicturePath('files/mobileThumbnail.jpg')
),
couponProcessingCodes: new CouponProcessingCodeArray([
new CouponProcessingCode('ABC1234567890', Country::FRANCE),
new CouponProcessingCode('5425003944130', Country::FRANCE),
]),
couponValidityInformations: new CouponValidityInformationArray([
new CouponValidityInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::FRANCE),

View file

@ -60,7 +60,7 @@ describe('find campaign request use case', function (): void {
new PicturePath('files/mobileThumbnail.jpg')
),
couponProcessingCodes: new CouponProcessingCodeArray([
new CouponProcessingCode('ABC1234567890', Country::FRANCE),
new CouponProcessingCode('5425003944130', Country::FRANCE),
]),
couponValidityInformations: new CouponValidityInformationArray([
new CouponValidityInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::FRANCE),

View file

@ -54,7 +54,7 @@ describe('list campaigns request use case', function (): void {
new PicturePath('files/mobileThumbnail.jpg')
),
couponProcessingCodes: new CouponProcessingCodeArray([
new CouponProcessingCode('ABC1234567890', Country::FRANCE),
new CouponProcessingCode('5425003944130', Country::FRANCE),
]),
couponValidityInformations: new CouponValidityInformationArray([
new CouponValidityInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::FRANCE),
@ -79,7 +79,7 @@ describe('list campaigns request use case', function (): void {
new PicturePath('files/mobileThumbnail.jpg')
),
couponProcessingCodes: new CouponProcessingCodeArray([
new CouponProcessingCode('ABC1234567890', Country::FRANCE),
new CouponProcessingCode('5425003944130', Country::FRANCE),
]),
couponValidityInformations: new CouponValidityInformationArray([
new CouponValidityInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::FRANCE),

View file

@ -55,7 +55,7 @@ describe('reject campaign request use case', function (): void {
new PicturePath('files/mobileThumbnail.jpg')
),
couponProcessingCodes: new CouponProcessingCodeArray([
new CouponProcessingCode('ABC1234567890', Country::FRANCE),
new CouponProcessingCode('5425003944130', Country::FRANCE),
]),
couponValidityInformations: new CouponValidityInformationArray([
new CouponValidityInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::FRANCE),

View file

@ -50,7 +50,7 @@ describe('campaign request', function (): void {
new PicturePath('files/mobileThumbnail.jpg')
),
couponProcessingCodes: new CouponProcessingCodeArray([
new CouponProcessingCode('ABC1234567890', Country::FRANCE),
new CouponProcessingCode('5425003944130', Country::FRANCE),
]),
couponValidityInformations: new CouponValidityInformationArray([
new CouponValidityInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::FRANCE),

View file

@ -16,8 +16,8 @@ use Shared\Enums\Country;
covers(CouponCountryCoverage::class);
describe('coupon country coverage', function (): void {
$franceCode = new CouponProcessingCode('ABC1234567890', Country::FRANCE);
$beneluxCode = new CouponProcessingCode('XYZ0987654321', Country::BENELUX);
$franceCode = new CouponProcessingCode('5425003944130', Country::FRANCE);
$beneluxCode = new CouponProcessingCode('5425003944147', Country::BENELUX);
$franceValidity = new CouponValidityInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::FRANCE);
$beneluxValidity = new CouponValidityInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::BENELUX);
$franceLegal = new CouponLegalInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::FRANCE);

View file

@ -10,7 +10,7 @@ use Shared\Enums\Country;
covers(CouponProcessingCode::class);
describe('processing code', function (): void {
$value = 'ABC1234567890';
$value = '5425003944130';
$emptyValue = '';
it('creates a valid processing code FRANCE', function () use ($value): void {

View file

@ -11,8 +11,8 @@ use Shared\Enums\Country;
covers(CouponProcessingCodeArray::class);
describe('coupon processing code array', function (): void {
$franceCode = new CouponProcessingCode('ABC1234567890', Country::FRANCE);
$beneluxCode = new CouponProcessingCode('XYZ0987654321', Country::BENELUX);
$franceCode = new CouponProcessingCode('5425003944130', Country::FRANCE);
$beneluxCode = new CouponProcessingCode('5425003944147', Country::BENELUX);
it('creates an array containing a France processing code', function () use ($franceCode): void {
// GIVEN
@ -52,7 +52,7 @@ describe('coupon processing code array', function (): void {
// GIVEN
$informations = [
$franceCode,
new CouponProcessingCode('XYZ0987654321', Country::FRANCE),
new CouponProcessingCode('5425003944130', Country::FRANCE),
];
// WHEN

View file

@ -10,7 +10,7 @@ use Shared\Enums\Country;
covers(CouponProcessingCode::class);
describe('coupon processing code', function (): void {
$value = 'ABC1234567890';
$value = '5425003944130';
it('creates a valid processing code', function () use ($value): void {
// GIVEN / WHEN
@ -21,30 +21,20 @@ describe('coupon processing code', function (): void {
->and($code->availableIn)->toBe(Country::FRANCE);
});
it('accepts lowercase and uppercase letters and digits', function (): void {
// GIVEN / WHEN
$code = new CouponProcessingCode('aBc1234567xYz', Country::FRANCE);
// THEN
expect($code->value)->toBe('aBc1234567xYz');
});
it('rejects an invalid value', function (string $invalidValue): void {
// GIVEN / WHEN
$action = fn (): CouponProcessingCode => new CouponProcessingCode($invalidValue, Country::FRANCE);
// THEN
expect($action)->toThrow(
\DomainException::class,
'Processing Code must be exactly 13 alphanumeric characters, e.g. ABC1234567890.',
);
expect($action)->toThrow(\DomainException::class, 'Processing Code must be exactly 13 numeric characters');
})->with([
'empty' => '',
'too short' => 'ABC123456789',
'too long' => 'ABC12345678901',
'special char' => 'ABC123456789!',
'with space' => 'ABC 123456789',
'trailing break' => "ABC1234567890\n",
'too short' => '542500394413',
'too long' => '54250039441301',
'with letters' => 'ABC1234567890',
'special char' => '542500394413!',
'with space' => '5425 03944130',
'trailing break' => "5425003944130\n",
]);
it('is equal to another processing code with the same value', function () use ($value): void {
@ -68,7 +58,7 @@ describe('coupon processing code', function (): void {
it('is not equal to a processing code with a different value', function () use ($value): void {
// GIVEN
$code = new CouponProcessingCode($value, Country::FRANCE);
$other = new CouponProcessingCode('XYZ0987654321', Country::FRANCE);
$other = new CouponProcessingCode('4006381333931', Country::FRANCE);
// WHEN / THEN
expect($code->equals($other))->toBeFalse();

View file

@ -38,8 +38,8 @@ describe('requested coupon', function (): void {
new PicturePath('files/mobileThumbnail.jpg')
);
$franceProcessingCode = new CouponProcessingCode('ABC1234567890', Country::FRANCE);
$beneluxProcessingCode = new CouponProcessingCode('XYZ9876543210', Country::BENELUX);
$franceProcessingCode = new CouponProcessingCode('5425003944130', Country::FRANCE);
$beneluxProcessingCode = new CouponProcessingCode('5425003944147', Country::BENELUX);
$couponProcessingCodes = new CouponProcessingCodeArray([
$franceProcessingCode,
$beneluxProcessingCode,