diff --git a/src/Application/UseCases/Campaign/Create/CreateCampaign.php b/src/Application/UseCases/Campaign/Create/CreateCampaign.php index 9dba30d..fd7525a 100644 --- a/src/Application/UseCases/Campaign/Create/CreateCampaign.php +++ b/src/Application/UseCases/Campaign/Create/CreateCampaign.php @@ -34,7 +34,6 @@ final readonly class CreateCampaign implements UseCase, Transactional $campaign = Campaign::create( name: $input->name, - publication: false, printAllAtOnce: $input->printAllAtOnce, coupons: $input->coupons, brandCode: $input->brandCode, diff --git a/src/Domain/Models/Entities/Campaign.php b/src/Domain/Models/Entities/Campaign.php index a6aa498..bab9f0c 100644 --- a/src/Domain/Models/Entities/Campaign.php +++ b/src/Domain/Models/Entities/Campaign.php @@ -49,7 +49,6 @@ final readonly class Campaign implements AggregateRoot, HasTimestampIdentifier public static function create( CampaignName $name, - bool $publication, bool $printAllAtOnce, CampaignCouponArray $coupons, BrandCode $brandCode, @@ -59,7 +58,7 @@ final readonly class Campaign implements AggregateRoot, HasTimestampIdentifier id: CampaignId::generate(), code: CampaignCode::generate(), name: $name, - publication: $publication, + publication: false, printAllAtOnce: $printAllAtOnce, coupons: $coupons, brandCode: $brandCode, diff --git a/tests/Unit/Application/UseCases/Coupon/Find/FindCouponTest.php b/tests/Unit/Application/UseCases/Coupon/Find/FindCouponTest.php index 5dcf5ee..a645884 100644 --- a/tests/Unit/Application/UseCases/Coupon/Find/FindCouponTest.php +++ b/tests/Unit/Application/UseCases/Coupon/Find/FindCouponTest.php @@ -97,7 +97,6 @@ describe('find coupon use case', function (): void { ); $campaign = Campaign::create( name: new CampaignName('Campaign name'), - publication: true, printAllAtOnce: true, coupons: new CampaignCouponArray([ new CampaignCoupon($coupon->code), diff --git a/tests/Unit/Application/UseCases/PrintableCoupon/Create/CreatePrintableCouponTest.php b/tests/Unit/Application/UseCases/PrintableCoupon/Create/CreatePrintableCouponTest.php index eee8871..16e5f07 100644 --- a/tests/Unit/Application/UseCases/PrintableCoupon/Create/CreatePrintableCouponTest.php +++ b/tests/Unit/Application/UseCases/PrintableCoupon/Create/CreatePrintableCouponTest.php @@ -20,6 +20,7 @@ use Domain\Models\ValueObjects\Brand\BrandCode; use Domain\Models\ValueObjects\Campaign\CampaignCode; use Domain\Models\ValueObjects\Campaign\CampaignCoupon; use Domain\Models\ValueObjects\Campaign\CampaignCouponArray; +use Domain\Models\ValueObjects\Campaign\CampaignId; use Domain\Models\ValueObjects\Campaign\CampaignName; use Domain\Models\ValueObjects\Coupon\CouponAvailabilityCalendar; use Domain\Models\ValueObjects\Coupon\CouponCode; @@ -114,7 +115,9 @@ describe('create coupon use case', function (): void { $couponCode, $printRules($maxPerCustomer, $cooldownDays), ); - $makeCampaign = fn (?int $maxPerCustomer = null, ?int $cooldownDays = null, bool $published = true): Campaign => Campaign::create( + $makeCampaign = fn (?int $maxPerCustomer = null, ?int $cooldownDays = null, $published = true): Campaign => Campaign::hydrate( + id: CampaignId::generate(), + code: $campaignCode, name: new CampaignName('Campaign name'), publication: $published, printAllAtOnce: true, diff --git a/tests/Unit/Domain/Models/Entities/CampaignTest.php b/tests/Unit/Domain/Models/Entities/CampaignTest.php index 7fd70c6..4735381 100644 --- a/tests/Unit/Domain/Models/Entities/CampaignTest.php +++ b/tests/Unit/Domain/Models/Entities/CampaignTest.php @@ -16,14 +16,11 @@ use Domain\Models\ValueObjects\Campaign\CampaignId; use Domain\Models\ValueObjects\Campaign\CampaignName; use Domain\Models\ValueObjects\Coupon\CouponCode; use Domain\Models\ValueObjects\PrintRules; -use Ramsey\Uuid\Uuid; covers(Campaign::class); describe('campaign', function (): void { - $code = CampaignCode::generate(); $name = new CampaignName('Name'); - $publication = \boolval(0); $printAllAtOnce = \boolval(1); $coupons = new CampaignCouponArray([ new CampaignCoupon( @@ -38,55 +35,22 @@ describe('campaign', function (): void { CarbonImmutable::setTestNow(); }); - it('creates a campaign', function () use ( - $code, - $name, - $publication, - $printAllAtOnce, - $coupons, - $brandCode, - $actorId, - ): void { + it('creates a campaign', function (): void { // GIVEN - $id = CampaignId::generate(); + $name = new CampaignName('Name'); + $coupons = new CampaignCouponArray([ + new CampaignCoupon( + new CouponCode('AAA01'), + new PrintRules(maxPerCustomer: 3) + ) + ]); + $brandCode = new BrandCode('AAA01'); + $actorId = ActorId::generate(); // WHEN - $campaign = Campaign::hydrate( - $id, - $code, - $name, - $publication, - $printAllAtOnce, - $coupons, - $brandCode, - $actorId - ); - - // THEN - expect($campaign->id())->toBe($id) - ->and($campaign->code)->toBe($code) - ->and($campaign->name)->toBe($name) - ->and($campaign->publication)->toBe($publication) - ->and($campaign->printAllAtOnce)->toBe($printAllAtOnce) - ->and($campaign->coupons)->toBe($coupons) - ->and($campaign->brandCode)->toBe($brandCode) - ->and($campaign->createdAt())->toBeInstanceOf(DateTimeInterface::class) - ->and($campaign->updatedAt())->toBeInstanceOf(DateTimeInterface::class); - }); - - it('creates a new campaign with a freshly generated id', function () use ( - $name, - $publication, - $printAllAtOnce, - $coupons, - $brandCode, - $actorId, - ): void { - // GIVEN / WHEN $campaign = Campaign::create( $name, - $publication, - $printAllAtOnce, + true, $coupons, $brandCode, $actorId @@ -96,17 +60,17 @@ describe('campaign', function (): void { expect($campaign->id())->toBeInstanceOf(CampaignId::class) ->and($campaign->code)->toBeInstanceOf(CampaignCode::class) ->and($campaign->name)->toBe($name) - ->and($campaign->publication)->toBe($publication) - ->and($campaign->printAllAtOnce)->toBe($printAllAtOnce) + ->and($campaign->publication)->toBeFalse() + ->and($campaign->printAllAtOnce)->toBeTrue() ->and($campaign->coupons)->toBe($coupons) ->and($campaign->brandCode)->toBe($brandCode) + ->and($campaign->actorId)->toBe($actorId) ->and($campaign->createdAt())->toBeInstanceOf(DateTimeInterface::class) ->and($campaign->updatedAt())->toBeNull(); }); it('generates a different id for each created campaign', function () use ( $name, - $publication, $printAllAtOnce, $coupons, $brandCode, @@ -115,7 +79,6 @@ describe('campaign', function (): void { // GIVEN / WHEN $firstCampaign = Campaign::create( $name, - $publication, $printAllAtOnce, $coupons, $brandCode, @@ -123,7 +86,6 @@ describe('campaign', function (): void { ); $secondCampaign = Campaign::create( $name, - $publication, $printAllAtOnce, $coupons, $brandCode, @@ -135,22 +97,17 @@ describe('campaign', function (): void { }); it('returns the creation date extracted from the id', function () use ( - $code, $name, - $publication, $printAllAtOnce, $coupons, $brandCode, $actorId, ): void { // GIVEN - $expected = new \DateTimeImmutable('2024-06-15 12:34:56.789000', new \DateTimeZone('UTC')); - $id = new CampaignId(Uuid::uuid7($expected)); - $campaign = Campaign::hydrate( - $id, - $code, + $expected = new \DateTimeImmutable('now', new \DateTimeZone('UTC')); + + $campaign = Campaign::create( $name, - $publication, $printAllAtOnce, $coupons, $brandCode, @@ -163,21 +120,4 @@ describe('campaign', function (): void { // THEN expect($result->format('Y-m-d H:i:s.v'))->toBe($expected->format('Y-m-d H:i:s.v')); }); - - it('rejects a campaign with a non-coupon element', function () use ($code, $name, $publication, $printAllAtOnce, $brandCode, $actorId): void { - // GIVEN - $id = CampaignId::generate(); - - // WHEN / THEN - expect(fn (): Campaign => Campaign::hydrate( - $id, - $code, - $name, - $publication, - $printAllAtOnce, - new CampaignCouponArray(['PC1']), - $brandCode, - $actorId - ))->toThrow(\DomainException::class, 'Coupons must be CampaignCoupon instances.'); - }); });