-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for the specific network formatters
- Loading branch information
1 parent
ec89116
commit b6695bd
Showing
5 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
open-social-distributor-app/src/DistributorLib/Post/Formatters/PostFormatVariantFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
open-social-distributor-app/test/DistributorLib.Tests/Helpers/MessageTestHelpers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace DistributorLib.Tests.Helpers; | ||
|
||
public static class MessageTestHelpers | ||
{ | ||
public static string RemoveHashTags(this string message) | ||
=> string.Join(' ', message.Split(' ').Where(w => !w.StartsWith('#'))); | ||
} |
62 changes: 62 additions & 0 deletions
62
open-social-distributor-app/test/DistributorLib.Tests/NetworkPostFormatterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System.Reflection; | ||
using DistributorLib.Input; | ||
using DistributorLib.Network; | ||
using DistributorLib.Post.Formatters; | ||
using DistributorLib.Tests.Helpers; | ||
|
||
namespace DistributorLib.Tests; | ||
|
||
public class NetworkPostFormatterTests | ||
{ | ||
[Fact] | ||
public void ProjectPlacesTestFilesInTheRightPlace() | ||
{ | ||
var runPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
Assert.False(string.IsNullOrWhiteSpace(runPath)); | ||
var testFilePath = Path.Combine(runPath, "TestData", "release-announcement-v0.1.jsonc"); | ||
Assert.False(string.IsNullOrWhiteSpace(testFilePath)); | ||
Assert.True(File.Exists(testFilePath), $"Test file not found at {testFilePath}"); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Hello world! #hello #lovely #world", "Hello world!")] | ||
public void RemoveHashTags_RemovesHashTags(string input, string expected) | ||
{ | ||
var result = input.RemoveHashTags(); | ||
Assert.Equal(expected, result); | ||
} | ||
|
||
[Theory] | ||
[InlineData(NetworkType.LinkedIn, 1, new[] { | ||
@"🎉 Announcing release 0.1 of Open Social Distributor - a command line tool that can create posts and threads across a variety of social networks. | ||
🆓 It's open source and free - and you're welcome to contribute to it if you fancy getting involved. | ||
🧵 This post (and thread if you're looking at it on Mastodon!) is an early test for the Open Social Distributor... 🤞 https://instantiator.dev/open-social-distributor/" })] | ||
[InlineData(NetworkType.Mastodon, 3, new[] { | ||
"🎉 Announcing release 0.1 of Open Social Distributor - a command line tool that can create posts and threads across a variety of social networks. https://instantiator.dev/open-social-distributor/ /1", | ||
"🆓 It's open source and free - and you're welcome to contribute to it if you fancy getting involved. /2", | ||
"🧵 This post (and thread if you're looking at it on Mastodon!) is an early test for the Open Social Distributor... 🤞 /3" })] | ||
[InlineData(NetworkType.Discord, 3, new[] { | ||
"🎉 Announcing release 0.1 of Open Social Distributor - a command line tool that can create posts and threads across a variety of social networks. https://instantiator.dev/open-social-distributor/", | ||
"🆓 It's open source and free - and you're welcome to contribute to it if you fancy getting involved.", | ||
"🧵 This post (and thread if you're looking at it on Mastodon!) is an early test for the Open Social Distributor... 🤞" })] | ||
public void LinkedInPostFormatter_CorrectlyFormatsAnnouncement(NetworkType network, int expectedMessages, IEnumerable<string> expectedText) | ||
{ | ||
var runPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | ||
var json = File.ReadAllText(Path.Combine(runPath!, "TestData", "release-announcement-v0.1.jsonc")); | ||
var reader = new PostListReader(); | ||
var list = reader.ReadJson(json); | ||
var message = list!.ToSocialMessages().Single(); | ||
|
||
var formatter = PostFormatVariantFactory.For(network); | ||
var result = formatter.FormatText(message); | ||
|
||
Assert.Equal(expectedMessages, result.Count()); | ||
|
||
var expectedMinusHashTags = expectedText.Select(m => m.RemoveHashTags().Trim()); | ||
var resultMinusHashTags = result.Select(m => m.RemoveHashTags().Trim()); | ||
|
||
Assert.Equal(expectedMinusHashTags, resultMinusHashTags); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
open-social-distributor-app/test/TestData/release-announcement-v0.1.jsonc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"posts": [ | ||
{ | ||
"parts": [ | ||
{ "part": "Text", "content": { "any": "🎉 Announcing release 0.1 of Open Social Distributor - a command line tool that can create posts and threads across a variety of social networks. $$ 🆓 It's open source and free - and you're welcome to contribute to it if you fancy getting involved. $$ 🧵 This post (and thread if you're looking at it on Mastodon!) is an early test for the Open Social Distributor... 🤞"} }, | ||
{ "part": "Link", "content": { "any": "https://instantiator.dev/open-social-distributor/" } }, | ||
{ "part": "Tag", "content": { "any": "SocialNetworks" } }, | ||
{ "part": "Tag", "content": { "any": "SocialMedia" } }, | ||
{ "part": "Tag", "content": { "any": "OpenSocialDistributor" } }, | ||
{ "part": "Tag", "content": { "any": "OSD" } }, | ||
{ "part": "Tag", "content": { "any": "Tool" } }, | ||
{ "part": "Tag", "content": { "any": "CLI" } }, | ||
{ "part": "Tag", "content": { "any": "OpenSource" } }, | ||
{ "part": "Tag", "content": { "any": "OSS" } } | ||
], // list of parts | ||
"images": [ | ||
{ | ||
"uri": "file://sample-messages/social-distributor-icon.png", | ||
"description": "The icon for Open Social Distributor - clear arrows in the 4 ordinal directions overlay a cloud of colours." | ||
}, | ||
{ | ||
"uri": "file://sample-messages/2023-10-08-capabilities.png", | ||
"description": "A table showing the supported social networks: Mastodon, Discord, Facebook and LinkedIn all appear. All support threads, links, tags, and images - although Facebook and LinkedIn have not yet had their threading capability fully tested." | ||
} | ||
] // list of images | ||
} // individual message | ||
] // list of posts | ||
} |