Skip to content

Commit 1e6d18e

Browse files
author
Bart Koelman
committed
Added test to capture the current behavior to return data:null for void operations. The spec allows an empty object too, but I don't consider this important enough to add yet another JSON converter with all its overhead.
1 parent 64cc4e2 commit 1e6d18e

File tree

1 file changed

+40
-19
lines changed

1 file changed

+40
-19
lines changed

test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Mixed/AtomicSerializationTests.cs

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Threading.Tasks;
55
using FluentAssertions;
66
using JsonApiDotNetCore.Configuration;
7-
using JsonApiDotNetCore.Resources;
87
using Microsoft.Extensions.DependencyInjection;
98
using TestBuildingBlocks;
109
using Xunit;
@@ -13,8 +12,6 @@ namespace JsonApiDotNetCoreTests.IntegrationTests.AtomicOperations.Mixed
1312
{
1413
public sealed class AtomicSerializationTests : IClassFixture<IntegrationTestContext<TestableStartup<OperationsDbContext>, OperationsDbContext>>
1514
{
16-
private const string JsonDateTimeOffsetFormatSpecifier = "yyyy-MM-ddTHH:mm:ss.FFFFFFFK";
17-
1815
private readonly IntegrationTestContext<TestableStartup<OperationsDbContext>, OperationsDbContext> _testContext;
1916
private readonly OperationsFakers _fakers = new();
2017

@@ -25,11 +22,11 @@ public AtomicSerializationTests(IntegrationTestContext<TestableStartup<Operation
2522
testContext.UseController<OperationsController>();
2623

2724
// These routes need to be registered in ASP.NET for rendering links to resource/relationship endpoints.
28-
testContext.UseController<PerformersController>();
25+
testContext.UseController<TextLanguagesController>();
2926

3027
testContext.ConfigureServicesAfterStartup(services =>
3128
{
32-
services.AddScoped(typeof(IResourceChangeTracker<>), typeof(NeverSameResourceChangeTracker<>));
29+
services.AddResourceDefinition<ImplicitlyChangingTextLanguageDefinition>();
3330
});
3431

3532
var options = (JsonApiOptions)testContext.Factory.Services.GetRequiredService<IJsonApiOptions>();
@@ -39,32 +36,46 @@ public AtomicSerializationTests(IntegrationTestContext<TestableStartup<Operation
3936
}
4037

4138
[Fact]
42-
public async Task Includes_version_with_ext_on_operations_endpoint()
39+
public async Task Hides_data_for_void_operation()
4340
{
4441
// Arrange
45-
Performer newPerformer = _fakers.Performer.Generate();
46-
newPerformer.Id = Unknown.TypedId.Int32;
42+
Performer existingPerformer = _fakers.Performer.Generate();
43+
44+
TextLanguage newLanguage = _fakers.TextLanguage.Generate();
45+
newLanguage.Id = Guid.NewGuid();
4746

4847
await _testContext.RunOnDatabaseAsync(async dbContext =>
4948
{
50-
await dbContext.ClearTableAsync<Performer>();
49+
dbContext.Performers.Add(existingPerformer);
50+
await dbContext.SaveChangesAsync();
5151
});
5252

5353
var requestBody = new
5454
{
55-
atomic__operations = new[]
55+
atomic__operations = new object[]
5656
{
5757
new
5858
{
59-
op = "add",
59+
op = "update",
6060
data = new
6161
{
6262
type = "performers",
63-
id = newPerformer.StringId,
63+
id = existingPerformer.StringId,
6464
attributes = new
6565
{
66-
artistName = newPerformer.ArtistName,
67-
bornAt = newPerformer.BornAt
66+
}
67+
}
68+
},
69+
new
70+
{
71+
op = "add",
72+
data = new
73+
{
74+
type = "textLanguages",
75+
id = newLanguage.StringId,
76+
attributes = new
77+
{
78+
isoCode = newLanguage.IsoCode
6879
}
6980
}
7081
}
@@ -87,16 +98,26 @@ await _testContext.RunOnDatabaseAsync(async dbContext =>
8798
]
8899
},
89100
""atomic:results"": [
101+
{
102+
""data"": null
103+
},
90104
{
91105
""data"": {
92-
""type"": ""performers"",
93-
""id"": """ + newPerformer.StringId + @""",
106+
""type"": ""textLanguages"",
107+
""id"": """ + newLanguage.StringId + @""",
94108
""attributes"": {
95-
""artistName"": """ + newPerformer.ArtistName + @""",
96-
""bornAt"": """ + newPerformer.BornAt.ToString(JsonDateTimeOffsetFormatSpecifier) + @"""
109+
""isoCode"": """ + newLanguage.IsoCode + @" (changed)""
110+
},
111+
""relationships"": {
112+
""lyrics"": {
113+
""links"": {
114+
""self"": ""http://localhost/textLanguages/" + newLanguage.StringId + @"/relationships/lyrics"",
115+
""related"": ""http://localhost/textLanguages/" + newLanguage.StringId + @"/lyrics""
116+
}
117+
}
97118
},
98119
""links"": {
99-
""self"": ""http://localhost/performers/" + newPerformer.StringId + @"""
120+
""self"": ""http://localhost/textLanguages/" + newLanguage.StringId + @"""
100121
}
101122
}
102123
}

0 commit comments

Comments
 (0)