def test_delete_drink_review_fail( drink_repository_mock, drink_id, drink_name, drink_image_url, drink_type, ): drink_repository_mock.find_by_drink_id.side_effect = ResourceNotFoundError( ) drink_repository_mock.update.return_value = None drink_application_service = DrinkApplicationService( drink_repository=drink_repository_mock) input_dto = DeleteDrinkReviewInputDto(drink_id=str(drink_id), drink_rating=5) actual = drink_application_service.delete_drink_review(input_dto) expected = FailedOutputDto(type="Resource Not Found Error", message="") assert actual == expected drink_repository_mock.find_by_drink_id.return_value = None drink_repository_mock.update.side_effect = ResourceNotFoundError() drink_application_service = DrinkApplicationService( drink_repository=drink_repository_mock) input_dto = DeleteDrinkReviewInputDto(drink_id=str(drink_id), drink_rating=5) actual = drink_application_service.delete_drink_review(input_dto) expected = FailedOutputDto(type="Resource Not Found Error", message="") assert actual == expected
def delete_review( self, input_dto: DeleteReviewInputDto, drink_application_service: DrinkApplicationService, ) -> Union[DeleteReviewOutputDto, FailedOutputDto]: try: review_id = ReviewId.from_str(input_dto.review_id) review = self._review_repository.find_by_review_id(review_id) if review is None: return FailedOutputDto.build_resource_not_found_error( f"{str(input_dto.review_id)}의 리뷰를 찾을 수 없습니다.") self._review_repository.delete_by_review_id(review_id) drinks_input_dto = DeleteDrinkReviewInputDto( drink_id=str(review.drink_id), drink_rating=int(review.rating)) drink_delete_review_output_dto = drink_application_service.delete_drink_review( input_dto=drinks_input_dto) if not drink_delete_review_output_dto.status: return drink_delete_review_output_dto return DeleteReviewOutputDto() except ResourceNotFoundError as e: return FailedOutputDto.build_resource_not_found_error( message=str(e)) except Exception as e: return FailedOutputDto.build_system_error(message=str(e))
def test_delete_drink_review_success( drink_repository_mock, drink_id, drink_name, drink_image_url, drink_type, ): drink_repository_mock.find_by_drink_id.return_value = Drink( id=drink_id, name=drink_name, image_url=drink_image_url, type=drink_type) drink_repository_mock.update.return_value = None drink_application_service = DrinkApplicationService( drink_repository=drink_repository_mock) input_dto = DeleteDrinkReviewInputDto(drink_id=str(drink_id), drink_rating=5) actual = drink_application_service.delete_drink_review(input_dto) expected = DeleteDrinkReviewOutputDto() assert actual == expected