Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

21536 - Passing short Name Id parameter to find refunds #1783

Merged
merged 13 commits into from
Oct 18, 2024
12 changes: 6 additions & 6 deletions pay-api/src/pay_api/dtos/eft_shortname.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""

from decimal import Decimal
from typing import List

from attrs import define

Expand Down Expand Up @@ -67,14 +66,15 @@ class EFTShortNameRefundPatchRequest(Serializable):


@define
class EFTShortNameRefundGetRequest:
class EFTShortNameRefundGetRequest(Serializable):
"""EFT Short name refund DTO."""

statuses: List[str]
statuses: str = None
short_name_id: int = None

@classmethod
def from_dict(cls, data: dict):
"""Convert from request json to EFTShortNameRefundDTO."""
input_string = data.get("status", "")
statuses = input_string.split(",") if input_string else []
return EFTShortNameRefundGetRequest(statuses=statuses)
dto = super().from_dict(data)
dto.statuses = dto.statuses.split(",") if dto.statuses else []
return dto
4 changes: 3 additions & 1 deletion pay-api/src/pay_api/models/eft_refund.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ class EFTRefund(Audit):
status = db.Column(db.String(25), nullable=True)

@classmethod
def find_refunds(cls, statuses: List[str]):
def find_refunds(cls, statuses: List[str], short_name_id: int = None):
"""Return all refunds by status."""
query = cls.query
if statuses:
query = cls.query.filter(EFTRefund.status.in_(statuses))
if short_name_id:
query = cls.query.filter(EFTRefund.short_name_id == short_name_id)
return query.all()
2 changes: 1 addition & 1 deletion pay-api/src/pay_api/services/eft_refund.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def create_shortname_refund(request: dict, **kwargs):
@staticmethod
def get_shortname_refunds(data: EFTShortNameRefundGetRequest):
"""Get all refunds."""
refunds = EFTRefundModel.find_refunds(data.statuses)
refunds = EFTRefundModel.find_refunds(data.statuses, data.short_name_id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update tests for short_name_id search please

return [refund.to_dict() for refund in refunds]

@staticmethod
Expand Down
23 changes: 18 additions & 5 deletions pay-api/tests/unit/api/test_eft_short_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,24 +1067,37 @@ def test_post_shortname_refund_invalid_request(client, mocker, jwt):


@pytest.mark.parametrize(
"query_string, test_name, count",
"query_string_factory, test_name, count",
[
("", "get_all", 3),
(lambda short_id: "", "get_all", 3),
(
f"?status={EFTShortnameRefundStatus.APPROVED.value},{EFTShortnameRefundStatus.PENDING_APPROVAL.value}",
lambda short_id: f"?short_name_id={short_id}&statuses={EFTShortnameRefundStatus.APPROVED.value},"
f"{EFTShortnameRefundStatus.PENDING_APPROVAL.value}",
"short_name_id_status_filter_multiple",
2,
),
(
lambda short_id: f"?short_name_id={short_id}&statuses={EFTShortnameRefundStatus.DECLINED.value}",
"short_name_id_status_filter_rejected",
1,
),
(
lambda short_id: f"?statuses={EFTShortnameRefundStatus.APPROVED.value},"
f"{EFTShortnameRefundStatus.PENDING_APPROVAL.value}",
"status_filter_multiple",
2,
),
(
f"?status={EFTShortnameRefundStatus.DECLINED.value}",
lambda short_id: f"?statuses={EFTShortnameRefundStatus.DECLINED.value}",
"status_filter_rejected",
1,
),
],
)
def test_get_shortname_refund(session, client, jwt, query_string, test_name, count):
def test_get_shortname_refund(session, client, jwt, query_string_factory, test_name, count):
"""Test get short name refund."""
short_name = factory_eft_shortname("TEST_SHORTNAME").save()
query_string = query_string_factory(short_name.id)
factory_eft_refund(short_name_id=short_name.id, status=EFTShortnameRefundStatus.APPROVED.value)
factory_eft_refund(
short_name_id=short_name.id,
Expand Down
Loading