Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for syncing complex forms twice #1256

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task InitializeAsync()
if (Path.Exists(crdtProjectsFolder)) Directory.Delete(crdtProjectsFolder, true);
Directory.CreateDirectory(crdtProjectsFolder);
var crdtProject = await _services.ServiceProvider.GetRequiredService<ProjectsService>()
.CreateProject(new(_projectName, FwProjectId: FwDataApi.ProjectId, SeedNewProjectData: true));
.CreateProject(new(_projectName, FwProjectId: FwDataApi.ProjectId, SeedNewProjectData: false));
CrdtApi = (CrdtMiniLcmApi) await _services.ServiceProvider.OpenCrdtProject(crdtProject);
}

Expand Down
60 changes: 60 additions & 0 deletions backend/FwLite/FwLiteProjectSync.Tests/SyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ public async Task FirstSyncJustDoesAnImport()
.For(e => e.ComplexForms).Exclude(c => c.Id));
}

[Fact]
public async Task SecondSyncDoesNothing()
{
var crdtApi = _fixture.CrdtApi;
var fwdataApi = _fixture.FwDataApi;
await _syncService.Sync(crdtApi, fwdataApi);
var secondSync = await _syncService.Sync(crdtApi, fwdataApi);
secondSync.CrdtChanges.Should().Be(0);
secondSync.FwdataChanges.Should().Be(0);
}

[Fact]
public static async Task SyncFailsWithMismatchedProjectIds()
{
Expand Down Expand Up @@ -138,6 +149,55 @@ await crdtApi.CreateEntry(new Entry()
.For(e => e.ComplexForms).Exclude(c => c.Id));
}

[Fact]
public async Task CreatingAComplexEntryInFwDataSyncsWithoutIssue()
{
var crdtApi = _fixture.CrdtApi;
var fwdataApi = _fixture.FwDataApi;
await _syncService.Sync(crdtApi, fwdataApi);

var hat = await fwdataApi.CreateEntry(new Entry()
{
LexemeForm = { { "en", "Hat" } },
Senses =
[
new Sense() { Gloss = { { "en", "Hat" } }, }
]
});
var stand = await fwdataApi.CreateEntry(new Entry()
{
LexemeForm = { { "en", "Stand" } },
Senses =
[
new Sense() { Gloss = { { "en", "Stand" } }, }
]
});
var hatstand = await fwdataApi.CreateEntry(new Entry()
{
LexemeForm = { { "en", "Hatstand" } },
Senses =
[
new Sense() { Gloss = { { "en", "Hatstand" } }, }
],
});
var component1 = ComplexFormComponent.FromEntries(hatstand, hat);
var component2 = ComplexFormComponent.FromEntries(hatstand, stand);
hatstand.Components = [component1, component2];
await _syncService.Sync(crdtApi, fwdataApi);

var crdtEntries = await crdtApi.GetEntries().ToArrayAsync();
var fwdataEntries = await fwdataApi.GetEntries().ToArrayAsync();
crdtEntries.Should().BeEquivalentTo(fwdataEntries,
options => options.For(e => e.Components).Exclude(c => c.Id)
.For(e => e.ComplexForms).Exclude(c => c.Id));

// Sync again, ensure no problems or changes
var secondSync = await _syncService.Sync(crdtApi, fwdataApi);
secondSync.CrdtChanges.Should().Be(0);
secondSync.FwdataChanges.Should().Be(0);
}


[Fact]
public async Task PartsOfSpeechSyncBothWays()
{
Expand Down
Loading