Skip to content

Commit

Permalink
Always calculate edit token.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Aug 10, 2022
1 parent 2a4105c commit a8da5c6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,20 @@ public async Task<IReadOnlyList<IEnrichedAssetEntity>> EnrichAsync(IEnumerable<I
await EnrichTagsAsync(results, ct);

EnrichWithMetadataText(results);

if (!context.IsFrontendClient)
{
ComputeTokens(results);
}
EnrichWithEditTokens(results);
}

return results;
}
}

private void ComputeTokens(IEnumerable<IEnrichedAssetEntity> assets)
private void EnrichWithEditTokens(IEnumerable<IEnrichedAssetEntity> assets)
{
var url = urlGenerator.Root();

foreach (var asset in assets)
{
// We have to use these short names here because they are later read like this.
var token = new
{
a = asset.AppId.Name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ public CalculateTokens(IUrlGenerator urlGenerator, IJsonSerializer serializer)
public Task EnrichAsync(Context context, IEnumerable<ContentEntity> contents, ProvideSchema schemas,
CancellationToken ct)
{
if (context.IsFrontendClient)
{
return Task.CompletedTask;
}

var url = urlGenerator.Root();

foreach (var content in contents)
{
// We have to use these short names here because they are later read like this.
var token = new
{
a = content.AppId.Name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public async Task Should_enrich_multiple_assets_with_tag_names()
}

[Fact]
public async Task Should_not_compute_ui_tokens_for_frontend()
public async Task Should_also_compute_ui_tokens_for_frontend()
{
var source = new AssetEntity
{
Expand All @@ -182,10 +182,10 @@ public async Task Should_not_compute_ui_tokens_for_frontend()

var result = await sut.EnrichAsync(new[] { source }, new Context(Mocks.FrontendUser(), Mocks.App(appId)), ct);

Assert.Null(result[0].EditToken);
Assert.NotNull(result[0].EditToken);

A.CallTo(() => urlGenerator.Root())
.MustNotHaveHappened();
.MustHaveHappened();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@ public CalculateTokensTests()
}

[Fact]
public async Task Should_not_compute_ui_tokens_for_frontend()
public async Task Should_compute_ui_tokens()
{
var source = CreateContent();

await sut.EnrichAsync(new Context(Mocks.FrontendUser(), Mocks.App(appId)), new[] { source }, schemaProvider, default);
await sut.EnrichAsync(requestContext, new[] { source }, schemaProvider, default);

Assert.Null(source.EditToken);
Assert.NotNull(source.EditToken);

A.CallTo(() => urlGenerator.Root())
.MustNotHaveHappened();
.MustHaveHappened();
}

[Fact]
public async Task Should_compute_ui_tokens()
public async Task Should_also_compute_ui_tokens_for_frontend()
{
var source = CreateContent();

await sut.EnrichAsync(requestContext, new[] { source }, schemaProvider, default);
await sut.EnrichAsync(new Context(Mocks.FrontendUser(), Mocks.App(appId)), new[] { source }, schemaProvider, default);

Assert.NotNull(source.EditToken);

Expand Down

0 comments on commit a8da5c6

Please sign in to comment.