Skip to content

Commit 0eb9327

Browse files
Merge pull request #331 from RemainingDelta/326-Enhancement
326-Enhancement add unit tests for TIMEZONE_ALIASES and convert_time command
2 parents a58d68d + c201cfe commit 0eb9327

1 file changed

Lines changed: 130 additions & 0 deletions

File tree

tests/test_convert_time.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
"""Tests for TIMEZONE_ALIASES and convert_time command in features/general.py."""
2+
3+
from features.general import General
4+
5+
6+
# --- TIMEZONE_ALIASES ---
7+
8+
9+
def test_alias_est_resolves_to_new_york():
10+
assert General.TIMEZONE_ALIASES["EST"] == "America/New_York"
11+
12+
13+
def test_alias_pt_resolves_to_los_angeles():
14+
assert General.TIMEZONE_ALIASES["PT"] == "America/Los_Angeles"
15+
16+
17+
def test_alias_utc_resolves_to_utc():
18+
assert General.TIMEZONE_ALIASES["UTC"] == "UTC"
19+
20+
21+
def test_alias_ist_resolves_to_kolkata():
22+
assert General.TIMEZONE_ALIASES["IST"] == "Asia/Kolkata"
23+
24+
25+
def test_alias_jst_resolves_to_tokyo():
26+
assert General.TIMEZONE_ALIASES["JST"] == "Asia/Tokyo"
27+
28+
29+
def test_alias_gmt_resolves_to_london():
30+
assert General.TIMEZONE_ALIASES["GMT"] == "Europe/London"
31+
32+
33+
def test_alias_cet_resolves_to_berlin():
34+
assert General.TIMEZONE_ALIASES["CET"] == "Europe/Berlin"
35+
36+
37+
# --- convert_time command ---
38+
39+
40+
async def test_convert_time_valid_input_sends_embed(mock_bot, mock_interaction):
41+
cog = General(mock_bot)
42+
await cog.convert_time.callback(
43+
cog, mock_interaction, "2025-01-01", "12:00 PM", "UTC"
44+
)
45+
46+
mock_interaction.response.send_message.assert_called_once()
47+
kwargs = mock_interaction.response.send_message.call_args.kwargs
48+
assert "embed" in kwargs
49+
50+
51+
async def test_convert_time_embed_contains_discord_timestamp(
52+
mock_bot, mock_interaction
53+
):
54+
cog = General(mock_bot)
55+
await cog.convert_time.callback(
56+
cog, mock_interaction, "2025-01-01", "12:00 PM", "UTC"
57+
)
58+
59+
embed = mock_interaction.response.send_message.call_args.kwargs["embed"]
60+
assert "<t:" in embed.description
61+
62+
63+
async def test_convert_time_alias_works(mock_bot, mock_interaction):
64+
"""EST alias should resolve and return an embed, not an error."""
65+
cog = General(mock_bot)
66+
await cog.convert_time.callback(
67+
cog, mock_interaction, "2025-06-15", "3:00 PM", "EST"
68+
)
69+
70+
kwargs = mock_interaction.response.send_message.call_args.kwargs
71+
assert "embed" in kwargs
72+
73+
74+
async def test_convert_time_iana_timezone_works(mock_bot, mock_interaction):
75+
"""Direct IANA timezone name should be accepted."""
76+
cog = General(mock_bot)
77+
await cog.convert_time.callback(
78+
cog, mock_interaction, "2025-06-15", "3:00 PM", "America/New_York"
79+
)
80+
81+
kwargs = mock_interaction.response.send_message.call_args.kwargs
82+
assert "embed" in kwargs
83+
84+
85+
async def test_convert_time_invalid_timezone_sends_ephemeral_error(
86+
mock_bot, mock_interaction
87+
):
88+
cog = General(mock_bot)
89+
await cog.convert_time.callback(
90+
cog, mock_interaction, "2025-01-01", "12:00 PM", "FAKETZ"
91+
)
92+
93+
mock_interaction.response.send_message.assert_called_once()
94+
kwargs = mock_interaction.response.send_message.call_args.kwargs
95+
assert kwargs.get("ephemeral") is True
96+
97+
98+
async def test_convert_time_invalid_date_sends_ephemeral_error(
99+
mock_bot, mock_interaction
100+
):
101+
cog = General(mock_bot)
102+
await cog.convert_time.callback(
103+
cog, mock_interaction, "not-a-date", "12:00 PM", "UTC"
104+
)
105+
106+
mock_interaction.response.send_message.assert_called_once()
107+
kwargs = mock_interaction.response.send_message.call_args.kwargs
108+
assert kwargs.get("ephemeral") is True
109+
110+
111+
async def test_convert_time_invalid_time_format_sends_ephemeral_error(
112+
mock_bot, mock_interaction
113+
):
114+
cog = General(mock_bot)
115+
await cog.convert_time.callback(cog, mock_interaction, "2025-01-01", "25:99", "UTC")
116+
117+
mock_interaction.response.send_message.assert_called_once()
118+
kwargs = mock_interaction.response.send_message.call_args.kwargs
119+
assert kwargs.get("ephemeral") is True
120+
121+
122+
async def test_convert_time_footer_shows_alias_expansion(mock_bot, mock_interaction):
123+
"""Footer should note the alias expansion when an abbreviation is used."""
124+
cog = General(mock_bot)
125+
await cog.convert_time.callback(
126+
cog, mock_interaction, "2025-01-01", "12:00 PM", "EST"
127+
)
128+
129+
embed = mock_interaction.response.send_message.call_args.kwargs["embed"]
130+
assert "from EST" in embed.footer.text

0 commit comments

Comments
 (0)