Skip to content

Commit

Permalink
fix: (sales dashboard) correct api call overage data (#2434)
Browse files Browse the repository at this point in the history
* Fix api call overage data

* Add unit test
  • Loading branch information
matthewelwell committed Jul 13, 2023
1 parent 3a4d8cb commit c55e675
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 4 additions & 1 deletion api/organisations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ def add_single_seat(self):

def get_api_call_overage(self):
subscription_info = self.organisation.subscription_information_cache
return subscription_info.allowed_30d_api_calls - subscription_info.api_calls_30d
overage = (
subscription_info.api_calls_30d - subscription_info.allowed_30d_api_calls
)
return overage if overage > 0 else 0


class OrganisationWebhook(AbstractBaseExportableWebhookModel):
Expand Down
22 changes: 22 additions & 0 deletions api/organisations/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from organisations.models import (
TRIAL_SUBSCRIPTION_ID,
Organisation,
OrganisationSubscriptionInformationCache,
Subscription,
)
from organisations.subscriptions.constants import (
Expand Down Expand Up @@ -367,3 +368,24 @@ def test_organisation_update_clears_environment_caches(

# Then
mock_environment_cache.delete_many.assert_called_once_with([environment.api_key])


@pytest.mark.parametrize(
"allowed_calls_30d, actual_calls_30d, expected_overage",
((1000000, 500000, 0), (1000000, 1100000, 100000), (0, 100000, 100000)),
)
def test_subscription_get_api_call_overage(
organisation, subscription, allowed_calls_30d, actual_calls_30d, expected_overage
):
# Given
OrganisationSubscriptionInformationCache.objects.create(
organisation=organisation,
allowed_30d_api_calls=allowed_calls_30d,
api_calls_30d=actual_calls_30d,
)

# When
overage = subscription.get_api_call_overage()

# Then
assert overage == expected_overage
2 changes: 1 addition & 1 deletion api/sales_dashboard/templates/sales_dashboard/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ <h1 class="h2">Organisations</h1>
<td>{{org.subscription_information_cache.api_calls_24h|intcomma|default:0}}</td>
<td>{{org.subscription_information_cache.api_calls_7d|intcomma|default:0}}</td>
<td><span class="{% if org.subscription_information_cache.api_calls_30d > org.subscription_information_cache.allowed_30d_api_calls %}badge badge-danger{% endif %}">{{org.subscription_information_cache.api_calls_30d|intcomma|default:0}}</span></td>
<td>{% if org.subscription.get_api_call_overage > 0 %}<span class="badge badge-danger">{{org.subscription.get_api_call_overage}}</span>{% endif %}</td>
<td><span {% if org.subscription.get_api_call_overage > 0 %}class="badge badge-danger"{% endif %}>{{org.subscription.get_api_call_overage|intcomma}}</span></td>
</tr>
{% endfor %}
</tbody>
Expand Down

3 comments on commit c55e675

@vercel
Copy link

@vercel vercel bot commented on c55e675 Jul 13, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on c55e675 Jul 13, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

docs – ./docs

docs.bullet-train.io
docs-git-main-flagsmith.vercel.app
docs-flagsmith.vercel.app
docs.flagsmith.com

@vercel
Copy link

@vercel vercel bot commented on c55e675 Jul 13, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.