68 lines
2.9 KiB
C#
68 lines
2.9 KiB
C#
using PrivaPub.Federation.Actors;
|
|||
|
|
using PrivaPub.Federation.Objects;
|
||
|
|
|
||
|
|
using System.Text.Json;
|
||
|
|
using System.Text.Json.Nodes;
|
||
|
|
|
||
|
|
namespace PrivaPub.Tests.Federation
|
||
|
|
{
|
||
|
|
public class FlairTests
|
||
|
|
{
|
||
|
|
[Fact]
|
||
|
|
public void A_lemmy_posts_flair_is_described_by_its_community()
|
||
|
|
{
|
||
|
|
using var group = JsonDocument.Parse("""
|
||
|
|
{
|
||
|
|
"id": "https://lemmy.example/c/tenforward", "type": "Group", "preferredUsername": "tenforward", "inbox": "https://lemmy.example/c/tenforward/inbox",
|
||
|
|
"attributedTo": "https://lemmy.example/c/tenforward/moderators",
|
||
|
|
"tag": [{ "type": "CommunityPostTag", "id": "https://lemmy.example/c/tenforward/tag/news", "preferredUsername": "news",
|
||
|
|
"name": "News", "content": "What happened", "color": "color03" }]
|
||
|
|
}
|
||
|
|
""");
|
||
|
|
var community = ActorDocument.Parse(group.RootElement);
|
||
|
|
var page = NoteParser.Parse(JsonNode.Parse("""
|
||
|
|
{
|
||
|
|
"id": "https://lemmy.example/post/1", "type": "Page", "name": "Big news", "attributedTo": "https://lemmy.example/u/bo",
|
||
|
|
"tag": [{ "type": "CommunityPostTag", "id": "https://lemmy.example/c/tenforward/tag/news", "preferredUsername": "news" },
|
||
|
|
{ "type": "Mention", "href": "https://lemmy.example/c/tenforward", "name": "@tenforward@lemmy.example" }]
|
||
|
|
}
|
||
|
|
"""));
|
||
|
|
|
||
|
|
Assert.Equal("https://lemmy.example/c/tenforward/moderators", community.Moderators);
|
||
|
|
var flair = Assert.Single(ObjectShapes.Described(page.Flairs, community.Flairs));
|
||
|
|
Assert.Equal("News", flair.Name);
|
||
|
|
Assert.Equal("news", flair.Slug);
|
||
|
|
Assert.Equal("color03", flair.Color);
|
||
|
|
Assert.Equal("What happened", flair.Description);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void Reads_piefeds_flairs_in_both_dialects_and_its_older_community_list()
|
||
|
|
{
|
||
|
|
var post = NoteParser.Parse(JsonNode.Parse("""
|
||
|
|
{
|
||
|
|
"id": "https://piefed.example/post/9", "type": "Page", "name": "A question", "attributedTo": "https://piefed.example/u/pf",
|
||
|
|
"tag": [{ "type": "lemmy:CommunityTag", "id": "https://piefed.example/c/ask/tag/3", "display_name": "Solved",
|
||
|
|
"text_color": "#ffffff", "background_color": "#2e7d32", "blur_images": false },
|
||
|
|
{ "type": "Hashtag", "href": "https://piefed.example/tag/q", "name": "#q" }]
|
||
|
|
}
|
||
|
|
"""));
|
||
|
|
using var group = JsonDocument.Parse("""
|
||
|
|
{
|
||
|
|
"id": "https://piefed.example/c/ask", "type": "Group", "preferredUsername": "ask", "inbox": "https://piefed.example/c/ask/inbox",
|
||
|
|
"lemmy:tagsForPosts": [{ "type": "lemmy:CommunityTag", "id": "https://piefed.example/c/ask/tag/4", "display_name": "Spoiler",
|
||
|
|
"text_color": "#000", "background_color": "red; background: url(x)", "blur_images": true }]
|
||
|
|
}
|
||
|
|
""");
|
||
|
|
|
||
|
|
var solved = Assert.Single(post.Flairs);
|
||
|
|
Assert.Equal("Solved", solved.Name);
|
||
|
|
Assert.Equal("#2e7d32", solved.BackgroundColor);
|
||
|
|
Assert.Equal("q", Assert.Single(post.Tags));
|
||
|
|
var spoiler = Assert.Single(ActorDocument.Parse(group.RootElement).Flairs);
|
||
|
|
Assert.True(spoiler.BlurImages);
|
||
|
|
Assert.Equal("#000", spoiler.TextColor);
|
||
|
|
Assert.Null(spoiler.BackgroundColor);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|