Skip to content

Commit 2cb27a2

Browse files
myieyeclaude
andcommitted
Refine IsMain publication tests and validation after review
Consolidate the get-or-create main-publication helper onto MiniLcmTestBase (shared by the publication and create-entry conformance tests, reusing the project's existing main rather than minting a second). Make the REST route's CreateEntryOptions defaults explicit via ToOptions(defaults), extract CreatePublicationChange.MainAlreadyExists, and make DoesNotChangePropertyTo generic over the forbidden value's type. Drop the dry-run PublicationSyncTests: the collection-level promotion it guarded was removed when IsMain moved into standard per-publication diffing, so the failure mode it covered is structurally gone. Fix entry-api-helper to inline the create-entry options inside page.evaluate — module imports are closure variables that don't cross the Playwright serialization boundary, so referencing the shared helper there throws. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ac9611f commit 2cb27a2

14 files changed

Lines changed: 42 additions & 945 deletions
Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using FwDataMiniLcmBridge.Api;
21
using FwDataMiniLcmBridge.Tests.Fixtures;
3-
using MiniLcm.Models;
4-
using SIL.LCModel.Infrastructure;
52

63
namespace FwDataMiniLcmBridge.Tests.MiniLcmTests;
74

@@ -12,17 +9,4 @@ protected override Task<IMiniLcmApi> NewApi()
129
{
1310
return Task.FromResult<IMiniLcmApi>(fixture.NewProjectApi("publications-test", "en", "en"));
1411
}
15-
16-
// FieldWorks' main publication is its protected one; the MiniLcm write path deliberately never flips
17-
// IsProtected (see UpdatePublicationProxy), so seed it directly at the LCM layer for these tests.
18-
protected override async Task<Publication> SeedMainPublication(string name = "Main")
19-
{
20-
var fwApi = (FwDataMiniLcmApi)BaseApi;
21-
var pub = await Api.CreatePublication(new Publication { Id = Guid.NewGuid(), Name = { { "en", name } } });
22-
var lcmPublication = fwApi.GetLcmPublication(pub.Id)
23-
?? throw new InvalidOperationException($"Seeded publication {pub.Id} not found in LCM");
24-
NonUndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(fwApi.Cache.ServiceLocator.ActionHandler,
25-
() => lcmPublication.IsProtected = true);
26-
return await Api.GetPublication(pub.Id) ?? throw new InvalidOperationException($"Seeded main {pub.Id} not found");
27-
}
2812
}

backend/FwLite/FwLiteProjectSync.Tests/EntrySyncTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,19 +312,19 @@ public async Task CanSyncRandomEntries(ApiType? roundTripApiType)
312312
var expected = after.Copy();
313313

314314
// Don't auto-add the main publication when staging data: the sync path under test (EntrySync) never does.
315-
var noAutoMain = new CreateEntryOptions(AutoAddMainPublication: false);
315+
var asIsEntryOptions = CreateEntryOptions.AsIs;
316316
if (roundTripApi is not null)
317317
{
318318
// round-tripping ensures we're dealing with realistic data
319319
// (e.g. in fwdata ComplexFormComponents do not have an Id)
320-
before = await roundTripApi.CreateEntry(before, noAutoMain);
320+
before = await roundTripApi.CreateEntry(before, asIsEntryOptions);
321321
await roundTripApi.DeleteEntry(before.Id);
322-
after = await roundTripApi.CreateEntry(after, noAutoMain);
322+
after = await roundTripApi.CreateEntry(after, asIsEntryOptions);
323323
await roundTripApi.DeleteEntry(after.Id);
324324
}
325325

326326
// before should not be round-tripped here. That's handled above.
327-
await Api.CreateEntry(before, noAutoMain);
327+
await Api.CreateEntry(before, asIsEntryOptions);
328328

329329
// act
330330
await EntrySync.SyncFull(before, after, Api);

backend/FwLite/FwLiteProjectSync.Tests/PublicationSyncTests.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

backend/FwLite/FwLiteProjectSync/CrdtFwdataProjectSyncService.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using LexCore.Sync;
55
using Microsoft.Extensions.Logging;
66
using MiniLcm;
7-
using MiniLcm.Models;
87
using MiniLcm.SyncHelpers;
98
using MiniLcm.Validators;
109

backend/FwLite/FwLiteWeb/Routes/MiniLcmRoutes.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ public static IAsyncEnumerable<Publication> GetPublications([FromServices] MiniL
174174
}
175175

176176
public static Task<Entry> PostEntry([FromBody] Entry entry,
177-
[AsParameters] CreateEntryParams options,
177+
[AsParameters] CreateEntryOptionsParams paramOptions,
178178
[FromServices] MiniLcmHolder holder)
179179
{
180180
var api = holder.MiniLcmApi;
181-
return api.CreateEntry(entry, options.ToOptions());
181+
return api.CreateEntry(entry, paramOptions.ToOptions(defaults: CreateEntryOptions.WithMainPublication));
182182
}
183183

184184
public static Task DeleteEntry(Guid id, [FromServices] MiniLcmHolder holder)
@@ -188,19 +188,16 @@ public static Task DeleteEntry(Guid id, [FromServices] MiniLcmHolder holder)
188188
}
189189
}
190190

191-
private class CreateEntryParams
191+
private class CreateEntryOptionsParams
192192
{
193193
[FromQuery]
194194
public bool? AutoAddMainPublication { get; set; }
195-
196195
[FromQuery]
197196
public bool? IncludeComplexFormsAndComponents { get; set; }
198197

199-
// Unspecified defaults to interactive-creation behaviour (auto-add the main publication), not the
200-
// CreateEntryOptions record default, which is the opposite.
201-
public CreateEntryOptions ToOptions() => new(
202-
IncludeComplexFormsAndComponents: IncludeComplexFormsAndComponents ?? true,
203-
AutoAddMainPublication: AutoAddMainPublication ?? true);
198+
public CreateEntryOptions ToOptions(CreateEntryOptions defaults) => new(
199+
IncludeComplexFormsAndComponents: IncludeComplexFormsAndComponents ?? defaults.IncludeComplexFormsAndComponents,
200+
AutoAddMainPublication: AutoAddMainPublication ?? defaults.AutoAddMainPublication);
204201
}
205202

206203
private class MiniLcmQueryOptions

0 commit comments

Comments
 (0)