def test_delete_review_fail(
    review_repository_mock,
    drink_application_service_mock,
    review_id,
    drink_id,
    user_id,
    rating,
    created_at,
):
    review_repository_mock.find_by_review_id.return_value = Review(
        id=review_id,
        drink_id=drink_id,
        user_id=UserId(value=user_id),
        rating=ReviewRating(value=rating),
        comment="hello",
        created_at=created_at,
        updated_at=created_at,
    )
    review_repository_mock.delete_by_review_id.side_effect = ResourceNotFoundError(
    )
    review_application_service = ReviewApplicationService(
        review_repository=review_repository_mock)

    drink_application_service_mock.delete_drink_review.return_value = DeleteDrinkReviewOutputDto(
    )

    input_dto = DeleteReviewInputDto(review_id=str(review_id))
    actual = review_application_service.delete_review(
        input_dto, drink_application_service_mock)
    expected = FailedOutputDto(type="Resource Not Found Error", message="")
    assert actual == expected
def test_find_review_success(
    review_repository_mock,
    review_id,
    drink_id,
    user_id,
    rating,
    created_at,
):
    review_repository_mock.find_by_review_id.return_value = Review(
        id=review_id,
        drink_id=drink_id,
        user_id=UserId(value=user_id),
        rating=ReviewRating(value=rating),
        comment="hello",
        created_at=created_at,
        updated_at=created_at,
    )
    review_application_service = ReviewApplicationService(
        review_repository=review_repository_mock)

    input_dto = FindReviewInputDto(review_id=str(review_id))

    actual = review_application_service.find_review(input_dto)
    expected = FindReviewOutputDto(
        review_id=str(review_id),
        drink_id=str(drink_id),
        user_id=str(UserId(value=user_id)),
        rating=int(ReviewRating(value=rating)),
        comment="hello",
        created_at=created_at,
        updated_at=created_at,
    )
    assert actual == expected
def test_create_review_fail(
    review_repository_mock,
    drink_application_service_mock,
    review_id,
    drink_id,
    user_id,
    rating,
    created_at,
):
    review_repository_mock.add.side_effect = ResourceAlreadyExistError()
    review_application_service = ReviewApplicationService(
        review_repository=review_repository_mock)

    drink_application_service_mock.add_drink_review.return_value = AddDrinkReviewOutputDto(
    )

    input_dto = CreateReviewInputDto(
        drink_id=str(drink_id),
        user_id=str(UserId(value=user_id)),
        rating=int(ReviewRating(value=rating)),
        comment="",
    )

    actual = review_application_service.create_review(
        input_dto, drink_application_service_mock)
    expected = FailedOutputDto(type="Resource Conflict Error", message="")
    assert actual == expected
def test_delete_review_success(
    review_repository_mock,
    drink_application_service_mock,
    review_id,
    drink_id,
    user_id,
    rating,
    created_at,
):
    review_repository_mock.find_by_review_id.return_value = Review(
        id=review_id,
        drink_id=drink_id,
        user_id=UserId(value=user_id),
        rating=ReviewRating(value=rating),
        comment="hello",
        created_at=created_at,
        updated_at=created_at,
    )
    review_repository_mock.delete_by_review_id.return_value = None
    review_application_service = ReviewApplicationService(
        review_repository=review_repository_mock)

    drink_application_service_mock.delete_drink_review.return_value = DeleteDrinkReviewOutputDto(
    )

    input_dto = DeleteReviewInputDto(review_id=str(review_id))

    actual = review_application_service.delete_review(
        input_dto, drink_application_service_mock)
    expected = DeleteReviewOutputDto()
    assert actual == expected
def test_find_reviews_success(
    review_repository_mock,
    review_id,
    drink_id,
    user_id,
    rating,
    created_at,
):
    drink_id_2 = "335ca1a4-5175-5e41-8bac-40ffd840835c"
    user_id_2 = "meme"
    review_id_2 = ReviewId.build(user_id=user_id_2, drink_id=drink_id_2)

    review_repository_mock.find_all.return_value = [
        Review(
            id=review_id,
            drink_id=drink_id,
            user_id=UserId(value=user_id),
            rating=ReviewRating(value=rating),
            comment="hello",
            created_at=created_at,
            updated_at=created_at,
        ),
        Review(
            id=review_id_2,
            drink_id=DrinkId.from_str(drink_id_2),
            user_id=UserId(value=user_id_2),
            rating=ReviewRating(value=rating),
            comment="olleh",
            created_at=created_at,
            updated_at=created_at,
        ),
    ]
    review_application_service = ReviewApplicationService(
        review_repository=review_repository_mock)

    input_dto = FindReviewsInputDto(query_param=QueryParam())
    actual = review_application_service.find_reviews(input_dto)
    expected = FindReviewsOutputDto(items=[
        FindReviewsOutputDto.Item(
            review_id=str(review_id),
            drink_id=str(drink_id),
            user_id=str(user_id),
            rating=int(rating),
            comment="hello",
            created_at=created_at,
            updated_at=created_at,
        ),
        FindReviewsOutputDto.Item(
            review_id=str(review_id_2),
            drink_id=str(drink_id_2),
            user_id=str(user_id_2),
            rating=int(rating),
            comment="olleh",
            created_at=created_at,
            updated_at=created_at,
        ),
    ])
    assert actual == expected
Beispiel #6
0
def create_review(
    request: CreateReviewJsonRequest,
    access_token: str = Header(...),
    auth_application_service: AuthApplicationService = Depends(
        Provide[Container.auth_application_service]),
    review_application_service: ReviewApplicationService = Depends(
        Provide[Container.review_application_service]),
    drink_application_service: DrinkApplicationService = Depends(
        Provide[Container.drink_application_service]),
) -> Union[CreateReviewJsonResponse, JSONResponse]:
    get_token_data_input_dto = GetTokenDataInputDto(access_token=access_token)
    get_token_data_output_dto = auth_application_service.get_token_data(
        get_token_data_input_dto)
    if not get_token_data_output_dto.status:
        return FailedJsonResponse.build_by_output_dto(
            get_token_data_output_dto)

    input_dto = CreateReviewInputDto(
        drink_id=request.drink_id,
        user_id=get_token_data_output_dto.user_id,
        rating=request.rating,
        comment=request.comment,
    )
    output_dto = review_application_service.create_review(
        input_dto=input_dto,
        drink_application_service=drink_application_service)
    if not output_dto.status:
        return FailedJsonResponse.build_by_output_dto(output_dto)
    return CreateReviewJsonResponse.build_by_output_dto(output_dto)
def test_find_reviews_fail(
    review_repository_mock,
    review_id,
    drink_id,
    user_id,
    rating,
    created_at,
):
    review_repository_mock.find_all.side_effect = InvalidParamInputError()
    review_application_service = ReviewApplicationService(
        review_repository=review_repository_mock)

    input_dto = FindReviewsInputDto(query_param=QueryParam())
    actual = review_application_service.find_reviews(input_dto)
    expected = FailedOutputDto(type="Parameters Error", message="")

    assert actual == expected
def test_find_review_fail(
    review_repository_mock,
    review_id,
    drink_id,
    user_id,
    rating,
    created_at,
):
    review_repository_mock.find_by_review_id.side_effect = ResourceNotFoundError(
    )
    review_application_service = ReviewApplicationService(
        review_repository=review_repository_mock)

    input_dto = FindReviewInputDto(review_id=str(review_id))
    actual = review_application_service.find_review(input_dto)
    expected = FailedOutputDto(type="Resource Not Found Error", message="")

    assert actual == expected
Beispiel #9
0
def get_reviews(
    query_param: QueryParam = Depends(),
    review_application_service: ReviewApplicationService = Depends(
        Provide[Container.review_application_service]),
) -> Union[List[GetReviewsJsonResponse], JSONResponse]:
    input_dto = FindReviewsInputDto(query_param=query_param.to_enum())
    output_dto = review_application_service.find_reviews(input_dto=input_dto)
    if not output_dto.status:
        return FailedJsonResponse.build_by_output_dto(output_dto)
    return GetReviewsJsonResponse.build_by_output_dto(output_dto)
Beispiel #10
0
def get_review(
    review_id: str,
    review_application_service: ReviewApplicationService = Depends(
        Provide[Container.review_application_service]),
) -> Union[GetReviewJsonResponse, JSONResponse]:
    input_dto = FindReviewInputDto(review_id=review_id)
    output_dto = review_application_service.find_review(input_dto=input_dto)
    if not output_dto.status:
        return FailedJsonResponse.build_by_output_dto(output_dto)
    return GetReviewJsonResponse.build_by_output_dto(output_dto)
def test_create_review_success(
    app,
    review_repository_mock,
    drink_application_service_mock,
    review_id,
    drink_id,
    user_id,
    rating,
    created_at,
):
    review_repository_mock.add.return_value = None
    review_application_service = ReviewApplicationService(
        review_repository=review_repository_mock)

    drink_application_service_mock.add_drink_review.return_value = AddDrinkReviewOutputDto(
    )
    with app.container.drink_application_service.override(
            drink_application_service_mock):
        input_dto = CreateReviewInputDto(
            drink_id=str(drink_id),
            user_id=user_id,
            rating=int(ReviewRating(value=rating)),
            comment="",
        )

        actual = review_application_service.create_review(
            input_dto, drink_application_service_mock)
        expected = CreateReviewOutputDto(
            review_id=str(review_id),
            drink_id=str(drink_id),
            user_id=user_id,
            rating=rating,
            comment="",
            created_at=actual.created_at,
            updated_at=actual.updated_at,
        )

        assert actual == expected
Beispiel #12
0
def delete_review(
    request: DeleteReviewJsonRequest,
    access_token: str = Header(...),
    auth_application_service: AuthApplicationService = Depends(
        Provide[Container.auth_application_service]),
    review_application_service: ReviewApplicationService = Depends(
        Provide[Container.review_application_service]),
    drink_application_service: DrinkApplicationService = Depends(
        Provide[Container.drink_application_service]),
) -> Optional[JSONResponse]:
    get_token_data_input_dto = GetTokenDataInputDto(access_token=access_token)
    get_token_data_output_dto = auth_application_service.get_token_data(
        get_token_data_input_dto)
    if not get_token_data_output_dto.status:
        return FailedJsonResponse.build_by_output_dto(
            get_token_data_output_dto)

    input_dto = DeleteReviewInputDto(review_id=request.review_id)
    output_dto = review_application_service.delete_review(
        input_dto, drink_application_service)
    if not output_dto.status:
        return FailedJsonResponse.build_by_output_dto(output_dto)