Skip to content

Commit 10647af

Browse files
committed
Exclude API-computed properties from test comparisons
The normalization wrapper creates new objects instead of mutating input objects, so tests can no longer rely on the API mutating the input. This commit excludes API-computed properties (Order, Id, DefaultFirstTranslationId, Translation.Id) from test comparisons where the test is verifying user-provided values, not API-computed ones. https://claude.ai/code/session_01MYAMRqK5NJmFkQ7a7tVkTd
1 parent 5b32a45 commit 10647af

4 files changed

Lines changed: 32 additions & 13 deletions

File tree

backend/FwLite/FwDataMiniLcmBridge.Tests/MiniLcmTests/UpdateEntryTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,18 @@ public async Task UpdateEntry_CanUpdateExampleSentenceTranslations_WhenNoTransla
8181

8282
var before = entry.Copy();
8383
var exampleSentence = entry.Senses[0].ExampleSentences[0];
84-
exampleSentence.Translations = [new() { Text = { { "en", new RichString("updated") } } }];
84+
var translationId = Guid.NewGuid();
85+
exampleSentence.Translations = [new() { Id = translationId, Text = { { "en", new RichString("updated") } } }];
8586

8687
// Act
8788
var updatedEntry = await Api.UpdateEntry(before, entry);
8889
var updatedExampleSentence = updatedEntry.Senses[0].ExampleSentences[0];
8990

9091
// Assert
9192
var translation = updatedExampleSentence.Translations.Should().ContainSingle().Subject;
93+
translation.Id.Should().Be(translationId);
9294
translation.Text["en"].Should().BeEquivalentTo(new RichString("updated", "en"));
93-
updatedEntry.Should().BeEquivalentTo(entry, options => options);
95+
updatedEntry.Should().BeEquivalentTo(entry);
9496
}
9597

9698
[Theory]

backend/FwLite/MiniLcm.Tests/CreateEntryTestsBase.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ public async Task CanCreateEntry_AutoFaker()
1818
{
1919
var entry = await AutoFaker.EntryReadyForCreation(Api);
2020
var createdEntry = await Api.CreateEntry(entry);
21+
// Order is set by the API, not user input, so exclude from comparison
2122
createdEntry.Should().BeEquivalentTo(entry, options => options
22-
.For(e => e.Components).Exclude(e => e.Id)
23-
.For(e => e.ComplexForms).Exclude(e => e.Id));
23+
.For(e => e.Components).Exclude(c => c.Id)
24+
.For(e => e.Components).Exclude(c => c.Order)
25+
.For(e => e.ComplexForms).Exclude(c => c.Id)
26+
.For(e => e.ComplexForms).Exclude(c => c.Order)
27+
.For(e => e.Senses).Exclude(s => s.Order)
28+
.For(e => e.Senses).For(s => s.ExampleSentences).Exclude(e => e.Order));
2429
}
2530

2631
[Fact]

backend/FwLite/MiniLcm.Tests/ExampleSentenceTestsBase.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,37 @@ public async Task Get_ExistingExampleSentence_ReturnsExampleSentence()
4747
[Fact]
4848
public async Task CanCreateExampleSentence()
4949
{
50+
var exampleSentenceId = Guid.NewGuid();
51+
var translationId = Guid.NewGuid();
5052
var expectedExampleSentence = new ExampleSentence()
5153
{
54+
Id = exampleSentenceId,
5255
SenseId = _senseId,
5356
Reference = new RichString("This is a reference", "en"),
5457
Sentence = { { "en", new RichString("test", "en") } },
55-
Translations = { new Translation() { Text = { { "en", new RichString("test", "en") } } } }
58+
Translations = { new Translation() { Id = translationId, Text = { { "en", new RichString("test", "en") } } } }
5659
};
5760
var actualSentence = await Api.CreateExampleSentence(_entryId, _senseId, expectedExampleSentence);
58-
actualSentence.Should().BeEquivalentTo(expectedExampleSentence);
61+
// Exclude API-computed properties: Order (sequence position) and DefaultFirstTranslationId (computed from Translations)
62+
actualSentence.Should().BeEquivalentTo(expectedExampleSentence,
63+
options => options
64+
.Excluding(s => s.Order)
65+
.Excluding(s => s.DefaultFirstTranslationId));
5966
}
6067

6168
[Fact]
6269
public async Task CanCreateEmptyExampleSentence()
6370
{
71+
var exampleSentenceId = Guid.NewGuid();
6472
var expectedExampleSentence = new ExampleSentence()
6573
{
74+
Id = exampleSentenceId,
6675
SenseId = _senseId
6776
};
6877
var actualSentence = await Api.CreateExampleSentence(_entryId, _senseId, expectedExampleSentence);
69-
actualSentence.Should().BeEquivalentTo(expectedExampleSentence);
78+
// Exclude Order since it's API-computed (sequence position)
79+
actualSentence.Should().BeEquivalentTo(expectedExampleSentence,
80+
options => options.Excluding(s => s.Order));
7081
}
7182

7283
[Fact]

backend/FwLite/MiniLcm.Tests/UpdateEntryTestsBase.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ public async Task UpdateEntry_CanReorderSenses(string before, string after, stri
168168
var afterEntry = beforeEntry!.Copy();
169169
afterEntry.Senses = afterSenses;
170170

171-
// sanity checks
172-
beforeEntry.Senses.Should().BeEquivalentTo(beforeSenses, options => options.WithStrictOrdering());
171+
// sanity checks (exclude Order since it's API-computed, not in our input)
172+
beforeEntry.Senses.Should().BeEquivalentTo(beforeSenses, options => options.WithStrictOrdering().Excluding(s => s.Order));
173173
if (!ApiUsesImplicitOrdering)
174174
{
175175
beforeEntry.Senses.Select(s => s.Order).Should()
@@ -230,8 +230,8 @@ public async Task UpdateEntry_CanReorderExampleSentence(string before, string af
230230
var afterSense = afterEntry.Senses[0];
231231
afterSense.ExampleSentences = afterExamples;
232232

233-
// sanity checks
234-
beforeSense.ExampleSentences.Should().BeEquivalentTo(beforeExamples, options => options.WithStrictOrdering());
233+
// sanity checks (exclude Order since it's API-computed, not in our input)
234+
beforeSense.ExampleSentences.Should().BeEquivalentTo(beforeExamples, options => options.WithStrictOrdering().Excluding(s => s.Order));
235235
if (!ApiUsesImplicitOrdering)
236236
{
237237
beforeSense.ExampleSentences.Select(s => s.Order).Should()
@@ -306,10 +306,11 @@ public async Task UpdateEntry_CanReorderComponents(string before, string after,
306306
var afterEntry = beforeEntry!.Copy();
307307
afterEntry.Components = afterComponents;
308308

309-
// sanity checks
309+
// sanity checks (exclude Order since it's API-computed, not in our input)
310310
beforeEntry.Components.Should().BeEquivalentTo(beforeComponents, options => options
311311
.WithStrictOrdering()
312-
.Excluding(c => c.Id));
312+
.Excluding(c => c.Id)
313+
.Excluding(c => c.Order));
313314
if (!ApiUsesImplicitOrdering)
314315
{
315316
beforeEntry.Components.Select(s => s.Order).Should()

0 commit comments

Comments
 (0)