-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start rewrite person filters with duplicate check
- Loading branch information
1 parent
90ea3b4
commit c6caf33
Showing
20 changed files
with
676 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,8 @@ Once configured, Korga automatically synchronizes people and groups from ChurchT | |
There is no Web UI available yet to manage distribution lists so you must stick to the CLI inside the Docker container: | ||
|
||
``` | ||
./Korga distribution-list create --group 137 kids | ||
./Korga dist create kids | ||
./Korga dist add-recipient kids -g 137 | ||
``` | ||
|
||
This command creates a distribution list _[email protected]_ which forwards emails to every member of group #137. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,266 @@ | ||
using Korga.ChurchTools.Entities; | ||
using Korga.Filters; | ||
using Korga.Filters.Entities; | ||
using Korga.Tests; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Korga.Server.Tests; | ||
|
||
public class PersonFilterServiceTests : DatabaseTestBase | ||
{ | ||
private readonly PersonFilterService personFilterService; | ||
|
||
public PersonFilterServiceTests() | ||
{ | ||
personFilterService = serviceScope.ServiceProvider.GetRequiredService<PersonFilterService>(); | ||
} | ||
|
||
protected override void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddScoped<PersonFilterService>(); | ||
} | ||
|
||
[Fact] | ||
public async Task TestGetPeople_Empty() | ||
{ | ||
await InitializeSampleDataset(); | ||
|
||
// Create an empty person filter list | ||
PersonFilterList filterList = new(); | ||
databaseContext.PersonFilterLists.Add(filterList); | ||
await databaseContext.SaveChangesAsync(); | ||
|
||
var people = await personFilterService.GetPeople(filterList.Id); | ||
Assert.Empty(people); | ||
} | ||
|
||
[Fact] | ||
public async Task TestGetPeople_Person() | ||
{ | ||
await InitializeSampleDataset(); | ||
|
||
// Create person filter | ||
PersonFilterList filterList = new() | ||
{ | ||
Filters = [new SinglePerson { PersonId = 1 }] | ||
}; | ||
databaseContext.PersonFilterLists.Add(filterList); | ||
await databaseContext.SaveChangesAsync(); | ||
|
||
var people = await personFilterService.GetPeople(filterList.Id); | ||
Person actual = Assert.Single(people); | ||
Assert.Equal(1, actual.Id); | ||
} | ||
|
||
[Fact] | ||
public async Task TestGetPeople_Status() | ||
{ | ||
await InitializeSampleDataset(); | ||
|
||
// Create status filter | ||
PersonFilterList filterList = new() | ||
{ | ||
Filters = [new StatusFilter { StatusId = 3 }] | ||
}; | ||
databaseContext.PersonFilterLists.Add(filterList); | ||
await databaseContext.SaveChangesAsync(); | ||
|
||
var people = await personFilterService.GetPeople(filterList.Id); | ||
Assert.Equal(2, people.Count()); | ||
Assert.Contains(people, p => p.Id == 1); | ||
Assert.Contains(people, p => p.Id == 2); | ||
} | ||
|
||
[Fact] | ||
public async Task TestGetPeople_Status_Status() | ||
{ | ||
await InitializeSampleDataset(); | ||
|
||
// Create person filter | ||
PersonFilterList filterList = new() | ||
{ | ||
Filters = | ||
[ | ||
new StatusFilter { StatusId = 2 }, | ||
new StatusFilter { StatusId = 3 }, | ||
] | ||
}; | ||
databaseContext.PersonFilterLists.Add(filterList); | ||
await databaseContext.SaveChangesAsync(); | ||
|
||
var people = await personFilterService.GetPeople(filterList.Id); | ||
Assert.Equal(3, people.Count()); | ||
Assert.Contains(people, p => p.Id == 1); | ||
Assert.Contains(people, p => p.Id == 2); | ||
Assert.Contains(people, p => p.Id == 3); | ||
} | ||
|
||
[Fact] | ||
public async Task TestGetPeople_Group() | ||
{ | ||
await InitializeSampleDataset(); | ||
|
||
// Create person filter | ||
PersonFilterList filterList = new() | ||
{ | ||
Filters = [new GroupFilter { GroupId = 1 }] | ||
}; | ||
databaseContext.PersonFilterLists.Add(filterList); | ||
await databaseContext.SaveChangesAsync(); | ||
|
||
var people = await personFilterService.GetPeople(filterList.Id); | ||
Person actual = Assert.Single(people); | ||
Assert.Equal(1, actual.Id); | ||
} | ||
|
||
[Fact] | ||
public async Task TestAddFilter_Group_EmptyList() | ||
{ | ||
await InitializeSampleDataset(); | ||
PersonFilterList filterList = new(); | ||
databaseContext.PersonFilterLists.Add(filterList); | ||
await databaseContext.SaveChangesAsync(); | ||
|
||
bool inserted = await personFilterService.AddFilter(filterList.Id, new GroupFilter { GroupId = 1 }); | ||
Assert.True(inserted); | ||
} | ||
|
||
[Fact] | ||
public async Task TestAddFilter_Group_NewFilter() | ||
{ | ||
await InitializeSampleDataset(); | ||
|
||
// Create sample filter | ||
PersonFilterList filterList = new() | ||
{ | ||
Filters = [new GroupFilter { GroupId = 1 }] | ||
}; | ||
databaseContext.PersonFilterLists.Add(filterList); | ||
await databaseContext.SaveChangesAsync(); | ||
|
||
bool inserted = await personFilterService.AddFilter(filterList.Id, new GroupFilter { GroupId = 2 }); | ||
Assert.True(inserted); | ||
} | ||
|
||
[Fact] | ||
public async Task TestAddFilter_Group_AlreadyExists() | ||
{ | ||
await InitializeSampleDataset(); | ||
|
||
// Create sample filter | ||
PersonFilterList filterList = new() | ||
{ | ||
Filters = [new GroupFilter { GroupId = 1 }] | ||
}; | ||
databaseContext.PersonFilterLists.Add(filterList); | ||
await databaseContext.SaveChangesAsync(); | ||
|
||
bool inserted = await personFilterService.AddFilter(filterList.Id, new GroupFilter { GroupId = 1 }); | ||
Assert.False(inserted); | ||
} | ||
|
||
[Fact] | ||
public async Task TestAddFilter_GroupType_AlreadyExists() | ||
{ | ||
await InitializeSampleDataset(); | ||
|
||
// Create sample filter | ||
PersonFilterList filterList = new() | ||
{ | ||
Filters = [new GroupTypeFilter { GroupTypeId = 1 }] | ||
}; | ||
databaseContext.PersonFilterLists.Add(filterList); | ||
await databaseContext.SaveChangesAsync(); | ||
|
||
bool inserted = await personFilterService.AddFilter(filterList.Id, new GroupTypeFilter { GroupTypeId = 1 }); | ||
Assert.False(inserted); | ||
} | ||
|
||
[Fact] | ||
public async Task TestAddFilter_SinglePerson_AlreadyExists() | ||
{ | ||
await InitializeSampleDataset(); | ||
|
||
// Create sample filter | ||
PersonFilterList filterList = new() | ||
{ | ||
Filters = [new SinglePerson { PersonId = 1 }] | ||
}; | ||
databaseContext.PersonFilterLists.Add(filterList); | ||
await databaseContext.SaveChangesAsync(); | ||
|
||
bool inserted = await personFilterService.AddFilter(filterList.Id, new SinglePerson { PersonId = 1 }); | ||
Assert.False(inserted); | ||
} | ||
[Fact] | ||
public async Task TestAddFilter_Status_AlreadyExists() | ||
{ | ||
await InitializeSampleDataset(); | ||
|
||
// Create sample filter | ||
PersonFilterList filterList = new() | ||
{ | ||
Filters = [new StatusFilter { StatusId = 3 }] | ||
}; | ||
databaseContext.PersonFilterLists.Add(filterList); | ||
await databaseContext.SaveChangesAsync(); | ||
|
||
bool inserted = await personFilterService.AddFilter(filterList.Id, new StatusFilter { StatusId = 3 }); | ||
Assert.False(inserted); | ||
} | ||
|
||
|
||
private async ValueTask InitializeSampleDataset() | ||
{ | ||
// Initialize database | ||
// TODO: Use migrations again | ||
//await databaseContext.Database.MigrateAsync(); | ||
await databaseContext.Database.EnsureCreatedAsync(); | ||
|
||
databaseContext.Status.AddRange( | ||
[ | ||
new(1, "Gast"), | ||
new(2, "Freund"), | ||
new(3, "Mitglied"), | ||
]); | ||
databaseContext.GroupTypes.AddRange( | ||
[ | ||
new(1, "Kleingruppe"), | ||
new(2, "Dienst"), | ||
]); | ||
databaseContext.GroupRoles.AddRange( | ||
[ | ||
new(8, 1, "Teilnehmer"), | ||
new(9, 1, "Leiter"), | ||
new(15, 2, "Mitarbeiter"), | ||
new(16, 2, "Leiter"), | ||
]); | ||
databaseContext.GroupStatuses.AddRange( | ||
[ | ||
new(1, "active"), | ||
new(2, "archived"), | ||
]); | ||
databaseContext.People.AddRange( | ||
[ | ||
new(1, 3, "Markus", "Wiebe", "[email protected]"), | ||
new(2, 3, "Debora", "Wiebe", "[email protected]"), | ||
new(3, 2, "Mohammad", "Khamenei", "[email protected]"), | ||
new(4, 1, "Barbara", "Müller", "[email protected]"), | ||
]); | ||
databaseContext.Groups.AddRange( | ||
[ | ||
new(1, 1, 1, "Admin"), | ||
new(2, 2, 1, "Kinderdienst"), | ||
]); | ||
databaseContext.GroupMembers.AddRange( | ||
[ | ||
new() { PersonId = 1, GroupId = 1, GroupRoleId = 9 }, | ||
new() { PersonId = 2, GroupId = 2, GroupRoleId = 16 }, | ||
new() { PersonId = 4, GroupId = 2, GroupRoleId = 15 }, | ||
]); | ||
await databaseContext.SaveChangesAsync(); | ||
} | ||
} |
Oops, something went wrong.