def test_add_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 = AddDrinkReviewInputDto(drink_id=str(drink_id), drink_rating=5)

    actual = drink_application_service.add_drink_review(input_dto)
    expected = FailedOutputDto(type="Resource Not Found Error", message="")
    assert actual == expected

    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 = ResourceNotFoundError()
    drink_application_service = DrinkApplicationService(
        drink_repository=drink_repository_mock)

    input_dto = AddDrinkReviewInputDto(drink_id=str(drink_id), drink_rating=5)

    actual = drink_application_service.add_drink_review(input_dto)
    expected = FailedOutputDto(type="Resource Not Found Error", message="")
    assert actual == expected
def test_add_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 = AddDrinkReviewInputDto(drink_id=str(drink_id), drink_rating=5)

    actual = drink_application_service.add_drink_review(input_dto)
    expected = AddDrinkReviewOutputDto()
    assert actual == expected
    def create_review(
        self,
        input_dto: CreateReviewInputDto,
        drink_application_service: DrinkApplicationService,
    ) -> Union[CreateReviewOutputDto, FailedOutputDto]:
        try:
            review = Review(
                id=ReviewId.build(user_id=input_dto.user_id,
                                  drink_id=input_dto.drink_id),
                drink_id=DrinkId(value=input_dto.drink_id),
                user_id=UserId(value=input_dto.user_id),
                rating=ReviewRating(value=input_dto.rating),
                comment=input_dto.comment,
                created_at=time.time(),
                updated_at=time.time(),
            )
            self._review_repository.add(review)
            input_dto = AddDrinkReviewInputDto(drink_id=input_dto.drink_id,
                                               drink_rating=input_dto.rating)
            drink_add_review_output_dto = drink_application_service.add_drink_review(
                input_dto=input_dto)

            if not drink_add_review_output_dto.status:
                return drink_add_review_output_dto
            return CreateReviewOutputDto(
                review_id=str(review.id),
                drink_id=str(review.drink_id),
                user_id=str(review.user_id),
                rating=int(review.rating),
                comment=review.comment,
                created_at=review.created_at,
                updated_at=review.updated_at,
            )
        except ResourceAlreadyExistError as e:
            return FailedOutputDto.build_resource_conflict_error(
                message=str(e))
        except Exception as e:
            return FailedOutputDto.build_system_error(message=str(e))