@ -28,8 +28,8 @@ public class OrganizationUserRepositoryTests
var organization = await organizationRepository . CreateAsync ( new Organization
var organization = await organizationRepository . CreateAsync ( new Organization
{
{
Name = "Test Org" ,
Name = "Test Org" ,
BillingEmail = user . Email , // TODO: EF does not enfore this being NOT NULL
BillingEmail = user . Email , // TODO: EF does not enforc e this being NOT NULL
Plan = "Test" , // TODO: EF does not enforce this being NOT NULl
Plan = "Test" , // TODO: EF does not enforce this being NOT NULL
} ) ;
} ) ;
var orgUser = await organizationUserRepository . CreateAsync ( new OrganizationUser
var orgUser = await organizationUserRepository . CreateAsync ( new OrganizationUser
@ -37,6 +37,7 @@ public class OrganizationUserRepositoryTests
OrganizationId = organization . Id ,
OrganizationId = organization . Id ,
UserId = user . Id ,
UserId = user . Id ,
Status = OrganizationUserStatusType . Confirmed ,
Status = OrganizationUserStatusType . Confirmed ,
Email = user . Email
} ) ;
} ) ;
await organizationUserRepository . DeleteAsync ( orgUser ) ;
await organizationUserRepository . DeleteAsync ( orgUser ) ;
@ -46,6 +47,171 @@ public class OrganizationUserRepositoryTests
Assert . NotEqual ( newUser . AccountRevisionDate , user . AccountRevisionDate ) ;
Assert . NotEqual ( newUser . AccountRevisionDate , user . AccountRevisionDate ) ;
}
}
[DatabaseTheory, DatabaseData]
public async Task DeleteManyAsync_Migrates_UserDefaultCollection ( IUserRepository userRepository ,
ICollectionRepository collectionRepository ,
IOrganizationRepository organizationRepository ,
IOrganizationUserRepository organizationUserRepository
)
{
var user1 = await userRepository . CreateAsync ( new User
{
Name = "Test User" ,
Email = $"test+{Guid.NewGuid()}@example.com" ,
ApiKey = "TEST" ,
SecurityStamp = "stamp" ,
} ) ;
var user2 = await userRepository . CreateAsync ( new User
{
Name = "Test User" ,
Email = $"test+{Guid.NewGuid()}@example.com" ,
ApiKey = "TEST" ,
SecurityStamp = "stamp" ,
} ) ;
var organization = await organizationRepository . CreateAsync ( new Organization
{
Name = "Test Org" ,
BillingEmail = user1 . Email , // TODO: EF does not enforce this being NOT NULL
Plan = "Test" , // TODO: EF does not enforce this being NOT NULL
} ) ;
var orgUser1 = await organizationUserRepository . CreateAsync ( new OrganizationUser
{
OrganizationId = organization . Id ,
UserId = user1 . Id ,
Status = OrganizationUserStatusType . Confirmed ,
Email = user1 . Email
} ) ;
var orgUser2 = await organizationUserRepository . CreateAsync ( new OrganizationUser
{
OrganizationId = organization . Id ,
UserId = user2 . Id ,
Status = OrganizationUserStatusType . Confirmed ,
Email = user2 . Email
} ) ;
var defaultUserCollection1 = await collectionRepository . CreateAsync ( new Collection
{
Name = "Test Collection 1" ,
Id = user1 . Id ,
Type = CollectionType . DefaultUserCollection ,
OrganizationId = organization . Id
} ) ;
var defaultUserCollection2 = await collectionRepository . CreateAsync ( new Collection
{
Name = "Test Collection 2" ,
Id = user2 . Id ,
Type = CollectionType . DefaultUserCollection ,
OrganizationId = organization . Id
} ) ;
// Create the CollectionUser entry for the defaultUserCollection
await collectionRepository . UpdateUsersAsync ( defaultUserCollection1 . Id , new List < CollectionAccessSelection > ( )
{
new CollectionAccessSelection
{
Id = orgUser1 . Id ,
HidePasswords = false ,
ReadOnly = false ,
Manage = true
} ,
} ) ;
await collectionRepository . UpdateUsersAsync ( defaultUserCollection2 . Id , new List < CollectionAccessSelection > ( )
{
new CollectionAccessSelection
{
Id = orgUser2 . Id ,
HidePasswords = false ,
ReadOnly = false ,
Manage = true
} ,
} ) ;
await organizationUserRepository . DeleteManyAsync ( new List < Guid > { orgUser1 . Id , orgUser2 . Id } ) ;
var newUser = await userRepository . GetByIdAsync ( user1 . Id ) ;
Assert . NotNull ( newUser ) ;
Assert . NotEqual ( newUser . AccountRevisionDate , user1 . AccountRevisionDate ) ;
var updatedCollection1 = await collectionRepository . GetByIdAsync ( defaultUserCollection1 . Id ) ;
Assert . NotNull ( updatedCollection1 ) ;
Assert . Equal ( CollectionType . SharedCollection , updatedCollection1 . Type ) ;
Assert . Equal ( user1 . Email , updatedCollection1 . DefaultUserCollectionEmail ) ;
var updatedCollection2 = await collectionRepository . GetByIdAsync ( defaultUserCollection2 . Id ) ;
Assert . NotNull ( updatedCollection2 ) ;
Assert . Equal ( CollectionType . SharedCollection , updatedCollection2 . Type ) ;
Assert . Equal ( user2 . Email , updatedCollection2 . DefaultUserCollectionEmail ) ;
}
[DatabaseTheory, DatabaseData]
public async Task DeleteAsync_Migrates_UserDefaultCollection ( IUserRepository userRepository ,
ICollectionRepository collectionRepository ,
IOrganizationRepository organizationRepository ,
IOrganizationUserRepository organizationUserRepository
)
{
var user = await userRepository . CreateAsync ( new User
{
Name = "Test User" ,
Email = $"test+{Guid.NewGuid()}@example.com" ,
ApiKey = "TEST" ,
SecurityStamp = "stamp" ,
} ) ;
var organization = await organizationRepository . CreateAsync ( new Organization
{
Name = "Test Org" ,
BillingEmail = user . Email , // TODO: EF does not enforce this being NOT NULL
Plan = "Test" , // TODO: EF does not enforce this being NOT NULL
} ) ;
var orgUser = await organizationUserRepository . CreateAsync ( new OrganizationUser
{
OrganizationId = organization . Id ,
UserId = user . Id ,
Status = OrganizationUserStatusType . Confirmed ,
Email = user . Email
} ) ;
var defaultUserCollection = await collectionRepository . CreateAsync ( new Collection
{
Name = "Test Collection" ,
Id = user . Id ,
Type = CollectionType . DefaultUserCollection ,
OrganizationId = organization . Id
} ) ;
// Create the CollectionUser entry for the defaultUserCollection
await collectionRepository . UpdateUsersAsync ( defaultUserCollection . Id , new List < CollectionAccessSelection > ( )
{
new CollectionAccessSelection
{
Id = orgUser . Id ,
HidePasswords = false ,
ReadOnly = false ,
Manage = true
} ,
} ) ;
await organizationUserRepository . DeleteAsync ( orgUser ) ;
var newUser = await userRepository . GetByIdAsync ( user . Id ) ;
Assert . NotNull ( newUser ) ;
Assert . NotEqual ( newUser . AccountRevisionDate , user . AccountRevisionDate ) ;
var updatedCollection = await collectionRepository . GetByIdAsync ( defaultUserCollection . Id ) ;
Assert . NotNull ( updatedCollection ) ;
Assert . Equal ( CollectionType . SharedCollection , updatedCollection . Type ) ;
Assert . Equal ( user . Email , updatedCollection . DefaultUserCollectionEmail ) ;
}
[DatabaseTheory, DatabaseData]
[DatabaseTheory, DatabaseData]
public async Task DeleteManyAsync_Works ( IUserRepository userRepository ,
public async Task DeleteManyAsync_Works ( IUserRepository userRepository ,
IOrganizationRepository organizationRepository ,
IOrganizationRepository organizationRepository ,
@ -70,8 +236,8 @@ public class OrganizationUserRepositoryTests
var organization = await organizationRepository . CreateAsync ( new Organization
var organization = await organizationRepository . CreateAsync ( new Organization
{
{
Name = "Test Org" ,
Name = "Test Org" ,
BillingEmail = user1 . Email , // TODO: EF does not enforce this being NOT NULl
BillingEmail = user1 . Email , // TODO: EF does not enforce this being NOT NULL
Plan = "Test" , // TODO: EF does not enforce this being NOT NULl
Plan = "Test" , // TODO: EF does not enforce this being NOT NULL
} ) ;
} ) ;
var orgUser1 = await organizationUserRepository . CreateAsync ( new OrganizationUser
var orgUser1 = await organizationUserRepository . CreateAsync ( new OrganizationUser
@ -79,6 +245,7 @@ public class OrganizationUserRepositoryTests
OrganizationId = organization . Id ,
OrganizationId = organization . Id ,
UserId = user1 . Id ,
UserId = user1 . Id ,
Status = OrganizationUserStatusType . Confirmed ,
Status = OrganizationUserStatusType . Confirmed ,
Email = user1 . Email
} ) ;
} ) ;
var orgUser2 = await organizationUserRepository . CreateAsync ( new OrganizationUser
var orgUser2 = await organizationUserRepository . CreateAsync ( new OrganizationUser
@ -86,6 +253,7 @@ public class OrganizationUserRepositoryTests
OrganizationId = organization . Id ,
OrganizationId = organization . Id ,
UserId = user2 . Id ,
UserId = user2 . Id ,
Status = OrganizationUserStatusType . Confirmed ,
Status = OrganizationUserStatusType . Confirmed ,
Email = user2 . Email
} ) ;
} ) ;
await organizationUserRepository . DeleteManyAsync ( new List < Guid >
await organizationUserRepository . DeleteManyAsync ( new List < Guid >
@ -135,8 +303,8 @@ public class OrganizationUserRepositoryTests
var organization = await organizationRepository . CreateAsync ( new Organization
var organization = await organizationRepository . CreateAsync ( new Organization
{
{
Name = "Test Org" ,
Name = "Test Org" ,
BillingEmail = user1 . Email , // TODO: EF does not enforce this being NOT NULl
BillingEmail = user1 . Email , // TODO: EF does not enforce this being NOT NULL
Plan = "Test" , // TODO: EF does not enforce this being NOT NULl
Plan = "Test" , // TODO: EF does not enforce this being NOT NULL
PrivateKey = "privatekey" ,
PrivateKey = "privatekey" ,
} ) ;
} ) ;
@ -291,8 +459,8 @@ public class OrganizationUserRepositoryTests
var organization = await organizationRepository . CreateAsync ( new Organization
var organization = await organizationRepository . CreateAsync ( new Organization
{
{
Name = "Test Org" ,
Name = "Test Org" ,
BillingEmail = user1 . Email , // TODO: EF does not enforce this being NOT NULl
BillingEmail = user1 . Email , // TODO: EF does not enforce this being NOT NULL
Plan = "Test" , // TODO: EF does not enforce this being NOT NULl
Plan = "Test" , // TODO: EF does not enforce this being NOT NULL
PrivateKey = "privatekey" ,
PrivateKey = "privatekey" ,
} ) ;
} ) ;
@ -354,6 +522,134 @@ public class OrganizationUserRepositoryTests
Assert . Equal ( organization . UseAdminSponsoredFamilies , result . UseAdminSponsoredFamilies ) ;
Assert . Equal ( organization . UseAdminSponsoredFamilies , result . UseAdminSponsoredFamilies ) ;
}
}
[DatabaseTheory, DatabaseData]
public async Task GetManyByOrganizationWithClaimedDomainsAsync_WithVerifiedDomain_WithOneMatchingEmailDomain_ReturnsSingle (
IUserRepository userRepository ,
IOrganizationRepository organizationRepository ,
IOrganizationUserRepository organizationUserRepository ,
IOrganizationDomainRepository organizationDomainRepository )
{
var id = Guid . NewGuid ( ) ;
var domainName = $"{id}.example.com" ;
var user1 = await userRepository . CreateAsync ( new User
{
Name = "Test User 1" ,
Email = $"test+{id}@{domainName}" ,
ApiKey = "TEST" ,
SecurityStamp = "stamp" ,
Kdf = KdfType . PBKDF2_SHA256 ,
KdfIterations = 1 ,
KdfMemory = 2 ,
KdfParallelism = 3
} ) ;
var user2 = await userRepository . CreateAsync ( new User
{
Name = "Test User 2" ,
Email = $"test+{id}@x-{domainName}" , // Different domain
ApiKey = "TEST" ,
SecurityStamp = "stamp" ,
Kdf = KdfType . PBKDF2_SHA256 ,
KdfIterations = 1 ,
KdfMemory = 2 ,
KdfParallelism = 3
} ) ;
var user3 = await userRepository . CreateAsync ( new User
{
Name = "Test User 2" ,
Email = $"test+{id}@{domainName}.example.com" , // Different domain
ApiKey = "TEST" ,
SecurityStamp = "stamp" ,
Kdf = KdfType . PBKDF2_SHA256 ,
KdfIterations = 1 ,
KdfMemory = 2 ,
KdfParallelism = 3
} ) ;
var organization = await organizationRepository . CreateAsync ( new Organization
{
Name = $"Test Org {id}" ,
BillingEmail = user1 . Email , // TODO: EF does not enforce this being NOT NULL
Plan = "Test" , // TODO: EF does not enforce this being NOT NULL
PrivateKey = "privatekey" ,
UsePolicies = false ,
UseSso = false ,
UseKeyConnector = false ,
UseScim = false ,
UseGroups = false ,
UseDirectory = false ,
UseEvents = false ,
UseTotp = false ,
Use2fa = false ,
UseApi = false ,
UseResetPassword = false ,
UseSecretsManager = false ,
SelfHost = false ,
UsersGetPremium = false ,
UseCustomPermissions = false ,
Enabled = true ,
UsePasswordManager = false ,
LimitCollectionCreation = false ,
LimitCollectionDeletion = false ,
LimitItemDeletion = false ,
AllowAdminAccessToAllCollectionItems = false ,
UseRiskInsights = false ,
UseAdminSponsoredFamilies = false
} ) ;
var organizationDomain = new OrganizationDomain
{
OrganizationId = organization . Id ,
DomainName = domainName ,
Txt = "btw+12345" ,
} ;
organizationDomain . SetVerifiedDate ( ) ;
organizationDomain . SetNextRunDate ( 1 2 ) ;
organizationDomain . SetJobRunCount ( ) ;
await organizationDomainRepository . CreateAsync ( organizationDomain ) ;
var orgUser1 = await organizationUserRepository . CreateAsync ( new OrganizationUser
{
Id = CoreHelpers . GenerateComb ( ) ,
OrganizationId = organization . Id ,
UserId = user1 . Id ,
Status = OrganizationUserStatusType . Confirmed ,
Type = OrganizationUserType . Owner ,
ResetPasswordKey = "resetpasswordkey1" ,
AccessSecretsManager = false
} ) ;
await organizationUserRepository . CreateAsync ( new OrganizationUser
{
Id = CoreHelpers . GenerateComb ( ) ,
OrganizationId = organization . Id ,
UserId = user2 . Id ,
Status = OrganizationUserStatusType . Confirmed ,
Type = OrganizationUserType . User ,
ResetPasswordKey = "resetpasswordkey1" ,
AccessSecretsManager = false
} ) ;
await organizationUserRepository . CreateAsync ( new OrganizationUser
{
Id = CoreHelpers . GenerateComb ( ) ,
OrganizationId = organization . Id ,
UserId = user3 . Id ,
Status = OrganizationUserStatusType . Confirmed ,
Type = OrganizationUserType . User ,
ResetPasswordKey = "resetpasswordkey1" ,
AccessSecretsManager = false
} ) ;
var responseModel = await organizationUserRepository . GetManyByOrganizationWithClaimedDomainsAsync ( organization . Id ) ;
Assert . NotNull ( responseModel ) ;
Assert . Single ( responseModel ) ;
Assert . Equal ( orgUser1 . Id , responseModel . Single ( ) . Id ) ;
}
[DatabaseTheory, DatabaseData]
[DatabaseTheory, DatabaseData]
public async Task CreateManyAsync_NoId_Works ( IOrganizationRepository organizationRepository ,
public async Task CreateManyAsync_NoId_Works ( IOrganizationRepository organizationRepository ,
IUserRepository userRepository ,
IUserRepository userRepository ,
@ -369,7 +665,7 @@ public class OrganizationUserRepositoryTests
{
{
Name = $"test-{Guid.NewGuid()}" ,
Name = $"test-{Guid.NewGuid()}" ,
BillingEmail = "billing@example.com" , // TODO: EF does not enforce this being NOT NULL
BillingEmail = "billing@example.com" , // TODO: EF does not enforce this being NOT NULL
Plan = "Test" , // TODO: EF does not enforce this being NOT NULl
Plan = "Test" , // TODO: EF does not enforce this being NOT NULL
} ) ;
} ) ;
var orgUsers = users . Select ( u = > new OrganizationUser
var orgUsers = users . Select ( u = > new OrganizationUser
@ -403,7 +699,7 @@ public class OrganizationUserRepositoryTests
{
{
Name = $"test-{Guid.NewGuid()}" ,
Name = $"test-{Guid.NewGuid()}" ,
BillingEmail = "billing@example.com" , // TODO: EF does not enforce this being NOT NULL
BillingEmail = "billing@example.com" , // TODO: EF does not enforce this being NOT NULL
Plan = "Test" , // TODO: EF does not enforce this being NOT NULl
Plan = "Test" , // TODO: EF does not enforce this being NOT NULL
} ) ;
} ) ;
var orgUsers = users . Select ( u = > new OrganizationUser
var orgUsers = users . Select ( u = > new OrganizationUser
@ -435,8 +731,8 @@ public class OrganizationUserRepositoryTests
var organization = await organizationRepository . CreateAsync ( new Organization
var organization = await organizationRepository . CreateAsync ( new Organization
{
{
Name = "Test Org" ,
Name = "Test Org" ,
BillingEmail = "billing@test.com" , // TODO: EF does not enfore this being NOT NULL
BillingEmail = "billing@test.com" , // TODO: EF does not enforc e this being NOT NULL
Plan = "Test" , // TODO: EF does not enforce this being NOT NULl ,
Plan = "Test" , // TODO: EF does not enforce this being NOT NULL ,
CreationDate = requestTime
CreationDate = requestTime
} ) ;
} ) ;
@ -863,7 +1159,7 @@ public class OrganizationUserRepositoryTests
}
}
[DatabaseTheory, DatabaseData]
[DatabaseTheory, DatabaseData]
public async Task GetManyByOrganizationWithClaimedDomainsAsync_WithVerifiedDomain_WithOneMatchingEmailDomain_ReturnsSingle (
public async Task GetManyByOrganizationWithClaimedDomainsAsync_WithNoVerifiedDomain_ReturnsEmpty (
IUserRepository userRepository ,
IUserRepository userRepository ,
IOrganizationRepository organizationRepository ,
IOrganizationRepository organizationRepository ,
IOrganizationUserRepository organizationUserRepository ,
IOrganizationUserRepository organizationUserRepository ,
@ -885,30 +1181,6 @@ public class OrganizationUserRepositoryTests
AccountRevisionDate = requestTime
AccountRevisionDate = requestTime
} ) ;
} ) ;
var user2 = await userRepository . CreateAsync ( new User
{
Id = CoreHelpers . GenerateComb ( ) ,
Name = "Test User 2" ,
Email = $"test+{id}@x-{domainName}" , // Different domain
ApiKey = "TEST" ,
SecurityStamp = "stamp" ,
CreationDate = requestTime ,
RevisionDate = requestTime ,
AccountRevisionDate = requestTime
} ) ;
var user3 = await userRepository . CreateAsync ( new User
{
Id = CoreHelpers . GenerateComb ( ) ,
Name = "Test User 3" ,
Email = $"test+{id}@{domainName}.example.com" , // Different domain
ApiKey = "TEST" ,
SecurityStamp = "stamp" ,
CreationDate = requestTime ,
RevisionDate = requestTime ,
AccountRevisionDate = requestTime
} ) ;
var organization = await organizationRepository . CreateAsync ( new Organization
var organization = await organizationRepository . CreateAsync ( new Organization
{
{
Id = CoreHelpers . GenerateComb ( ) ,
Id = CoreHelpers . GenerateComb ( ) ,
@ -920,6 +1192,7 @@ public class OrganizationUserRepositoryTests
RevisionDate = requestTime
RevisionDate = requestTime
} ) ;
} ) ;
// Create domain but do NOT verify it
var organizationDomain = new OrganizationDomain
var organizationDomain = new OrganizationDomain
{
{
Id = CoreHelpers . GenerateComb ( ) ,
Id = CoreHelpers . GenerateComb ( ) ,
@ -929,11 +1202,10 @@ public class OrganizationUserRepositoryTests
CreationDate = requestTime
CreationDate = requestTime
} ;
} ;
organizationDomain . SetNextRunDate ( 1 2 ) ;
organizationDomain . SetNextRunDate ( 1 2 ) ;
organizationDomain . SetVerifiedDate ( ) ;
// Note: NOT calling SetVerifiedDate()
organizationDomain . SetJobRunCount ( ) ;
await organizationDomainRepository . CreateAsync ( organizationDomain ) ;
await organizationDomainRepository . CreateAsync ( organizationDomain ) ;
var orgUser1 = await organizationUserRepository . CreateAsync ( new OrganizationUser
await organizationUserRepository . CreateAsync ( new OrganizationUser
{
{
Id = CoreHelpers . GenerateComb ( ) ,
Id = CoreHelpers . GenerateComb ( ) ,
OrganizationId = organization . Id ,
OrganizationId = organization . Id ,
@ -944,99 +1216,124 @@ public class OrganizationUserRepositoryTests
RevisionDate = requestTime
RevisionDate = requestTime
} ) ;
} ) ;
await organizationUserRepository . CreateAsync ( new OrganizationUser
var responseModel = await organizationUserRepository . GetManyByOrganizationWithClaimedDomainsAsync ( organization . Id ) ;
Assert . NotNull ( responseModel ) ;
Assert . Empty ( responseModel ) ;
}
[DatabaseTheory, DatabaseData]
public async Task DeleteAsync_WithNullEmail_DoesNotSetDefaultUserCollectionEmail ( IUserRepository userRepository ,
ICollectionRepository collectionRepository ,
IOrganizationRepository organizationRepository ,
IOrganizationUserRepository organizationUserRepository
)
{
var user = await userRepository . CreateAsync ( new User
{
{
Id = CoreHelpers . GenerateComb ( ) ,
Name = "Test User" ,
OrganizationId = organization . Id ,
Email = $"test+{Guid.NewGuid()}@example.com" ,
UserId = user2 . Id ,
ApiKey = "TEST" ,
Status = OrganizationUserStatusType . Confirmed ,
SecurityStamp = "stamp" ,
Type = OrganizationUserType . User ,
CreationDate = requestTime ,
RevisionDate = requestTime
} ) ;
} ) ;
await organizationUserRepository . CreateAsync ( new OrganizationUser
var organization = await organizationRepository . CreateAsync ( new Organization
{
Name = "Test Org" ,
BillingEmail = user . Email ,
Plan = "Test" ,
} ) ;
var orgUser = await organizationUserRepository . CreateAsync ( new OrganizationUser
{
{
Id = CoreHelpers . GenerateComb ( ) ,
OrganizationId = organization . Id ,
OrganizationId = organization . Id ,
UserId = user3 . Id ,
UserId = user . Id ,
Status = OrganizationUserStatusType . Confirmed ,
Status = OrganizationUserStatusType . Confirmed ,
Type = OrganizationUserType . User ,
Email = null
CreationDate = requestTime ,
RevisionDate = requestTime
} ) ;
} ) ;
var responseModel = await organizationUserRepository . GetManyByOrganizationWithClaimedDomainsAsync ( organization . Id ) ;
var defaultUserCollection = await collectionRepository . CreateAsync ( new Collection
{
Name = "Test Collection" ,
Id = user . Id ,
Type = CollectionType . DefaultUserCollection ,
OrganizationId = organization . Id
} ) ;
Assert . NotNull ( responseModel ) ;
await collectionRepository . UpdateUsersAsync ( defaultUserCollection . Id , new List < CollectionAccessSelection > ( )
Assert . Single ( responseModel ) ;
{
Assert . Equal ( orgUser1 . Id , responseModel . Single ( ) . Id ) ;
new CollectionAccessSelection
Assert . Equal ( user1 . Id , responseModel . Single ( ) . UserId ) ;
{
Assert . Equal ( organization . Id , responseModel . Single ( ) . OrganizationId ) ;
Id = orgUser . Id ,
HidePasswords = false ,
ReadOnly = false ,
Manage = true
} ,
} ) ;
await organizationUserRepository . DeleteAsync ( orgUser ) ;
var updatedCollection = await collectionRepository . GetByIdAsync ( defaultUserCollection . Id ) ;
Assert . NotNull ( updatedCollection ) ;
Assert . Equal ( CollectionType . SharedCollection , updatedCollection . Type ) ;
Assert . Equal ( user . Email , updatedCollection . DefaultUserCollectionEmail ) ;
}
}
[DatabaseTheory, DatabaseData]
[DatabaseTheory, DatabaseData]
public async Task GetManyByOrganizationWithClaimedDomainsAsync_WithNoVerifiedDomain_ReturnsEmpty (
public async Task DeleteAsync_WithEmptyEmail_DoesNotSetDefaultUserCollectionEmail ( IUserRepository userRepository ,
IUserRepository userRepository ,
ICollectionRepository collection Repository ,
IOrganizationRepository organizationRepository ,
IOrganizationRepository organizationRepository ,
IOrganizationUserRepository organizationUserRepository ,
IOrganizationUserRepository organizationUserRepository
IOrganizationDomainRepository organizationDomainRepository )
)
{
{
var id = Guid . NewGuid ( ) ;
var user = await userRepository . CreateAsync ( new User
var domainName = $"{id}.example.com" ;
var requestTime = DateTime . UtcNow ;
var user1 = await userRepository . CreateAsync ( new User
{
{
Id = CoreHelpers . GenerateComb ( ) ,
Name = "Test User" ,
Name = "Test User 1" ,
Email = $"test+{Guid.NewGuid()}@example.com" ,
Email = $"test+{id}@{domainName}" ,
ApiKey = "TEST" ,
ApiKey = "TEST" ,
SecurityStamp = "stamp" ,
SecurityStamp = "stamp" ,
CreationDate = requestTime ,
RevisionDate = requestTime ,
AccountRevisionDate = requestTime
} ) ;
} ) ;
var organization = await organizationRepository . CreateAsync ( new Organization
var organization = await organizationRepository . CreateAsync ( new Organization
{
{
Id = CoreHelpers . GenerateComb ( ) ,
Name = "Test Org" ,
Name = $"Test Org {id}" ,
BillingEmail = user . Email ,
BillingEmail = user1 . Email ,
Plan = "Test" ,
Plan = "Test" ,
Enabled = true ,
CreationDate = requestTime ,
RevisionDate = requestTime
} ) ;
} ) ;
// Create domain but do NOT verify it
var orgUser = await organizationUserRepository . CreateAsync ( new OrganizationUser
var organizationDomain = new OrganizationDomain
{
{
Id = CoreHelpers . GenerateComb ( ) ,
OrganizationId = organization . Id ,
OrganizationId = organization . Id ,
DomainName = domainName ,
UserId = user . Id ,
Txt = "btw+12345" ,
Status = OrganizationUserStatusType . Confirmed ,
CreationDate = requestTime
Email = "" // Empty string email
} ;
} ) ;
organizationDomain . SetNextRunDate ( 1 2 ) ;
// Note: NOT calling SetVerifiedDate()
await organizationDomainRepository . CreateAsync ( organizationDomain ) ;
await organizationUser Repository. CreateAsync ( new OrganizationUser
var defaultUserCollection = await collectionRepository . CreateAsync ( new Collection
{
{
Id = CoreHelpers . GenerateComb ( ) ,
Name = "Test Collection" ,
OrganizationId = organization . Id ,
Id = user . Id ,
UserId = user1 . Id ,
Type = CollectionType . DefaultUserCollection ,
Status = OrganizationUserStatusType . Confirmed ,
OrganizationId = organization . Id
Type = OrganizationUserType . Owner ,
CreationDate = requestTime ,
RevisionDate = requestTime
} ) ;
} ) ;
var responseModel = await organizationUserRepository . GetManyByOrganizationWithClaimedDomainsAsync ( organization . Id ) ;
await collectionRepository . UpdateUsersAsync ( defaultUserCollection . Id , new List < CollectionAccessSelection > ( )
{
new CollectionAccessSelection
{
Id = orgUser . Id ,
HidePasswords = false ,
ReadOnly = false ,
Manage = true
} ,
} ) ;
Assert . NotNull ( responseModel ) ;
await organizationUserRepository . DeleteAsync ( orgUser ) ;
Assert . Empty ( responseModel ) ;
var updatedCollection = await collectionRepository . GetByIdAsync ( defaultUserCollection . Id ) ;
Assert . NotNull ( updatedCollection ) ;
Assert . Equal ( CollectionType . SharedCollection , updatedCollection . Type ) ;
Assert . Equal ( user . Email , updatedCollection . DefaultUserCollectionEmail ) ;
}
}
[DatabaseTheory, DatabaseData]
[DatabaseTheory, DatabaseData]