Enhance badge descriptions in campaign detail and RSS feed outputs

This commit is contained in:
Joakim Hellsén 2026-01-16 01:54:18 +01:00
commit fad0821515
No known key found for this signature in database
6 changed files with 141 additions and 9 deletions

View file

@ -8,9 +8,13 @@ from django.test import TestCase
from django.urls import reverse
from django.utils import timezone
from twitch.models import ChatBadge
from twitch.models import ChatBadgeSet
from twitch.models import DropBenefit
from twitch.models import DropCampaign
from twitch.models import Game
from twitch.models import Organization
from twitch.models import TimeBasedDrop
class RSSFeedTestCase(TestCase):
@ -59,6 +63,39 @@ class RSSFeedTestCase(TestCase):
assert response.status_code == 200
assert response["Content-Type"] == "application/rss+xml; charset=utf-8"
def test_campaign_feed_includes_badge_description(self) -> None:
"""Badge benefit descriptions should be visible in the RSS drop summary."""
drop = TimeBasedDrop.objects.create(
twitch_id="drop-1",
name="Diana Chat Badge",
campaign=self.campaign,
required_minutes_watched=0,
required_subs=1,
)
benefit = DropBenefit.objects.create(
twitch_id="benefit-1",
name="Diana",
distribution_type="BADGE",
)
drop.benefits.add(benefit)
badge_set = ChatBadgeSet.objects.create(set_id="diana")
ChatBadge.objects.create(
badge_set=badge_set,
badge_id="1",
image_url_1x="https://example.com/1x.png",
image_url_2x="https://example.com/2x.png",
image_url_4x="https://example.com/4x.png",
title="Diana",
description="This badge was earned by subscribing.",
)
url = reverse("twitch:campaign_feed")
response = self.client.get(url)
assert response.status_code == 200
content = response.content.decode("utf-8")
assert "This badge was earned by subscribing." in content
def test_game_campaign_feed(self) -> None:
"""Test game-specific campaign feed returns 200."""
url = reverse("twitch:game_campaign_feed", args=[self.game.twitch_id])

View file

@ -10,6 +10,8 @@ from django.urls import reverse
from django.utils import timezone
from twitch.models import Channel
from twitch.models import ChatBadge
from twitch.models import ChatBadgeSet
from twitch.models import DropBenefit
from twitch.models import DropCampaign
from twitch.models import Game
@ -469,6 +471,54 @@ class TestChannelListView:
assert response.status_code == 200
assert "campaign" in response.context
@pytest.mark.django_db
def test_drop_campaign_detail_view_badge_benefit_includes_description_from_chatbadge(
self,
client: Client,
) -> None:
"""Test campaign detail view includes badge benefit description from ChatBadge."""
game: Game = Game.objects.create(twitch_id="g-badge", name="Game", display_name="Game")
campaign: DropCampaign = DropCampaign.objects.create(
twitch_id="c-badge",
name="Campaign",
game=game,
operation_name="DropCampaignDetails",
)
drop = TimeBasedDrop.objects.create(
twitch_id="d1",
name="Drop",
campaign=campaign,
required_minutes_watched=0,
required_subs=1,
)
benefit = DropBenefit.objects.create(
twitch_id="b1",
name="Diana",
distribution_type="BADGE",
)
drop.benefits.add(benefit)
badge_set = ChatBadgeSet.objects.create(set_id="diana")
ChatBadge.objects.create(
badge_set=badge_set,
badge_id="1",
image_url_1x="https://example.com/1",
image_url_2x="https://example.com/2",
image_url_4x="https://example.com/4",
title="Diana",
description="This badge was earned by subscribing.",
)
url: str = reverse("twitch:campaign_detail", args=[campaign.twitch_id])
response: _MonkeyPatchedWSGIResponse = client.get(url)
assert response.status_code == 200
# The campaign detail page prints a syntax-highlighted JSON block; the badge description should be present.
html = response.content.decode("utf-8")
assert "This badge was earned by subscribing." in html
@pytest.mark.django_db
def test_games_grid_view(self, client: Client) -> None:
"""Test games grid view returns 200 and has games in context."""