Skip to content

Commit 54eb419

Browse files
committed
Add morph-type tests (#1850)
1 parent 649fb2c commit 54eb419

4 files changed

Lines changed: 134 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using FwDataMiniLcmBridge.Tests.Fixtures;
2+
3+
namespace FwDataMiniLcmBridge.Tests.MiniLcmTests;
4+
5+
[Collection(ProjectLoaderFixture.Name)]
6+
public class MorphTypeTests(ProjectLoaderFixture fixture) : MorphTypeTestsBase
7+
{
8+
protected override Task<IMiniLcmApi> NewApi()
9+
{
10+
return Task.FromResult<IMiniLcmApi>(fixture.NewProjectApi("morph-type-test", "en", "en"));
11+
}
12+
}

backend/FwLite/FwLiteProjectSync.Tests/UpdateDiffTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,18 @@ public void TranslationDiffShouldUpdateAllFields()
7373
before.Should().BeEquivalentTo(after, options => options
7474
.Excluding(x => x.Id));
7575
}
76+
77+
[Fact]
78+
public void MorphTypeDiffShouldUpdateAllFields()
79+
{
80+
var before = new MorphType { Kind = MorphTypeKind.Stem };
81+
var after = AutoFaker.Generate<MorphType>();
82+
after.Kind = before.Kind; // Kind is immutable per MorphTypeUpdateValidator
83+
var morphTypeDiffToUpdate = MorphTypeSync.MorphTypeDiffToUpdate(before, after);
84+
ArgumentNullException.ThrowIfNull(morphTypeDiffToUpdate);
85+
morphTypeDiffToUpdate.Apply(before);
86+
before.Should().BeEquivalentTo(after, options => options
87+
.Excluding(x => x.Id)
88+
.Excluding(x => x.DeletedAt));
89+
}
7690
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace LcmCrdt.Tests.MiniLcmTests;
2+
3+
public class MorphTypeTests : MorphTypeTestsBase
4+
{
5+
private readonly MiniLcmApiFixture _fixture = new();
6+
7+
protected override async Task<IMiniLcmApi> NewApi()
8+
{
9+
await _fixture.InitializeAsync();
10+
var api = _fixture.Api;
11+
return api;
12+
}
13+
14+
public override async Task DisposeAsync()
15+
{
16+
await base.DisposeAsync();
17+
await _fixture.DisposeAsync();
18+
}
19+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
namespace MiniLcm.Tests;
2+
3+
public abstract class MorphTypeTestsBase : MiniLcmTestBase
4+
{
5+
[Fact]
6+
public async Task GetMorphTypes_ReturnsAllCanonicalMorphTypes()
7+
{
8+
var morphTypes = await Api.GetMorphTypes().ToArrayAsync();
9+
morphTypes.Should().NotBeEmpty();
10+
morphTypes.Should().AllSatisfy(mt => mt.Id.Should().NotBe(Guid.Empty));
11+
// All canonical kinds (except Unknown) should be present
12+
var allKinds = Enum.GetValues<MorphTypeKind>().Where(k => k != MorphTypeKind.Unknown);
13+
morphTypes.Select(mt => mt.Kind).Should().BeEquivalentTo(allKinds);
14+
}
15+
16+
[Fact]
17+
public async Task GetMorphType_ById_ReturnsExpected()
18+
{
19+
var morphTypes = await Api.GetMorphTypes().ToArrayAsync();
20+
var stem = morphTypes.First(mt => mt.Kind == MorphTypeKind.Stem);
21+
22+
var result = await Api.GetMorphType(stem.Id);
23+
24+
result.Should().NotBeNull();
25+
result!.Kind.Should().Be(MorphTypeKind.Stem);
26+
result.Id.Should().Be(stem.Id);
27+
}
28+
29+
[Fact]
30+
public async Task GetMorphType_ByKind_ReturnsExpected()
31+
{
32+
var result = await Api.GetMorphType(MorphTypeKind.Prefix);
33+
34+
result.Should().NotBeNull();
35+
result!.Kind.Should().Be(MorphTypeKind.Prefix);
36+
}
37+
38+
[Fact]
39+
public async Task GetMorphType_ByKind_Unknown_ReturnsNull()
40+
{
41+
var result = await Api.GetMorphType(MorphTypeKind.Unknown);
42+
result.Should().BeNull();
43+
}
44+
45+
[Fact]
46+
public async Task UpdateMorphType_UpdatesName()
47+
{
48+
var stem = await Api.GetMorphType(MorphTypeKind.Stem);
49+
stem.Should().NotBeNull();
50+
51+
var updatedStem = stem!.Copy();
52+
updatedStem.Name["en"] = "Updated Stem Name";
53+
await Api.UpdateMorphType(stem, updatedStem);
54+
55+
var result = await Api.GetMorphType(MorphTypeKind.Stem);
56+
result.Should().NotBeNull();
57+
result!.Name["en"].Should().Be("Updated Stem Name");
58+
}
59+
60+
[Fact]
61+
public async Task UpdateMorphType_UpdatesAbbreviation()
62+
{
63+
var prefix = await Api.GetMorphType(MorphTypeKind.Prefix);
64+
prefix.Should().NotBeNull();
65+
66+
var updated = prefix!.Copy();
67+
updated.Abbreviation["en"] = "updated pfx";
68+
await Api.UpdateMorphType(prefix, updated);
69+
70+
var result = await Api.GetMorphType(MorphTypeKind.Prefix);
71+
result.Should().NotBeNull();
72+
result!.Abbreviation["en"].Should().Be("updated pfx");
73+
}
74+
75+
[Fact]
76+
public async Task UpdateMorphType_NoChanges_DoesNotThrow()
77+
{
78+
var stem = await Api.GetMorphType(MorphTypeKind.Stem);
79+
stem.Should().NotBeNull();
80+
81+
var copy = stem!.Copy();
82+
// No changes made - should be a no-op
83+
await Api.UpdateMorphType(stem, copy);
84+
85+
var result = await Api.GetMorphType(MorphTypeKind.Stem);
86+
result.Should().NotBeNull();
87+
result.Should().BeEquivalentTo(stem);
88+
}
89+
}

0 commit comments

Comments
 (0)