mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2025-05-25 04:04:22 -04:00
Add tests for attachments
This commit is contained in:
parent
44f64a2cb3
commit
402b5cc7d0
3 changed files with 196 additions and 0 deletions
|
@ -0,0 +1,93 @@
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AngleSharp.Dom;
|
||||||
|
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||||
|
using DiscordChatExporter.Cli.Tests.TestData;
|
||||||
|
using DiscordChatExporter.Core.Discord;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Cli.Tests.Specs.HtmlWriting
|
||||||
|
{
|
||||||
|
public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task Message_with_a_generic_attachment_is_rendered_correctly()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||||
|
ChannelIds.AttachmentTestCases,
|
||||||
|
Snowflake.Parse("885587844989612074")
|
||||||
|
);
|
||||||
|
|
||||||
|
var fileUrl = message.QuerySelector("a")?.GetAttribute("href");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
message.Text().Should().ContainAll(
|
||||||
|
"Generic file attachment",
|
||||||
|
"Test.txt",
|
||||||
|
"11 bytes"
|
||||||
|
);
|
||||||
|
|
||||||
|
fileUrl.Should().StartWithEquivalentOf(
|
||||||
|
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Message_with_an_image_attachment_is_rendered_correctly()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||||
|
ChannelIds.AttachmentTestCases,
|
||||||
|
Snowflake.Parse("885654862656843786")
|
||||||
|
);
|
||||||
|
|
||||||
|
var imageUrl = message.QuerySelector("img")?.GetAttribute("src");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
message.Text().Should().Contain("Image attachment");
|
||||||
|
|
||||||
|
imageUrl.Should().StartWithEquivalentOf(
|
||||||
|
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Message_with_a_video_attachment_is_rendered_correctly()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||||
|
ChannelIds.AttachmentTestCases,
|
||||||
|
Snowflake.Parse("885655761919836171")
|
||||||
|
);
|
||||||
|
|
||||||
|
var videoUrl = message.QuerySelector("video source")?.GetAttribute("src");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
message.Text().Should().Contain("Video attachment");
|
||||||
|
|
||||||
|
videoUrl.Should().StartWithEquivalentOf(
|
||||||
|
"https://cdn.discordapp.com/attachments/885587741654536192/885655761512968233/file_example_MP4_640_3MG.mp4"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Message_with_an_audio_attachment_is_rendered_correctly()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var message = await ExportWrapper.GetMessageAsHtmlAsync(
|
||||||
|
ChannelIds.AttachmentTestCases,
|
||||||
|
Snowflake.Parse("885656175620808734")
|
||||||
|
);
|
||||||
|
|
||||||
|
var audioUrl = message.QuerySelector("audio source")?.GetAttribute("src");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
message.Text().Should().Contain("Audio attachment");
|
||||||
|
|
||||||
|
audioUrl.Should().StartWithEquivalentOf(
|
||||||
|
"https://cdn.discordapp.com/attachments/885587741654536192/885656175348187146/file_example_MP3_1MG.mp3"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,101 @@
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using DiscordChatExporter.Cli.Tests.Fixtures;
|
||||||
|
using DiscordChatExporter.Cli.Tests.TestData;
|
||||||
|
using DiscordChatExporter.Core.Discord;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace DiscordChatExporter.Cli.Tests.Specs.JsonWriting
|
||||||
|
{
|
||||||
|
public record AttachmentSpecs(ExportWrapperFixture ExportWrapper) : IClassFixture<ExportWrapperFixture>
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public async Task Message_with_a_generic_attachment_is_rendered_correctly()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||||
|
ChannelIds.AttachmentTestCases,
|
||||||
|
Snowflake.Parse("885587844989612074")
|
||||||
|
);
|
||||||
|
|
||||||
|
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
message.GetProperty("content").GetString().Should().Be("Generic file attachment");
|
||||||
|
|
||||||
|
attachments.Should().HaveCount(1);
|
||||||
|
attachments.Single().GetProperty("url").GetString().Should().StartWithEquivalentOf(
|
||||||
|
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt"
|
||||||
|
);
|
||||||
|
attachments.Single().GetProperty("fileName").GetString().Should().Be("Test.txt");
|
||||||
|
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(11);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Message_with_an_image_attachment_is_rendered_correctly()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||||
|
ChannelIds.AttachmentTestCases,
|
||||||
|
Snowflake.Parse("885654862656843786")
|
||||||
|
);
|
||||||
|
|
||||||
|
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
message.GetProperty("content").GetString().Should().Be("Image attachment");
|
||||||
|
|
||||||
|
attachments.Should().HaveCount(1);
|
||||||
|
attachments.Single().GetProperty("url").GetString().Should().StartWithEquivalentOf(
|
||||||
|
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png"
|
||||||
|
);
|
||||||
|
attachments.Single().GetProperty("fileName").GetString().Should().Be("bird-thumbnail.png");
|
||||||
|
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(466335);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Message_with_a_video_attachment_is_rendered_correctly()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||||
|
ChannelIds.AttachmentTestCases,
|
||||||
|
Snowflake.Parse("885655761919836171")
|
||||||
|
);
|
||||||
|
|
||||||
|
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
message.GetProperty("content").GetString().Should().Be("Video attachment");
|
||||||
|
|
||||||
|
attachments.Should().HaveCount(1);
|
||||||
|
attachments.Single().GetProperty("url").GetString().Should().StartWithEquivalentOf(
|
||||||
|
"https://cdn.discordapp.com/attachments/885587741654536192/885655761512968233/file_example_MP4_640_3MG.mp4"
|
||||||
|
);
|
||||||
|
attachments.Single().GetProperty("fileName").GetString().Should().Be("file_example_MP4_640_3MG.mp4");
|
||||||
|
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(3114374);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Message_with_an_audio_attachment_is_rendered_correctly()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var message = await ExportWrapper.GetMessageAsJsonAsync(
|
||||||
|
ChannelIds.AttachmentTestCases,
|
||||||
|
Snowflake.Parse("885656175620808734")
|
||||||
|
);
|
||||||
|
|
||||||
|
var attachments = message.GetProperty("attachments").EnumerateArray().ToArray();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
message.GetProperty("content").GetString().Should().Be("Audio attachment");
|
||||||
|
|
||||||
|
attachments.Should().HaveCount(1);
|
||||||
|
attachments.Single().GetProperty("url").GetString().Should().StartWithEquivalentOf(
|
||||||
|
"https://cdn.discordapp.com/attachments/885587741654536192/885656175348187146/file_example_MP3_1MG.mp3"
|
||||||
|
);
|
||||||
|
attachments.Single().GetProperty("fileName").GetString().Should().Be("file_example_MP3_1MG.mp3");
|
||||||
|
attachments.Single().GetProperty("fileSizeBytes").GetInt64().Should().Be(1087849);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,8 @@ namespace DiscordChatExporter.Cli.Tests.TestData
|
||||||
{
|
{
|
||||||
public static class ChannelIds
|
public static class ChannelIds
|
||||||
{
|
{
|
||||||
|
public static Snowflake AttachmentTestCases { get; } = Snowflake.Parse("885587741654536192");
|
||||||
|
|
||||||
public static Snowflake DateRangeTestCases { get; } = Snowflake.Parse("866674248747319326");
|
public static Snowflake DateRangeTestCases { get; } = Snowflake.Parse("866674248747319326");
|
||||||
|
|
||||||
public static Snowflake EmbedTestCases { get; } = Snowflake.Parse("866472452459462687");
|
public static Snowflake EmbedTestCases { get; } = Snowflake.Parse("866472452459462687");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue