From 9b8a15193da1e930f349abdb049215aa5346ac78 Mon Sep 17 00:00:00 2001 From: jrmccannon Date: Tue, 25 Mar 2025 12:45:11 -0500 Subject: [PATCH] Added groups and collection and users checks. --- .../OrganizationUserRepositoryTests.cs | 111 +++++++++++++++++- 1 file changed, 105 insertions(+), 6 deletions(-) diff --git a/test/Infrastructure.IntegrationTest/AdminConsole/Repositories/OrganizationUserRepositoryTests.cs b/test/Infrastructure.IntegrationTest/AdminConsole/Repositories/OrganizationUserRepositoryTests.cs index a2e0d12983..14b6f50415 100644 --- a/test/Infrastructure.IntegrationTest/AdminConsole/Repositories/OrganizationUserRepositoryTests.cs +++ b/test/Infrastructure.IntegrationTest/AdminConsole/Repositories/OrganizationUserRepositoryTests.cs @@ -445,7 +445,25 @@ public class OrganizationUserRepositoryTests CreationDate = requestTime }); - var collection = await collectionRepository.CreateAsync(new Collection + var collection1 = await collectionRepository.CreateAsync(new Collection + { + Id = CoreHelpers.GenerateComb(), + OrganizationId = organization.Id, + Name = "Test Collection", + ExternalId = "external-collection-1", + CreationDate = requestTime, + RevisionDate = requestTime + }); + var collection2 = await collectionRepository.CreateAsync(new Collection + { + Id = CoreHelpers.GenerateComb(), + OrganizationId = organization.Id, + Name = "Test Collection", + ExternalId = "external-collection-1", + CreationDate = requestTime, + RevisionDate = requestTime + }); + var collection3 = await collectionRepository.CreateAsync(new Collection { Id = CoreHelpers.GenerateComb(), OrganizationId = organization.Id, @@ -455,13 +473,28 @@ public class OrganizationUserRepositoryTests RevisionDate = requestTime }); - var group = await groupRepository.CreateAsync(new Group + var group1 = await groupRepository.CreateAsync(new Group { Id = CoreHelpers.GenerateComb(), OrganizationId = organization.Id, Name = "Test Group", ExternalId = "external-group-1" }); + var group2 = await groupRepository.CreateAsync(new Group + { + Id = CoreHelpers.GenerateComb(), + OrganizationId = organization.Id, + Name = "Test Group", + ExternalId = "external-group-1" + }); + var group3 = await groupRepository.CreateAsync(new Group + { + Id = CoreHelpers.GenerateComb(), + OrganizationId = organization.Id, + Name = "Test Group", + ExternalId = "external-group-1" + }); + var orgUserCollection = new List { @@ -482,19 +515,85 @@ public class OrganizationUserRepositoryTests [ new CollectionAccessSelection { - Id = collection.Id, + Id = collection1.Id, ReadOnly = true, HidePasswords = false, Manage = false } ], - Groups = [group.Id] + Groups = [group1.Id] + }, + new() + { + OrganizationUser = new OrganizationUser + { + Id = CoreHelpers.GenerateComb(), + OrganizationId = organization.Id, + Email = "test-user@test.com", + Status = OrganizationUserStatusType.Invited, + Type = OrganizationUserType.Owner, + ExternalId = "externalid-1", + Permissions = CoreHelpers.ClassToJsonData(new Permissions()), + AccessSecretsManager = false + }, + Collections = + [ + new CollectionAccessSelection + { + Id = collection2.Id, + ReadOnly = true, + HidePasswords = false, + Manage = false + } + ], + Groups = [group2.Id] + }, + new() + { + OrganizationUser = new OrganizationUser + { + Id = CoreHelpers.GenerateComb(), + OrganizationId = organization.Id, + Email = "test-user@test.com", + Status = OrganizationUserStatusType.Invited, + Type = OrganizationUserType.Owner, + ExternalId = "externalid-1", + Permissions = CoreHelpers.ClassToJsonData(new Permissions()), + AccessSecretsManager = false + }, + Collections = + [ + new CollectionAccessSelection + { + Id = collection3.Id, + ReadOnly = true, + HidePasswords = false, + Manage = false + } + ], + Groups = [group3.Id] } }; await organizationUserRepository.CreateManyAsync(orgUserCollection); - var orgUser = await organizationUserRepository.GetDetailsByIdAsync(orgUserCollection.First().OrganizationUser.Id); - Assert.Equal(orgUserCollection.First().OrganizationUser.Id, orgUser.Id); + var orgUser1 = await organizationUserRepository.GetDetailsByIdWithCollectionsAsync(orgUserCollection[0].OrganizationUser.Id); + var group1Database = await groupRepository.GetManyIdsByUserIdAsync(orgUserCollection[0].OrganizationUser.Id); + Assert.Equal(orgUserCollection[0].OrganizationUser.Id, orgUser1.OrganizationUser.Id); + Assert.Equal(collection1.Id, orgUser1.Collections.First().Id); + Assert.Equal(group1.Id, group1Database.First()); + + + var orgUser2 = await organizationUserRepository.GetDetailsByIdWithCollectionsAsync(orgUserCollection[1].OrganizationUser.Id); + var group2Database = await groupRepository.GetManyIdsByUserIdAsync(orgUserCollection[1].OrganizationUser.Id); + Assert.Equal(orgUserCollection[1].OrganizationUser.Id, orgUser2.OrganizationUser.Id); + Assert.Equal(collection2.Id, orgUser2.Collections.First().Id); + Assert.Equal(group2.Id, group2Database.First()); + + var orgUser3 = await organizationUserRepository.GetDetailsByIdWithCollectionsAsync(orgUserCollection[2].OrganizationUser.Id); + var group3Database = await groupRepository.GetManyIdsByUserIdAsync(orgUserCollection[2].OrganizationUser.Id); + Assert.Equal(orgUserCollection[2].OrganizationUser.Id, orgUser3.OrganizationUser.Id); + Assert.Equal(collection3.Id, orgUser3.Collections.First().Id); + Assert.Equal(group3.Id, group3Database.First()); } }