Skip to content

Commit

Permalink
Fixes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
boralyl committed Dec 22, 2020
1 parent d25e7a2 commit 9d068b9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion custom_components/nintendo_wishlist/eshop.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,11 @@ async def _get_eu_page(self, page: int = 0) -> ResultsDict:

def get_eu_switch_game(self, game: dict) -> SwitchGame:
try:
image_url = game["image_url"]
if not image_url.startswith("https:"):
image_url = f"https:{image_url}"
return {
"box_art_url": f"https:{game['image_url']}",
"box_art_url": image_url,
"nsuid": int(game["nsuid_txt"][0]),
"percent_off": game["price_discount_percentage_f"],
"title": game["title"],
Expand Down
20 changes: 20 additions & 0 deletions tests/test_eshop.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,26 @@ def test_get_eu_switch_game():
assert expected == actual


def test_get_eu_switch_game_with_https_prefix_on_image_url():
"""Regression test for when the image_url actually has a protocol."""
wishlist = ["Aggelos"]
eshop = EShop("DE", Mock(), wishlist)
game = {
"title": "Aggelos",
"image_url": "https://nintendo.com/image.png",
"nsuid_txt": ["70010000532"],
"price_discount_percentage_f": 10,
}
actual = eshop.get_eu_switch_game(game)
expected = {
"box_art_url": "https://nintendo.com/image.png",
"nsuid": 70010000532,
"percent_off": 10,
"title": "Aggelos",
}
assert expected == actual


async def test_fetch_eu():
"""Test the fetch_eu method returns the expected result."""
page_response = {
Expand Down

0 comments on commit 9d068b9

Please sign in to comment.