diff --git a/README.md b/README.md index 6258b17..169074a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # TODO - - If bid == closed, do not show bid to carriers on future requests - Make UpdateBid use case - Make GetBidsOfFreightOrder use case - Dashboard: diff --git a/src/Bid/UseCases/GetBidForCarrier.php b/src/Bid/UseCases/GetBidForCarrier.php index 3537556..1b1a673 100644 --- a/src/Bid/UseCases/GetBidForCarrier.php +++ b/src/Bid/UseCases/GetBidForCarrier.php @@ -15,12 +15,15 @@ class GetBidForCarrier /** * @throws InvalidArgumentException */ - public function execute(GetBidForCarrierRequest $dto): Bid + public function execute(GetBidForCarrierRequest $dto): ?Bid { $bid = $this->bidRepo->find($dto->id); if ($bid === null) { throw new InvalidArgumentException('Bid not found!'); } + if ($bid->isClosed() === true) { + return null; + } if ($bid->getWasOpened() === false) { $bid->setWasOpened(true); $this->bidRepo->save($bid); diff --git a/tests/Unit/Bid/UseCases/GetBidForCarrierTest.php b/tests/Unit/Bid/UseCases/GetBidForCarrierTest.php index 6fce3ae..c15404b 100644 --- a/tests/Unit/Bid/UseCases/GetBidForCarrierTest.php +++ b/tests/Unit/Bid/UseCases/GetBidForCarrierTest.php @@ -25,7 +25,7 @@ class GetBidForCarrierTest extends TestCase $this->expectException(InvalidArgumentException::class); $bidId = '12345abcd'; $dto = new GetBidForCarrierRequest($bidId); - $foundBid = $this->useCase->execute($dto); + $this->useCase->execute($dto); } public function test_first_view_flips_opened_flag(): void @@ -46,4 +46,21 @@ class GetBidForCarrierTest extends TestCase ); $this->assertEquals(true, $foundBid->getWasOpened()); } + + public function test_getting_closed_bid_returns_null(): void + { + $this->bidRepo->save(new Bid( + 0, + 0, + 0, + false, + true, + null, + null, + null, + )); + $this->assertNull($this->useCase->execute( + new GetBidForCarrierRequest(0), + )); + } }