|
3 | 3 | import asyncio |
4 | 4 | from types import SimpleNamespace |
5 | 5 | import json |
6 | | -from unittest.mock import AsyncMock, Mock |
| 6 | +from unittest.mock import AsyncMock, Mock, call |
7 | 7 |
|
8 | 8 | import discord |
9 | 9 | import pytest |
@@ -162,6 +162,182 @@ def permissions_for(self, _member: object) -> SimpleNamespace: |
162 | 162 | reason="Dashboard gig status update", |
163 | 163 | ) |
164 | 164 |
|
| 165 | + @pytest.mark.asyncio |
| 166 | + async def test_update_gig_thread_status_uses_fallback_for_marker_only_title( |
| 167 | + self, internal_api_routes, monkeypatch: pytest.MonkeyPatch |
| 168 | + ): |
| 169 | + """Dashboard status sync should not stack markers for marker-only titles.""" |
| 170 | + |
| 171 | + class FakeThread: |
| 172 | + id = 123 |
| 173 | + name = "[RECRUITING]" |
| 174 | + archived = False |
| 175 | + locked = False |
| 176 | + guild = SimpleNamespace(me=object()) |
| 177 | + |
| 178 | + def __init__(self) -> None: |
| 179 | + self.edit = AsyncMock() |
| 180 | + |
| 181 | + def permissions_for(self, _member: object) -> SimpleNamespace: |
| 182 | + return SimpleNamespace( |
| 183 | + manage_threads=True, |
| 184 | + view_channel=True, |
| 185 | + send_messages_in_threads=True, |
| 186 | + ) |
| 187 | + |
| 188 | + thread = FakeThread() |
| 189 | + monkeypatch.setattr( |
| 190 | + "five08.discord_bot.utils.internal_api.discord.Thread", |
| 191 | + FakeThread, |
| 192 | + ) |
| 193 | + internal_api_routes.bot.get_channel.return_value = thread |
| 194 | + |
| 195 | + result, status_code = await internal_api_routes._update_gig_thread_status( |
| 196 | + GigThreadStatusRequest(thread_id="123", status="filled") |
| 197 | + ) |
| 198 | + |
| 199 | + assert status_code == 200 |
| 200 | + assert result["title"] == "[FILLED] Discord gig 123" |
| 201 | + thread.edit.assert_awaited_once_with( |
| 202 | + name="[FILLED] Discord gig 123", |
| 203 | + reason="Dashboard gig status update", |
| 204 | + ) |
| 205 | + |
| 206 | + @pytest.mark.asyncio |
| 207 | + async def test_update_gig_thread_status_closes_lost_thread( |
| 208 | + self, internal_api_routes, monkeypatch: pytest.MonkeyPatch |
| 209 | + ): |
| 210 | + """Dashboard lost status changes should lock and archive the Discord thread.""" |
| 211 | + |
| 212 | + class FakeThread: |
| 213 | + id = 123 |
| 214 | + name = "[RECRUITING] Old gig" |
| 215 | + archived = False |
| 216 | + locked = False |
| 217 | + guild = SimpleNamespace(me=object()) |
| 218 | + |
| 219 | + def __init__(self) -> None: |
| 220 | + self.edit = AsyncMock() |
| 221 | + |
| 222 | + def permissions_for(self, _member: object) -> SimpleNamespace: |
| 223 | + return SimpleNamespace( |
| 224 | + manage_threads=True, |
| 225 | + view_channel=True, |
| 226 | + send_messages_in_threads=True, |
| 227 | + ) |
| 228 | + |
| 229 | + thread = FakeThread() |
| 230 | + monkeypatch.setattr( |
| 231 | + "five08.discord_bot.utils.internal_api.discord.Thread", |
| 232 | + FakeThread, |
| 233 | + ) |
| 234 | + internal_api_routes.bot.get_channel.return_value = thread |
| 235 | + |
| 236 | + result, status_code = await internal_api_routes._update_gig_thread_status( |
| 237 | + GigThreadStatusRequest(thread_id="123", status="lost") |
| 238 | + ) |
| 239 | + |
| 240 | + assert status_code == 200 |
| 241 | + assert result["status"] == "updated" |
| 242 | + assert result["title"] == "[LOST] Old gig" |
| 243 | + assert result["closed"] is True |
| 244 | + assert thread.edit.await_args_list == [ |
| 245 | + call(name="[LOST] Old gig", reason="Dashboard gig status update"), |
| 246 | + call( |
| 247 | + locked=True, |
| 248 | + archived=True, |
| 249 | + reason="Dashboard gig status update", |
| 250 | + ), |
| 251 | + ] |
| 252 | + |
| 253 | + @pytest.mark.asyncio |
| 254 | + async def test_update_gig_thread_status_reopens_non_lost_thread( |
| 255 | + self, internal_api_routes, monkeypatch: pytest.MonkeyPatch |
| 256 | + ): |
| 257 | + """Moving a closed lost thread away from lost should make it usable again.""" |
| 258 | + |
| 259 | + class FakeThread: |
| 260 | + id = 123 |
| 261 | + name = "[LOST] Old gig" |
| 262 | + archived = True |
| 263 | + locked = True |
| 264 | + guild = SimpleNamespace(me=object()) |
| 265 | + |
| 266 | + def __init__(self) -> None: |
| 267 | + self.edit = AsyncMock() |
| 268 | + |
| 269 | + def permissions_for(self, _member: object) -> SimpleNamespace: |
| 270 | + return SimpleNamespace( |
| 271 | + manage_threads=True, |
| 272 | + view_channel=True, |
| 273 | + send_messages_in_threads=True, |
| 274 | + ) |
| 275 | + |
| 276 | + thread = FakeThread() |
| 277 | + monkeypatch.setattr( |
| 278 | + "five08.discord_bot.utils.internal_api.discord.Thread", |
| 279 | + FakeThread, |
| 280 | + ) |
| 281 | + internal_api_routes.bot.get_channel.return_value = thread |
| 282 | + |
| 283 | + result, status_code = await internal_api_routes._update_gig_thread_status( |
| 284 | + GigThreadStatusRequest(thread_id="123", status="recruiting") |
| 285 | + ) |
| 286 | + |
| 287 | + assert status_code == 200 |
| 288 | + assert result["status"] == "updated" |
| 289 | + assert result["title"] == "[RECRUITING] Old gig" |
| 290 | + assert result["closed"] is False |
| 291 | + assert thread.edit.await_args_list == [ |
| 292 | + call( |
| 293 | + locked=False, |
| 294 | + archived=False, |
| 295 | + reason="Dashboard gig status update", |
| 296 | + ), |
| 297 | + call(name="[RECRUITING] Old gig", reason="Dashboard gig status update"), |
| 298 | + ] |
| 299 | + |
| 300 | + @pytest.mark.asyncio |
| 301 | + async def test_update_gig_thread_status_preserves_moderator_lock( |
| 302 | + self, internal_api_routes, monkeypatch: pytest.MonkeyPatch |
| 303 | + ): |
| 304 | + """Non-lost status sync should not clear locks unrelated to lost closure.""" |
| 305 | + |
| 306 | + class FakeThread: |
| 307 | + id = 123 |
| 308 | + name = "[RECRUITING] Old gig" |
| 309 | + archived = False |
| 310 | + locked = True |
| 311 | + guild = SimpleNamespace(me=object()) |
| 312 | + |
| 313 | + def __init__(self) -> None: |
| 314 | + self.edit = AsyncMock() |
| 315 | + |
| 316 | + def permissions_for(self, _member: object) -> SimpleNamespace: |
| 317 | + return SimpleNamespace( |
| 318 | + manage_threads=True, |
| 319 | + view_channel=True, |
| 320 | + send_messages_in_threads=True, |
| 321 | + ) |
| 322 | + |
| 323 | + thread = FakeThread() |
| 324 | + monkeypatch.setattr( |
| 325 | + "five08.discord_bot.utils.internal_api.discord.Thread", |
| 326 | + FakeThread, |
| 327 | + ) |
| 328 | + internal_api_routes.bot.get_channel.return_value = thread |
| 329 | + |
| 330 | + result, status_code = await internal_api_routes._update_gig_thread_status( |
| 331 | + GigThreadStatusRequest(thread_id="123", status="filled") |
| 332 | + ) |
| 333 | + |
| 334 | + assert status_code == 200 |
| 335 | + assert result["title"] == "[FILLED] Old gig" |
| 336 | + thread.edit.assert_awaited_once_with( |
| 337 | + name="[FILLED] Old gig", |
| 338 | + reason="Dashboard gig status update", |
| 339 | + ) |
| 340 | + |
165 | 341 | @pytest.mark.asyncio |
166 | 342 | async def test_update_gig_thread_status_reports_missing_manage_threads( |
167 | 343 | self, internal_api_routes, monkeypatch: pytest.MonkeyPatch |
|
0 commit comments