| 1 |
package discord |
| 2 |
|
| 3 |
import ( |
| 4 |
"strconv" |
| 5 |
"time" |
| 6 |
|
| 7 |
"github.com/onsi/ginkgo/v2" |
| 8 |
"github.com/onsi/gomega" |
| 9 |
|
| 10 |
"github.com/nicholas-fedor/shoutrrr/pkg/types" |
| 11 |
) |
| 12 |
|
| 13 |
var _ = ginkgo.Describe("Discord JSON Unit Tests", func() { |
| 14 |
ginkgo.Describe("hasEmbedFields function", func() { |
| 15 |
ginkgo.It("should return false for empty fields", func() { |
| 16 |
fields := []types.Field{} |
| 17 |
result := hasEmbedFields(fields) |
| 18 |
gomega.Expect(result).To(gomega.BeFalse()) |
| 19 |
}) |
| 20 |
|
| 21 |
ginkgo.It("should return true for regular fields only", func() { |
| 22 |
fields := []types.Field{ |
| 23 |
{Key: "regular_field", Value: "value"}, |
| 24 |
{Key: "another_field", Value: "another_value"}, |
| 25 |
} |
| 26 |
result := hasEmbedFields(fields) |
| 27 |
gomega.Expect(result).To(gomega.BeTrue()) |
| 28 |
}) |
| 29 |
|
| 30 |
ginkgo.It("should return true when embed_author_name is present", func() { |
| 31 |
fields := []types.Field{ |
| 32 |
{Key: "regular_field", Value: "value"}, |
| 33 |
{Key: "embed_author_name", Value: "Author Name"}, |
| 34 |
} |
| 35 |
result := hasEmbedFields(fields) |
| 36 |
gomega.Expect(result).To(gomega.BeTrue()) |
| 37 |
}) |
| 38 |
|
| 39 |
ginkgo.It("should return true when embed_author_url is present", func() { |
| 40 |
fields := []types.Field{ |
| 41 |
{Key: "embed_author_url", Value: "https://example.com"}, |
| 42 |
} |
| 43 |
result := hasEmbedFields(fields) |
| 44 |
gomega.Expect(result).To(gomega.BeTrue()) |
| 45 |
}) |
| 46 |
|
| 47 |
ginkgo.It("should return true when embed_author_icon_url is present", func() { |
| 48 |
fields := []types.Field{ |
| 49 |
{Key: "embed_author_icon_url", Value: "https://example.com/icon.png"}, |
| 50 |
} |
| 51 |
result := hasEmbedFields(fields) |
| 52 |
gomega.Expect(result).To(gomega.BeTrue()) |
| 53 |
}) |
| 54 |
|
| 55 |
ginkgo.It("should return true when embed_image_url is present", func() { |
| 56 |
fields := []types.Field{ |
| 57 |
{Key: "embed_image_url", Value: "https://example.com/image.png"}, |
| 58 |
} |
| 59 |
result := hasEmbedFields(fields) |
| 60 |
gomega.Expect(result).To(gomega.BeTrue()) |
| 61 |
}) |
| 62 |
|
| 63 |
ginkgo.It("should return true when embed_thumbnail_url is present", func() { |
| 64 |
fields := []types.Field{ |
| 65 |
{Key: "embed_thumbnail_url", Value: "https://example.com/thumb.png"}, |
| 66 |
} |
| 67 |
result := hasEmbedFields(fields) |
| 68 |
gomega.Expect(result).To(gomega.BeTrue()) |
| 69 |
}) |
| 70 |
|
| 71 |
ginkgo.It("should return true when multiple embed fields are present", func() { |
| 72 |
fields := []types.Field{ |
| 73 |
{Key: "embed_author_name", Value: "Author"}, |
| 74 |
{Key: "embed_image_url", Value: "https://example.com/image.png"}, |
| 75 |
{Key: "embed_thumbnail_url", Value: "https://example.com/thumb.png"}, |
| 76 |
} |
| 77 |
result := hasEmbedFields(fields) |
| 78 |
gomega.Expect(result).To(gomega.BeTrue()) |
| 79 |
}) |
| 80 |
}) |
| 81 |
|
| 82 |
ginkgo.Describe("processEmbedFields function", func() { |
| 83 |
ginkgo.It("should return nil values for empty fields", func() { |
| 84 |
fields := []types.Field{} |
| 85 |
author, image, thumbnail, embedFields := processEmbedFields(fields) |
| 86 |
gomega.Expect(author).To(gomega.BeNil()) |
| 87 |
gomega.Expect(image).To(gomega.BeNil()) |
| 88 |
gomega.Expect(thumbnail).To(gomega.BeNil()) |
| 89 |
gomega.Expect(embedFields).To(gomega.BeEmpty()) |
| 90 |
}) |
| 91 |
|
| 92 |
ginkgo.It("should process regular fields into embed fields", func() { |
| 93 |
fields := []types.Field{ |
| 94 |
{Key: "field1", Value: "value1"}, |
| 95 |
{Key: "field2", Value: "value2"}, |
| 96 |
} |
| 97 |
author, image, thumbnail, embedFields := processEmbedFields(fields) |
| 98 |
gomega.Expect(author).To(gomega.BeNil()) |
| 99 |
gomega.Expect(image).To(gomega.BeNil()) |
| 100 |
gomega.Expect(thumbnail).To(gomega.BeNil()) |
| 101 |
gomega.Expect(embedFields).To(gomega.HaveLen(2)) |
| 102 |
gomega.Expect(embedFields[0].Name).To(gomega.Equal("field1")) |
| 103 |
gomega.Expect(embedFields[0].Value).To(gomega.Equal("value1")) |
| 104 |
gomega.Expect(embedFields[1].Name).To(gomega.Equal("field2")) |
| 105 |
gomega.Expect(embedFields[1].Value).To(gomega.Equal("value2")) |
| 106 |
}) |
| 107 |
|
| 108 |
ginkgo.It("should process embed_author_name field", func() { |
| 109 |
fields := []types.Field{ |
| 110 |
{Key: "embed_author_name", Value: "Test Author"}, |
| 111 |
} |
| 112 |
author, image, thumbnail, embedFields := processEmbedFields(fields) |
| 113 |
gomega.Expect(author).NotTo(gomega.BeNil()) |
| 114 |
gomega.Expect(author.Name).To(gomega.Equal("Test Author")) |
| 115 |
gomega.Expect(author.URL).To(gomega.Equal("")) |
| 116 |
gomega.Expect(author.IconURL).To(gomega.Equal("")) |
| 117 |
gomega.Expect(image).To(gomega.BeNil()) |
| 118 |
gomega.Expect(thumbnail).To(gomega.BeNil()) |
| 119 |
gomega.Expect(embedFields).To(gomega.BeEmpty()) |
| 120 |
}) |
| 121 |
|
| 122 |
ginkgo.It("should process embed_author_url field", func() { |
| 123 |
fields := []types.Field{ |
| 124 |
{Key: "embed_author_url", Value: "https://example.com"}, |
| 125 |
} |
| 126 |
author, image, thumbnail, embedFields := processEmbedFields(fields) |
| 127 |
gomega.Expect(author).NotTo(gomega.BeNil()) |
| 128 |
gomega.Expect(author.Name).To(gomega.Equal("")) |
| 129 |
gomega.Expect(author.URL).To(gomega.Equal("https://example.com")) |
| 130 |
gomega.Expect(author.IconURL).To(gomega.Equal("")) |
| 131 |
gomega.Expect(image).To(gomega.BeNil()) |
| 132 |
gomega.Expect(thumbnail).To(gomega.BeNil()) |
| 133 |
gomega.Expect(embedFields).To(gomega.BeEmpty()) |
| 134 |
}) |
| 135 |
|
| 136 |
ginkgo.It("should process embed_author_icon_url field", func() { |
| 137 |
fields := []types.Field{ |
| 138 |
{Key: "embed_author_icon_url", Value: "https://example.com/icon.png"}, |
| 139 |
} |
| 140 |
author, image, thumbnail, embedFields := processEmbedFields(fields) |
| 141 |
gomega.Expect(author).NotTo(gomega.BeNil()) |
| 142 |
gomega.Expect(author.Name).To(gomega.Equal("")) |
| 143 |
gomega.Expect(author.URL).To(gomega.Equal("")) |
| 144 |
gomega.Expect(author.IconURL).To(gomega.Equal("https://example.com/icon.png")) |
| 145 |
gomega.Expect(image).To(gomega.BeNil()) |
| 146 |
gomega.Expect(thumbnail).To(gomega.BeNil()) |
| 147 |
gomega.Expect(embedFields).To(gomega.BeEmpty()) |
| 148 |
}) |
| 149 |
|
| 150 |
ginkgo.It("should process complete embed author with all fields", func() { |
| 151 |
fields := []types.Field{ |
| 152 |
{Key: "embed_author_name", Value: "Test Author"}, |
| 153 |
{Key: "embed_author_url", Value: "https://example.com"}, |
| 154 |
{Key: "embed_author_icon_url", Value: "https://example.com/icon.png"}, |
| 155 |
} |
| 156 |
author, image, thumbnail, embedFields := processEmbedFields(fields) |
| 157 |
gomega.Expect(author).NotTo(gomega.BeNil()) |
| 158 |
gomega.Expect(author.Name).To(gomega.Equal("Test Author")) |
| 159 |
gomega.Expect(author.URL).To(gomega.Equal("https://example.com")) |
| 160 |
gomega.Expect(author.IconURL).To(gomega.Equal("https://example.com/icon.png")) |
| 161 |
gomega.Expect(image).To(gomega.BeNil()) |
| 162 |
gomega.Expect(thumbnail).To(gomega.BeNil()) |
| 163 |
gomega.Expect(embedFields).To(gomega.BeEmpty()) |
| 164 |
}) |
| 165 |
|
| 166 |
ginkgo.It("should process embed_image_url field", func() { |
| 167 |
fields := []types.Field{ |
| 168 |
{Key: "embed_image_url", Value: "https://example.com/image.png"}, |
| 169 |
} |
| 170 |
author, image, thumbnail, embedFields := processEmbedFields(fields) |
| 171 |
gomega.Expect(author).To(gomega.BeNil()) |
| 172 |
gomega.Expect(image).NotTo(gomega.BeNil()) |
| 173 |
gomega.Expect(image.URL).To(gomega.Equal("https://example.com/image.png")) |
| 174 |
gomega.Expect(thumbnail).To(gomega.BeNil()) |
| 175 |
gomega.Expect(embedFields).To(gomega.BeEmpty()) |
| 176 |
}) |
| 177 |
|
| 178 |
ginkgo.It("should process embed_thumbnail_url field", func() { |
| 179 |
fields := []types.Field{ |
| 180 |
{Key: "embed_thumbnail_url", Value: "https://example.com/thumb.png"}, |
| 181 |
} |
| 182 |
author, image, thumbnail, embedFields := processEmbedFields(fields) |
| 183 |
gomega.Expect(author).To(gomega.BeNil()) |
| 184 |
gomega.Expect(image).To(gomega.BeNil()) |
| 185 |
gomega.Expect(thumbnail).NotTo(gomega.BeNil()) |
| 186 |
gomega.Expect(thumbnail.URL).To(gomega.Equal("https://example.com/thumb.png")) |
| 187 |
gomega.Expect(embedFields).To(gomega.BeEmpty()) |
| 188 |
}) |
| 189 |
|
| 190 |
ginkgo.It("should process mixed embed and regular fields", func() { |
| 191 |
fields := []types.Field{ |
| 192 |
{Key: "embed_author_name", Value: "Test Author"}, |
| 193 |
{Key: "embed_image_url", Value: "https://example.com/image.png"}, |
| 194 |
{Key: "regular_field", Value: "regular_value"}, |
| 195 |
{Key: "another_field", Value: "another_value"}, |
| 196 |
} |
| 197 |
author, image, thumbnail, embedFields := processEmbedFields(fields) |
| 198 |
gomega.Expect(author).NotTo(gomega.BeNil()) |
| 199 |
gomega.Expect(author.Name).To(gomega.Equal("Test Author")) |
| 200 |
gomega.Expect(image).NotTo(gomega.BeNil()) |
| 201 |
gomega.Expect(image.URL).To(gomega.Equal("https://example.com/image.png")) |
| 202 |
gomega.Expect(thumbnail).To(gomega.BeNil()) |
| 203 |
gomega.Expect(embedFields).To(gomega.HaveLen(2)) |
| 204 |
gomega.Expect(embedFields[0].Name).To(gomega.Equal("regular_field")) |
| 205 |
gomega.Expect(embedFields[0].Value).To(gomega.Equal("regular_value")) |
| 206 |
gomega.Expect(embedFields[1].Name).To(gomega.Equal("another_field")) |
| 207 |
gomega.Expect(embedFields[1].Value).To(gomega.Equal("another_value")) |
| 208 |
}) |
| 209 |
|
| 210 |
ginkgo.It("should handle duplicate embed fields by using last value", func() { |
| 211 |
fields := []types.Field{ |
| 212 |
{Key: "embed_author_name", Value: "First Author"}, |
| 213 |
{Key: "embed_author_name", Value: "Second Author"}, |
| 214 |
} |
| 215 |
author, image, thumbnail, embedFields := processEmbedFields(fields) |
| 216 |
gomega.Expect(author).NotTo(gomega.BeNil()) |
| 217 |
gomega.Expect(author.Name).To(gomega.Equal("Second Author")) |
| 218 |
gomega.Expect(image).To(gomega.BeNil()) |
| 219 |
gomega.Expect(thumbnail).To(gomega.BeNil()) |
| 220 |
gomega.Expect(embedFields).To(gomega.BeEmpty()) |
| 221 |
}) |
| 222 |
}) |
| 223 |
|
| 224 |
ginkgo.Describe("CreatePayloadFromItems function", func() { |
| 225 |
var colors [types.MessageLevelCount]uint |
| 226 |
|
| 227 |
ginkgo.BeforeEach(func() { |
| 228 |
colors = [types.MessageLevelCount]uint{ |
| 229 |
types.Unknown: 0, |
| 230 |
types.Debug: 0x0000ff, |
| 231 |
types.Info: 0x00ff00, |
| 232 |
types.Warning: 0xffff00, |
| 233 |
types.Error: 0xff0000, |
| 234 |
} |
| 235 |
}) |
| 236 |
|
| 237 |
ginkgo.It("should return error for empty items", func() { |
| 238 |
items := []types.MessageItem{} |
| 239 |
_, err := CreatePayloadFromItems(items, "", colors) |
| 240 |
gomega.Expect(err).To(gomega.MatchError(ErrEmptyMessage)) |
| 241 |
}) |
| 242 |
|
| 243 |
ginkgo.It("should create simple content payload for single plain text item", func() { |
| 244 |
items := []types.MessageItem{ |
| 245 |
{Text: "Simple message"}, |
| 246 |
} |
| 247 |
payload, err := CreatePayloadFromItems(items, "", colors) |
| 248 |
gomega.Expect(err).ToNot(gomega.HaveOccurred()) |
| 249 |
gomega.Expect(payload.Content).To(gomega.Equal("Simple message")) |
| 250 |
gomega.Expect(payload.Embeds).To(gomega.BeEmpty()) |
| 251 |
gomega.Expect(payload.Attachments).To(gomega.BeEmpty()) |
| 252 |
}) |
| 253 |
|
| 254 |
ginkgo.It("should create embed payload when title is provided", func() { |
| 255 |
items := []types.MessageItem{ |
| 256 |
{Text: "Message with title"}, |
| 257 |
} |
| 258 |
payload, err := CreatePayloadFromItems(items, "Test Title", colors) |
| 259 |
gomega.Expect(err).ToNot(gomega.HaveOccurred()) |
| 260 |
gomega.Expect(payload.Content).To(gomega.Equal("")) |
| 261 |
gomega.Expect(payload.Embeds).To(gomega.HaveLen(1)) |
| 262 |
gomega.Expect(payload.Embeds[0].Title).To(gomega.Equal("Test Title")) |
| 263 |
gomega.Expect(payload.Embeds[0].Content).To(gomega.Equal("Message with title")) |
| 264 |
}) |
| 265 |
|
| 266 |
ginkgo.It("should create embed payload when level is set", func() { |
| 267 |
items := []types.MessageItem{ |
| 268 |
{Text: "Info message", Level: types.Info}, |
| 269 |
} |
| 270 |
payload, err := CreatePayloadFromItems(items, "", colors) |
| 271 |
gomega.Expect(err).ToNot(gomega.HaveOccurred()) |
| 272 |
gomega.Expect(payload.Content).To(gomega.Equal("")) |
| 273 |
gomega.Expect(payload.Embeds).To(gomega.HaveLen(1)) |
| 274 |
gomega.Expect(payload.Embeds[0].Color).To(gomega.Equal(uint(0x00ff00))) |
| 275 |
gomega.Expect(payload.Embeds[0].Footer.Text).To(gomega.Equal("Info")) |
| 276 |
}) |
| 277 |
|
| 278 |
ginkgo.It("should create embed payload when timestamp is set", func() { |
| 279 |
timestamp := time.Date(2023, 1, 1, 12, 0, 0, 0, time.UTC) |
| 280 |
items := []types.MessageItem{ |
| 281 |
{Text: "Message with timestamp", Timestamp: timestamp}, |
| 282 |
} |
| 283 |
payload, err := CreatePayloadFromItems(items, "", colors) |
| 284 |
gomega.Expect(err).ToNot(gomega.HaveOccurred()) |
| 285 |
gomega.Expect(payload.Content).To(gomega.Equal("")) |
| 286 |
gomega.Expect(payload.Embeds).To(gomega.HaveLen(1)) |
| 287 |
gomega.Expect(payload.Embeds[0].Timestamp).To(gomega.Equal("2023-01-01T12:00:00Z")) |
| 288 |
}) |
| 289 |
|
| 290 |
ginkgo.It("should create embed payload when embed fields are present", func() { |
| 291 |
items := []types.MessageItem{ |
| 292 |
{ |
| 293 |
Text: "Message with embed fields", |
| 294 |
Fields: []types.Field{ |
| 295 |
{Key: "embed_author_name", Value: "Test Author"}, |
| 296 |
}, |
| 297 |
}, |
| 298 |
} |
| 299 |
payload, err := CreatePayloadFromItems(items, "", colors) |
| 300 |
gomega.Expect(err).ToNot(gomega.HaveOccurred()) |
| 301 |
gomega.Expect(payload.Content).To(gomega.Equal("")) |
| 302 |
gomega.Expect(payload.Embeds).To(gomega.HaveLen(1)) |
| 303 |
gomega.Expect(payload.Embeds[0].Author).NotTo(gomega.BeNil()) |
| 304 |
gomega.Expect(payload.Embeds[0].Author.Name).To(gomega.Equal("Test Author")) |
| 305 |
}) |
| 306 |
|
| 307 |
ginkgo.It("should create embed payload when file is attached", func() { |
| 308 |
items := []types.MessageItem{ |
| 309 |
{ |
| 310 |
Text: "Message with file", |
| 311 |
File: &types.File{Name: "test.txt", Data: []byte("content")}, |
| 312 |
}, |
| 313 |
} |
| 314 |
payload, err := CreatePayloadFromItems(items, "", colors) |
| 315 |
gomega.Expect(err).ToNot(gomega.HaveOccurred()) |
| 316 |
gomega.Expect(payload.Content).To(gomega.Equal("")) |
| 317 |
gomega.Expect(payload.Embeds).To(gomega.HaveLen(1)) |
| 318 |
gomega.Expect(payload.Attachments).To(gomega.HaveLen(1)) |
| 319 |
gomega.Expect(payload.Attachments[0].Filename).To(gomega.Equal("test.txt")) |
| 320 |
gomega.Expect(payload.Attachments[0].ID).To(gomega.Equal(0)) |
| 321 |
}) |
| 322 |
|
| 323 |
ginkgo.It("should handle multiple items with embeds", func() { |
| 324 |
items := []types.MessageItem{ |
| 325 |
{Text: "First message", Level: types.Info}, |
| 326 |
{Text: "Second message", Level: types.Warning}, |
| 327 |
} |
| 328 |
payload, err := CreatePayloadFromItems(items, "Multi Message", colors) |
| 329 |
gomega.Expect(err).ToNot(gomega.HaveOccurred()) |
| 330 |
gomega.Expect(payload.Content).To(gomega.Equal("")) |
| 331 |
gomega.Expect(payload.Embeds).To(gomega.HaveLen(2)) |
| 332 |
gomega.Expect(payload.Embeds[0].Title).To(gomega.Equal("Multi Message")) |
| 333 |
gomega.Expect(payload.Embeds[0].Color).To(gomega.Equal(uint(0x00ff00))) |
| 334 |
gomega.Expect(payload.Embeds[1].Color).To(gomega.Equal(uint(0xffff00))) |
| 335 |
}) |
| 336 |
|
| 337 |
ginkgo.It("should limit embeds to MaxEmbeds", func() { |
| 338 |
items := make([]types.MessageItem, MaxEmbeds+5) |
| 339 |
for i := range items { |
| 340 |
items[i] = types.MessageItem{Text: "Message " + strconv.Itoa(i)} |
| 341 |
} |
| 342 |
|
| 343 |
payload, err := CreatePayloadFromItems(items, "", colors) |
| 344 |
gomega.Expect(err).ToNot(gomega.HaveOccurred()) |
| 345 |
gomega.Expect(payload.Embeds).To(gomega.HaveLen(MaxEmbeds)) |
| 346 |
}) |
| 347 |
|
| 348 |
ginkgo.It("should process embed fields correctly in payload", func() { |
| 349 |
items := []types.MessageItem{ |
| 350 |
{ |
| 351 |
Text: "Message with complex embed", |
| 352 |
Fields: []types.Field{ |
| 353 |
{Key: "embed_author_name", Value: "Author Name"}, |
| 354 |
{Key: "embed_author_url", Value: "https://example.com"}, |
| 355 |
{Key: "embed_image_url", Value: "https://example.com/image.png"}, |
| 356 |
{Key: "embed_thumbnail_url", Value: "https://example.com/thumb.png"}, |
| 357 |
{Key: "regular_field", Value: "regular_value"}, |
| 358 |
}, |
| 359 |
}, |
| 360 |
} |
| 361 |
payload, err := CreatePayloadFromItems(items, "", colors) |
| 362 |
gomega.Expect(err).ToNot(gomega.HaveOccurred()) |
| 363 |
gomega.Expect(payload.Embeds).To(gomega.HaveLen(1)) |
| 364 |
embed := payload.Embeds[0] |
| 365 |
gomega.Expect(embed.Author).NotTo(gomega.BeNil()) |
| 366 |
gomega.Expect(embed.Author.Name).To(gomega.Equal("Author Name")) |
| 367 |
gomega.Expect(embed.Author.URL).To(gomega.Equal("https://example.com")) |
| 368 |
gomega.Expect(embed.Image).NotTo(gomega.BeNil()) |
| 369 |
gomega.Expect(embed.Image.URL).To(gomega.Equal("https://example.com/image.png")) |
| 370 |
gomega.Expect(embed.Thumbnail).NotTo(gomega.BeNil()) |
| 371 |
gomega.Expect(embed.Thumbnail.URL).To(gomega.Equal("https://example.com/thumb.png")) |
| 372 |
gomega.Expect(embed.Fields).To(gomega.HaveLen(1)) |
| 373 |
gomega.Expect(embed.Fields[0].Name).To(gomega.Equal("regular_field")) |
| 374 |
gomega.Expect(embed.Fields[0].Value).To(gomega.Equal("regular_value")) |
| 375 |
}) |
| 376 |
|
| 377 |
ginkgo.It("should handle multiple files with correct IDs", func() { |
| 378 |
items := []types.MessageItem{ |
| 379 |
{ |
| 380 |
Text: "First file", |
| 381 |
File: &types.File{Name: "file1.txt", Data: []byte("content1")}, |
| 382 |
}, |
| 383 |
{ |
| 384 |
Text: "Second file", |
| 385 |
File: &types.File{Name: "file2.txt", Data: []byte("content2")}, |
| 386 |
}, |
| 387 |
} |
| 388 |
payload, err := CreatePayloadFromItems(items, "", colors) |
| 389 |
gomega.Expect(err).ToNot(gomega.HaveOccurred()) |
| 390 |
gomega.Expect(payload.Attachments).To(gomega.HaveLen(2)) |
| 391 |
gomega.Expect(payload.Attachments[0].ID).To(gomega.Equal(0)) |
| 392 |
gomega.Expect(payload.Attachments[0].Filename).To(gomega.Equal("file1.txt")) |
| 393 |
gomega.Expect(payload.Attachments[1].ID).To(gomega.Equal(1)) |
| 394 |
gomega.Expect(payload.Attachments[1].Filename).To(gomega.Equal("file2.txt")) |
| 395 |
}) |
| 396 |
|
| 397 |
ginkgo.It("should handle zero timestamp correctly", func() { |
| 398 |
items := []types.MessageItem{ |
| 399 |
{Text: "Message with zero timestamp", Timestamp: time.Time{}}, |
| 400 |
} |
| 401 |
payload, err := CreatePayloadFromItems(items, "", colors) |
| 402 |
gomega.Expect(err).ToNot(gomega.HaveOccurred()) |
| 403 |
gomega.Expect(payload.Content).To(gomega.Equal("Message with zero timestamp")) |
| 404 |
gomega.Expect(payload.Embeds).To(gomega.BeEmpty()) |
| 405 |
}) |
| 406 |
|
| 407 |
ginkgo.It("should handle unknown level correctly", func() { |
| 408 |
items := []types.MessageItem{ |
| 409 |
{Text: "Message with unknown level", Level: types.Unknown}, |
| 410 |
} |
| 411 |
payload, err := CreatePayloadFromItems(items, "", colors) |
| 412 |
gomega.Expect(err).ToNot(gomega.HaveOccurred()) |
| 413 |
gomega.Expect(payload.Content).To(gomega.Equal("Message with unknown level")) |
| 414 |
gomega.Expect(payload.Embeds).To(gomega.BeEmpty()) |
| 415 |
}) |
| 416 |
|
| 417 |
ginkgo.It("should handle out of bounds level correctly", func() { |
| 418 |
items := []types.MessageItem{ |
| 419 |
{Text: "Message with invalid level", Level: types.MessageLevel(10)}, |
| 420 |
} |
| 421 |
payload, err := CreatePayloadFromItems(items, "", colors) |
| 422 |
gomega.Expect(err).ToNot(gomega.HaveOccurred()) |
| 423 |
gomega.Expect(payload.Content).To(gomega.Equal("")) |
| 424 |
gomega.Expect(payload.Embeds).To(gomega.HaveLen(1)) |
| 425 |
gomega.Expect(payload.Embeds[0].Color).To(gomega.Equal(uint(0))) |
| 426 |
}) |
| 427 |
}) |
| 428 |
}) |