Fix distribution_type

This commit is contained in:
Joakim Hellsén 2026-01-05 21:44:58 +01:00
commit bd66f3071e
No known key found for this signature in database
2 changed files with 43 additions and 6 deletions

View file

@ -0,0 +1,36 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from django.test import TestCase
from twitch.management.commands.better_import_drops import Command
from twitch.schemas import DropBenefitSchema
if TYPE_CHECKING:
from twitch.models import DropBenefit
class GetOrUpdateBenefitTests(TestCase):
"""Tests for the _get_or_update_benefit method in better_import_drops.Command."""
def test_defaults_distribution_type_when_missing(self) -> None:
"""Ensure importer sets distribution_type to empty string when absent."""
command = Command()
command.benefit_cache = {}
benefit_schema: DropBenefitSchema = DropBenefitSchema.model_validate(
{
"id": "benefit-missing-distribution-type",
"name": "Test Benefit",
"imageAssetURL": "https://example.com/benefit.png",
"entitlementLimit": 1,
"isIosAvailable": False,
"__typename": "DropBenefit",
},
)
benefit: DropBenefit = command._get_or_update_benefit(benefit_schema) # noqa: SLF001
benefit.refresh_from_db()
assert not benefit.distribution_type