static), out of scope for now. // // it('finds a campaign request by its id, along with its brand', function (): void { // // GIVEN // $id = CampaignRequestId::generate(); // $code = new BrandCode('AAA01'); // $campaignRequest = CampaignRequest::hydrate( // $id, // $code, // new Applicant('John', 'Doe', new Email('john.doe@example.com')), // Country::FR, // CampaignType::CLUB, // new PrintRules(maxPerCustomer: 3), // aFindableRequestedCoupon(), // CampaignStatus::CREATED, // ); // $brand = aFindableBrand($code); // // $repository = \Mockery::mock(CampaignRequestRepository::class); // $repository->shouldReceive('findById')->once()->with($id)->andReturn($campaignRequest); // // $brandRepository = \Mockery::mock(BrandRepository::class); // $brandRepository->shouldReceive('findByCode')->once()->with($code)->andReturn($brand); // // $useCase = new FindCampaignRequest($repository, $brandRepository); // // // WHEN // $result = $useCase->execute(new Input(id: $id)); // // // THEN // 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) // ->and($result->status)->toBe($campaignRequest->status) // ->and($result->rejectionReason)->toBeNull(); // }); // // it('finds a rejected campaign request with its rejection reason', function (): void { // // GIVEN // $id = CampaignRequestId::generate(); // $code = new BrandCode('AAA01'); // $rejectionReason = new RejectionReason('Missing legal documents.'); // $campaignRequest = CampaignRequest::hydrate( // $id, // $code, // new Applicant('John', 'Doe', new Email('john.doe@example.com')), // Country::FR, // CampaignType::CLUB, // new PrintRules(maxPerCustomer: 3), // aFindableRequestedCoupon(), // CampaignStatus::REJECTED, // $rejectionReason, // ); // // $repository = \Mockery::mock(CampaignRequestRepository::class); // $repository->shouldReceive('findById')->once()->with($id)->andReturn($campaignRequest); // // $brandRepository = \Mockery::mock(BrandRepository::class); // $brandRepository->shouldReceive('findByCode')->once()->with($code)->andReturn(aFindableBrand($code)); // // $useCase = new FindCampaignRequest($repository, $brandRepository); // // // WHEN // $result = $useCase->execute(new Input(id: $id)); // // // THEN // expect($result)->toBeInstanceOf(CampaignRequestFound::class) // ->and($result->status)->toBe(CampaignStatus::REJECTED) // ->and($result->rejectionReason)->toBe($rejectionReason); // }); it('returns CampaignRequestNotFound when the id is not found', function (): void { // GIVEN $id = CampaignRequestId::generate(); $repository = \Mockery::mock(CampaignRequestRepository::class); $repository->shouldReceive('findById')->once()->with($id)->andReturn(null); $brandRepository = \Mockery::mock(BrandRepository::class); $brandRepository->shouldNotReceive('findByCode'); $useCase = new FindCampaignRequest($repository, $brandRepository); // WHEN $result = $useCase->execute(new Input(id: $id)); // THEN expect($result)->toBeInstanceOf(CampaignRequestNotFound::class); }); it('throws when the campaign request references a brand that no longer exists', function (): void { // GIVEN $id = CampaignRequestId::generate(); $code = new BrandCode('AAA01'); $campaignRequest = CampaignRequest::hydrate( $id, $code, new Applicant('John', 'Doe', new Email('john.doe@example.com')), Country::FR, CampaignType::CLUB, new PrintRules(maxPerCustomer: 3), aFindableRequestedCoupon(), CampaignStatus::CREATED, ); $repository = \Mockery::mock(CampaignRequestRepository::class); $repository->shouldReceive('findById')->once()->with($id)->andReturn($campaignRequest); $brandRepository = \Mockery::mock(BrandRepository::class); $brandRepository->shouldReceive('findByCode')->once()->with($code)->andReturn(null); $useCase = new FindCampaignRequest($repository, $brandRepository); // WHEN $action = fn (): Output => $useCase->execute(new Input(id: $id)); // THEN expect($action)->toThrow(BrandNotFoundException::class); }); }); describe('find campaign request use case assertions', function (): void { it('rejects a wrong type input', function (): void { // GIVEN $repository = \Mockery::mock(CampaignRequestRepository::class); $brandRepository = \Mockery::mock(BrandRepository::class); $useCase = new FindCampaignRequest($repository, $brandRepository); $invalidInput = new class () implements BaseInput { }; // WHEN $action = fn (): Output => $useCase->execute($invalidInput); // THEN expect($action)->toThrow(\InvalidArgumentException::class); }); });