2021-09-09 18:55:28 -04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-02-11 16:12:15 -05:00
|
|
|
|
using DiscordChatExporter.Cli.Tests.Infra;
|
2021-09-09 18:55:28 -04:00
|
|
|
|
using DiscordChatExporter.Core.Discord;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
2023-02-06 08:57:08 -05:00
|
|
|
|
namespace DiscordChatExporter.Cli.Tests.Specs;
|
2021-12-08 16:50:21 -05:00
|
|
|
|
|
2023-02-09 11:44:24 -05:00
|
|
|
|
public class JsonAttachmentSpecs
|
2021-09-09 18:55:28 -04:00
|
|
|
|
{
|
2021-12-08 16:50:21 -05:00
|
|
|
|
[Fact]
|
2023-05-20 00:09:19 -04:00
|
|
|
|
public async Task I_can_export_a_channel_that_contains_a_message_with_a_generic_attachment()
|
2021-12-08 16:50:21 -05:00
|
|
|
|
{
|
|
|
|
|
// Act
|
2023-02-11 16:12:15 -05:00
|
|
|
|
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
2021-12-08 16:50:21 -05:00
|
|
|
|
ChannelIds.AttachmentTestCases,
|
|
|
|
|
Snowflake.Parse("885587844989612074")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
message.GetProperty("content").GetString().Should().Be("Generic file attachment");
|
|
|
|
|
|
2022-06-29 14:43:43 -04:00
|
|
|
|
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
2021-12-08 16:50:21 -05:00
|
|
|
|
attachments.Should().HaveCount(1);
|
2023-05-20 00:09:19 -04:00
|
|
|
|
|
2023-08-22 14:17:19 -04:00
|
|
|
|
attachments[0]
|
|
|
|
|
.GetProperty("url")
|
|
|
|
|
.GetString()
|
|
|
|
|
.Should()
|
2023-09-28 12:18:52 -04:00
|
|
|
|
.StartWith(
|
2023-08-22 14:17:19 -04:00
|
|
|
|
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt"
|
|
|
|
|
);
|
2023-09-28 12:18:52 -04:00
|
|
|
|
|
2023-05-20 00:09:19 -04:00
|
|
|
|
attachments[0].GetProperty("fileName").GetString().Should().Be("Test.txt");
|
|
|
|
|
attachments[0].GetProperty("fileSizeBytes").GetInt64().Should().Be(11);
|
2021-12-08 16:50:21 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2023-05-20 00:09:19 -04:00
|
|
|
|
public async Task I_can_export_a_channel_that_contains_a_message_with_an_image_attachment()
|
2021-12-08 16:50:21 -05:00
|
|
|
|
{
|
|
|
|
|
// Act
|
2023-02-11 16:12:15 -05:00
|
|
|
|
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
2021-12-08 16:50:21 -05:00
|
|
|
|
ChannelIds.AttachmentTestCases,
|
|
|
|
|
Snowflake.Parse("885654862656843786")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
message.GetProperty("content").GetString().Should().Be("Image attachment");
|
|
|
|
|
|
2022-06-29 14:43:43 -04:00
|
|
|
|
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
2021-12-08 16:50:21 -05:00
|
|
|
|
attachments.Should().HaveCount(1);
|
2023-05-20 00:09:19 -04:00
|
|
|
|
|
2023-08-22 14:17:19 -04:00
|
|
|
|
attachments[0]
|
|
|
|
|
.GetProperty("url")
|
|
|
|
|
.GetString()
|
|
|
|
|
.Should()
|
2023-09-28 12:18:52 -04:00
|
|
|
|
.StartWith(
|
2023-08-22 14:17:19 -04:00
|
|
|
|
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png"
|
|
|
|
|
);
|
2023-09-28 12:18:52 -04:00
|
|
|
|
|
2023-05-20 00:09:19 -04:00
|
|
|
|
attachments[0].GetProperty("fileName").GetString().Should().Be("bird-thumbnail.png");
|
|
|
|
|
attachments[0].GetProperty("fileSizeBytes").GetInt64().Should().Be(466335);
|
2021-12-08 16:50:21 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2023-05-20 00:09:19 -04:00
|
|
|
|
public async Task I_can_export_a_channel_that_contains_a_message_with_a_video_attachment()
|
2021-12-08 16:50:21 -05:00
|
|
|
|
{
|
|
|
|
|
// Act
|
2023-02-11 16:12:15 -05:00
|
|
|
|
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
2021-12-08 16:50:21 -05:00
|
|
|
|
ChannelIds.AttachmentTestCases,
|
|
|
|
|
Snowflake.Parse("885655761919836171")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
message.GetProperty("content").GetString().Should().Be("Video attachment");
|
|
|
|
|
|
2022-06-29 14:43:43 -04:00
|
|
|
|
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
2021-12-08 16:50:21 -05:00
|
|
|
|
attachments.Should().HaveCount(1);
|
2023-05-20 00:09:19 -04:00
|
|
|
|
|
2023-08-22 14:17:19 -04:00
|
|
|
|
attachments[0]
|
|
|
|
|
.GetProperty("url")
|
|
|
|
|
.GetString()
|
|
|
|
|
.Should()
|
2023-09-28 12:18:52 -04:00
|
|
|
|
.StartWith(
|
2023-08-22 14:17:19 -04:00
|
|
|
|
"https://cdn.discordapp.com/attachments/885587741654536192/885655761512968233/file_example_MP4_640_3MG.mp4"
|
|
|
|
|
);
|
2023-09-28 12:18:52 -04:00
|
|
|
|
|
2023-08-22 14:17:19 -04:00
|
|
|
|
attachments[0]
|
|
|
|
|
.GetProperty("fileName")
|
|
|
|
|
.GetString()
|
|
|
|
|
.Should()
|
|
|
|
|
.Be("file_example_MP4_640_3MG.mp4");
|
2023-09-28 12:18:52 -04:00
|
|
|
|
|
2023-05-20 00:09:19 -04:00
|
|
|
|
attachments[0].GetProperty("fileSizeBytes").GetInt64().Should().Be(3114374);
|
2021-12-08 16:50:21 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2023-05-20 00:09:19 -04:00
|
|
|
|
public async Task I_can_export_a_channel_that_contains_a_message_with_an_audio_attachment()
|
2021-09-09 18:55:28 -04:00
|
|
|
|
{
|
2021-12-08 16:50:21 -05:00
|
|
|
|
// Act
|
2023-02-11 16:12:15 -05:00
|
|
|
|
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
2021-12-08 16:50:21 -05:00
|
|
|
|
ChannelIds.AttachmentTestCases,
|
|
|
|
|
Snowflake.Parse("885656175620808734")
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
message.GetProperty("content").GetString().Should().Be("Audio attachment");
|
|
|
|
|
|
2022-06-29 14:43:43 -04:00
|
|
|
|
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
2021-12-08 16:50:21 -05:00
|
|
|
|
attachments.Should().HaveCount(1);
|
2023-05-20 00:09:19 -04:00
|
|
|
|
|
2023-08-22 14:17:19 -04:00
|
|
|
|
attachments[0]
|
|
|
|
|
.GetProperty("url")
|
|
|
|
|
.GetString()
|
|
|
|
|
.Should()
|
2023-09-28 12:18:52 -04:00
|
|
|
|
.StartWith(
|
2023-08-22 14:17:19 -04:00
|
|
|
|
"https://cdn.discordapp.com/attachments/885587741654536192/885656175348187146/file_example_MP3_1MG.mp3"
|
|
|
|
|
);
|
2023-09-28 12:18:52 -04:00
|
|
|
|
|
2023-05-20 00:09:19 -04:00
|
|
|
|
attachments[0].GetProperty("fileName").GetString().Should().Be("file_example_MP3_1MG.mp3");
|
|
|
|
|
attachments[0].GetProperty("fileSizeBytes").GetInt64().Should().Be(1087849);
|
2021-09-09 18:55:28 -04:00
|
|
|
|
}
|
2023-08-22 14:17:19 -04:00
|
|
|
|
}
|