|
| 1 | +from datetime import datetime, timezone |
1 | 2 | import json |
2 | 3 |
|
3 | 4 | from nonebot.adapters.discord.api import ( |
|
7 | 8 | SelectOption, |
8 | 9 | ) |
9 | 10 | from nonebot.adapters.discord.api.model import ( |
| 11 | + Embed, |
10 | 12 | ExecuteWebhookParams, |
11 | 13 | File, |
12 | 14 | MessageEditParams, |
@@ -42,6 +44,16 @@ def test_parse_data_execute_webhook_omits_unset_fields() -> None: |
42 | 44 | assert payload == {} |
43 | 45 |
|
44 | 46 |
|
| 47 | +def test_parse_data_serializes_embed_timestamp() -> None: |
| 48 | + timestamp = datetime(2026, 3, 14, 12, 0, tzinfo=timezone.utc) |
| 49 | + payload = parse_data( |
| 50 | + {"embeds": [Embed(timestamp=timestamp)]}, |
| 51 | + MessageSend, |
| 52 | + )["json"] |
| 53 | + |
| 54 | + assert payload["embeds"][0]["timestamp"] == timestamp.isoformat() |
| 55 | + |
| 56 | + |
45 | 57 | def test_parse_data_multipart_keeps_null_attachments() -> None: |
46 | 58 | res = parse_data( |
47 | 59 | { |
@@ -103,6 +115,22 @@ def test_parse_forum_thread_message_without_content() -> None: |
103 | 115 | assert payload["message"] == {} |
104 | 116 |
|
105 | 117 |
|
| 118 | +def test_parse_forum_thread_message_serializes_embed_timestamp_in_multipart() -> None: |
| 119 | + timestamp = datetime(2026, 3, 14, 12, 0, tzinfo=timezone.utc) |
| 120 | + res = parse_forum_thread_message( |
| 121 | + { |
| 122 | + "name": "thread-name", |
| 123 | + "files": [File(content=b"1", filename="a.txt")], |
| 124 | + "embeds": [Embed(timestamp=timestamp)], |
| 125 | + } |
| 126 | + ) |
| 127 | + multipart = res["files"] |
| 128 | + _, payload_json, _ = multipart["payload_json"] |
| 129 | + payload = json.loads(payload_json) |
| 130 | + |
| 131 | + assert payload["message"]["embeds"][0]["timestamp"] == timestamp.isoformat() |
| 132 | + |
| 133 | + |
106 | 134 | def test_parse_forum_thread_message_maps_message_attachment_id() -> None: |
107 | 135 | res = parse_forum_thread_message( |
108 | 136 | { |
|
0 commit comments