Skip to content

Commit c09b772

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 c09b772

4 files changed

Lines changed: 32 additions & 11 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ public async Task UpdateEntry_CanUpdateExampleSentenceTranslations_WhenNoTransla
9090
// Assert
9191
var translation = updatedExampleSentence.Translations.Should().ContainSingle().Subject;
9292
translation.Text["en"].Should().BeEquivalentTo(new RichString("updated", "en"));
93-
updatedEntry.Should().BeEquivalentTo(entry, options => options);
93+
// Exclude Translation.Id since it's API-generated when creating new translations
94+
updatedEntry.Should().BeEquivalentTo(entry, options => options
95+
.For(e => e.Senses)
96+
.For(s => s.ExampleSentences)
97+
.For(ex => ex.Translations)
98+
.Exclude(t => t.Id));
9499
}
95100

96101
[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: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ public async Task CanCreateExampleSentence()
5555
Translations = { new Translation() { Text = { { "en", new RichString("test", "en") } } } }
5656
};
5757
var actualSentence = await Api.CreateExampleSentence(_entryId, _senseId, expectedExampleSentence);
58-
actualSentence.Should().BeEquivalentTo(expectedExampleSentence);
58+
// Exclude API-computed properties: Id, Order, DefaultFirstTranslationId, and Translation.Id
59+
actualSentence.Should().BeEquivalentTo(expectedExampleSentence,
60+
options => options
61+
.Excluding(s => s.Id)
62+
.Excluding(s => s.Order)
63+
.Excluding(s => s.DefaultFirstTranslationId)
64+
.For(s => s.Translations).Exclude(t => t.Id));
5965
}
6066

6167
[Fact]
@@ -66,7 +72,11 @@ public async Task CanCreateEmptyExampleSentence()
6672
SenseId = _senseId
6773
};
6874
var actualSentence = await Api.CreateExampleSentence(_entryId, _senseId, expectedExampleSentence);
69-
actualSentence.Should().BeEquivalentTo(expectedExampleSentence);
75+
// Exclude API-computed properties: Id, Order
76+
actualSentence.Should().BeEquivalentTo(expectedExampleSentence,
77+
options => options
78+
.Excluding(s => s.Id)
79+
.Excluding(s => s.Order));
7080
}
7181

7282
[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)