Make tests more resilient

This commit is contained in:
Tyrrrz 2023-09-28 19:18:52 +03:00
parent c466c17793
commit fbfff4e51f
5 changed files with 32 additions and 15 deletions

View file

@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using System.Threading.Tasks;
using AngleSharp.Dom;
using DiscordChatExporter.Cli.Tests.Infra;
@ -27,7 +28,11 @@ public class HtmlAttachmentSpecs
.Select(e => e.GetAttribute("href"))
.Should()
.Contain(
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt"
u =>
u.StartsWith(
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt",
StringComparison.Ordinal
)
);
}
@ -48,7 +53,11 @@ public class HtmlAttachmentSpecs
.Select(e => e.GetAttribute("src"))
.Should()
.Contain(
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png"
u =>
u.StartsWith(
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png",
StringComparison.Ordinal
)
);
}
@ -69,7 +78,7 @@ public class HtmlAttachmentSpecs
var videoUrl = message.QuerySelector("video source")?.GetAttribute("src");
videoUrl
.Should()
.Be(
.StartWith(
"https://cdn.discordapp.com/attachments/885587741654536192/885655761512968233/file_example_MP4_640_3MG.mp4"
);
}
@ -91,7 +100,7 @@ public class HtmlAttachmentSpecs
var audioUrl = message.QuerySelector("audio source")?.GetAttribute("src");
audioUrl
.Should()
.Be(
.StartWith(
"https://cdn.discordapp.com/attachments/885587741654536192/885656175348187146/file_example_MP3_1MG.mp3"
);
}

View file

@ -145,7 +145,7 @@ public class HtmlEmbedSpecs
// Assert
var iframeUrl = message.QuerySelector("iframe")?.GetAttribute("src");
iframeUrl.Should().Be("https://open.spotify.com/embed/track/1LHZMWefF9502NPfArRfvP");
iframeUrl.Should().StartWith("https://open.spotify.com/embed/track/1LHZMWefF9502NPfArRfvP");
}
[Fact]
@ -161,7 +161,7 @@ public class HtmlEmbedSpecs
// Assert
var iframeUrl = message.QuerySelector("iframe")?.GetAttribute("src");
iframeUrl.Should().Be("https://www.youtube.com/embed/qOWW4OlgbvE");
iframeUrl.Should().StartWith("https://www.youtube.com/embed/qOWW4OlgbvE");
}
[Fact]

View file

@ -19,7 +19,7 @@ public class HtmlStickerSpecs
// Assert
var stickerUrl = message.QuerySelector("[title='rock'] img")?.GetAttribute("src");
stickerUrl.Should().Be("https://cdn.discordapp.com/stickers/904215665597120572.png");
stickerUrl.Should().StartWith("https://cdn.discordapp.com/stickers/904215665597120572.png");
}
[Fact]
@ -35,6 +35,9 @@ public class HtmlStickerSpecs
var stickerUrl = message
.QuerySelector("[title='Yikes'] [data-source]")
?.GetAttribute("data-source");
stickerUrl.Should().Be("https://cdn.discordapp.com/stickers/816087132447178774.json");
stickerUrl
.Should()
.StartWith("https://cdn.discordapp.com/stickers/816087132447178774.json");
}
}

View file

@ -28,9 +28,10 @@ public class JsonAttachmentSpecs
.GetProperty("url")
.GetString()
.Should()
.Be(
.StartWith(
"https://cdn.discordapp.com/attachments/885587741654536192/885587844964417596/Test.txt"
);
attachments[0].GetProperty("fileName").GetString().Should().Be("Test.txt");
attachments[0].GetProperty("fileSizeBytes").GetInt64().Should().Be(11);
}
@ -54,9 +55,10 @@ public class JsonAttachmentSpecs
.GetProperty("url")
.GetString()
.Should()
.Be(
.StartWith(
"https://cdn.discordapp.com/attachments/885587741654536192/885654862430359613/bird-thumbnail.png"
);
attachments[0].GetProperty("fileName").GetString().Should().Be("bird-thumbnail.png");
attachments[0].GetProperty("fileSizeBytes").GetInt64().Should().Be(466335);
}
@ -80,14 +82,16 @@ public class JsonAttachmentSpecs
.GetProperty("url")
.GetString()
.Should()
.Be(
.StartWith(
"https://cdn.discordapp.com/attachments/885587741654536192/885655761512968233/file_example_MP4_640_3MG.mp4"
);
attachments[0]
.GetProperty("fileName")
.GetString()
.Should()
.Be("file_example_MP4_640_3MG.mp4");
attachments[0].GetProperty("fileSizeBytes").GetInt64().Should().Be(3114374);
}
@ -110,9 +114,10 @@ public class JsonAttachmentSpecs
.GetProperty("url")
.GetString()
.Should()
.Be(
.StartWith(
"https://cdn.discordapp.com/attachments/885587741654536192/885656175348187146/file_example_MP3_1MG.mp3"
);
attachments[0].GetProperty("fileName").GetString().Should().Be("file_example_MP3_1MG.mp3");
attachments[0].GetProperty("fileSizeBytes").GetInt64().Should().Be(1087849);
}

View file

@ -28,7 +28,7 @@ public class JsonStickerSpecs
.GetProperty("sourceUrl")
.GetString()
.Should()
.Be("https://cdn.discordapp.com/stickers/904215665597120572.png");
.StartWith("https://cdn.discordapp.com/stickers/904215665597120572.png");
}
[Fact]
@ -50,6 +50,6 @@ public class JsonStickerSpecs
.GetProperty("sourceUrl")
.GetString()
.Should()
.Be("https://cdn.discordapp.com/stickers/816087132447178774.json");
.StartWith("https://cdn.discordapp.com/stickers/816087132447178774.json");
}
}