Skip to content

Commit

Permalink
Merge pull request #8419 from cfpb/tccp/avoid-hardcoding-strings
Browse files Browse the repository at this point in the history
TCCP: Don't hardcode fee strings
  • Loading branch information
chosak committed May 17, 2024
2 parents a6e7fe1 + 4d94fac commit 74411e6
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 26 deletions.
53 changes: 28 additions & 25 deletions cfgov/tccp/jinja2/tccp/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -497,27 +497,28 @@ <h2>
' for a late payment within six billing cycles of another
late payment' if card.late_fee_six_month_billing_cycle
}}
{# A handful of cards specify neither a first nor repeat late
fee and put all late fee info in the late_fee_policy_details
field. For cards like that, we'll show the details here and
not show the "Late fee policy details" item.
{#
A handful of cards specify neither a first nor repeat
late fee and put all late fee info in the
late_fee_policy_details field. For cards like that,
we'll show the details here and not show the "Late fee
policy details" item.
#}
{# TODO: Refactor to not use the exact string #}
{{ card.late_fee_policy_details if card.late_fee_types ==
['3. If you charge late fees that are not fixed dollar amounts, please explain your late fee policy here.']
{{
card.late_fee_policy_details
if card.has_only_variable_late_fees
}}
{% else %}
None
{% endif %}
</dd>
{# See the comment above: we won't show this if we're already showing
late fee details in the "Late fee" item, i.e. if the card has *only*
policy details chosen in late_fee_types
{#
See the comment above: we won't show this if we're already
showing late fee details in the "Late fee" item, i.e. if the
card has *only* policy details chosen in late_fee_types.
#}
{# TODO: Refactor to not use the exact string #}
{% if card.late_fee_policy_details
and card.late_fee_types !=
['3. If you charge late fees that are not fixed dollar amounts, please explain your late fee policy here.']
and not card.has_only_variable_late_fees
%}
<dt>Late fee policy details</dt>
<dd>{{ card.late_fee_policy_details }}</dd>
Expand All @@ -528,26 +529,28 @@ <h2>
{{ currency(card.over_limit_fee_dollars) if
card.over_limit_fee_dollars
}}
{# A handful of cards specify only over-limit fee details and
not a fixed dollar amount. For cards like that, we'll show
the details here and not show the "Over-limit fee details."
{#
A handful of cards specify only over-limit fee details
and not a fixed dollar amount. For cards like that,
we'll show the details here and not show the
"Over-limit fee details."
#}
{# TODO: Refactor to not use the exact string #}
{{ card.overlimit_fee_detail if card.over_limit_fee_types ==
['2. If you charge overlimit fees that are not fixed dollar amounts, please explain what overlimit fees you charge here:']
{{
card.overlimit_fee_detail
if card.has_only_variable_over_limit_fees
}}
{% else %}
None
{% endif %}
</dd>
{# See the comment above: we won't show this if we're already showing
over-limit fee details in the "Over-limit fee" item, i.e. if the
card has *only* details chosen in over_limit_fee_types.
{#
See the comment above: we won't show this if we're already
showing over-limit fee details in the "Over-limit fee" item,
i.e. if the card has *only* details chosen in
over_limit_fee_types.
#}
{# TODO: Refactor to not use the exact string #}
{% if card.overlimit_fee_detail
and card.over_limit_fee_types !=
['2. If you charge overlimit fees that are not fixed dollar amounts, please explain what overlimit fees you charge here:']
and not card.has_only_variable_over_limit_fees
%}
<dt>Over-limit fee details</dt>
<dd>{{ card.overlimit_fee_detail }}</dd>
Expand Down
10 changes: 10 additions & 0 deletions cfgov/tccp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,3 +745,13 @@ def purchase_apr_data_incomplete(self):
@property
def issued_by_credit_union(self):
return self.institution_type == "CU"

@property
def has_only_variable_late_fees(self):
return [enums.LateFeeTypeChoices[2][0]] == self.late_fee_types

@property
def has_only_variable_over_limit_fees(self):
return [
enums.OverlimitFeeTypeChoices[1][0]
] == self.over_limit_fee_types
2 changes: 2 additions & 0 deletions cfgov/tccp/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class CardSurveyDataSerializer(serializers.HyperlinkedModelSerializer):
purchase_apr_poor_rating = serializers.IntegerField()
purchase_apr_data_incomplete = serializers.BooleanField()
issued_by_credit_union = serializers.BooleanField()
has_only_variable_late_fees = serializers.BooleanField()
has_only_variable_over_limit_fees = serializers.BooleanField()

class Meta:
model = CardSurveyData
Expand Down
36 changes: 35 additions & 1 deletion cfgov/tccp/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from django.test import SimpleTestCase, TestCase
from django.utils import timezone

from tccp.enums import CreditTierColumns
from tccp.enums import (
CreditTierColumns,
LateFeeTypeChoices,
OverlimitFeeTypeChoices,
)
from tccp.models import CardSurveyData

from .baker import baker
Expand Down Expand Up @@ -222,3 +226,33 @@ def test_issued_by_credit_union(self):
self.assertFalse(
CardSurveyData(institution_type="Bank").issued_by_credit_union
)

def test_has_only_variable_late_fees(self):
self.assertFalse(
CardSurveyData(
late_fee_types=[
LateFeeTypeChoices[0][0],
LateFeeTypeChoices[2][0],
]
).has_only_variable_late_fees
)
self.assertTrue(
CardSurveyData(
late_fee_types=[LateFeeTypeChoices[2][0]]
).has_only_variable_late_fees
)

def test_has_only_variable_over_limit_fees(self):
self.assertFalse(
CardSurveyData(
over_limit_fee_types=[
OverlimitFeeTypeChoices[0][0],
OverlimitFeeTypeChoices[1][0],
]
).has_only_variable_over_limit_fees
)
self.assertTrue(
CardSurveyData(
over_limit_fee_types=[OverlimitFeeTypeChoices[1][0]]
).has_only_variable_over_limit_fees
)

0 comments on commit 74411e6

Please sign in to comment.