32 lines
1.3 KiB
C#
32 lines
1.3 KiB
C#
using PrivaPub.Federation.Rendering;
|
|||
|
|
|
||
|
|
using System.Text.Json.Nodes;
|
||
|
|
|
||
|
|
namespace PrivaPub.Tests.Federation
|
||
|
|
{
|
||
|
|
// The @context on everything we send. Readers that expand JSON-LD 1.0 (Smithereen) refuse a whole document over one
|
||
|
|
// term only 1.1 knows, so every term stays within 1.0
|
||
|
|
public class ContextTests
|
||
|
|
{
|
||
|
|
static readonly string[] Containers10 = ["@list", "@set", "@index", "@language"];
|
||
|
|
static readonly string[] Keywords11 = ["@version", "@protected", "@propagate", "@import", "@nest", "@prefix", "@context", "@direction", "@json"];
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void Every_term_is_json_ld_1_0()
|
||
|
|
{
|
||
|
|
var terms = ActivityPubRenderer.Context().OfType<JsonObject>().Single();
|
||
|
|
|
||
|
|
foreach (var (name, definition) in terms)
|
||
|
|
{
|
||
|
|
if (definition is not JsonObject term)
|
||
|
|
continue;
|
||
|
|
if (term["@container"] is JsonValue container)
|
||
|
|
Assert.True(Containers10.Contains(container.GetValue<string>()), $"{name}: @container {container} is JSON-LD 1.1");
|
||
|
|
Assert.True(term["@container"] is null or JsonValue, $"{name}: an array of containers is JSON-LD 1.1");
|
||
|
|
Assert.DoesNotContain(term.Select(p => p.Key), Keywords11.Contains);
|
||
|
|
Assert.NotEqual("@json", term["@type"]?.GetValue<string>());
|
||
|
|
}
|
||
|
|
Assert.DoesNotContain(terms.Select(p => p.Key), Keywords11.Contains);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|