diff --git a/src/administration/Administration.Service/BusinessLogic/UserUploadBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/UserUploadBusinessLogic.cs index ebe1bae377..ab35c7e4c1 100644 --- a/src/administration/Administration.Service/BusinessLogic/UserUploadBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/UserUploadBusinessLogic.cs @@ -209,7 +209,7 @@ await GetUserRoleDatas(parsed.Roles, validRoleData, _identityData.CompanyId).Con _mailingProcessCreation.CreateMailProcess(creationData.UserCreationInfo.Email, "NewUserPasswordTemplate", mailParameters); }, cancellationToken) - .Select(x => (x.CompanyUserId != Guid.Empty, x.Error)), + .Select(x => (x.Error == null, x.Error)), cancellationToken).ConfigureAwait(false); return new UserCreationStats( diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/UserUploadBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/UserUploadBusinessLogicTests.cs index 0af2fda6b9..d10ba8fc61 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/UserUploadBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/UserUploadBusinessLogicTests.cs @@ -404,6 +404,45 @@ public async Task TestUserCreationSharedIdpNoRolesError() .MustHaveHappened(4, Times.Exactly); } + [Fact] + public async Task TestDuplicateUserCreationError() + { + var creationInfo = _fixture.Create(); + var detailError = ConflictException.Create(ProvisioningServiceErrors.USER_CREATION_FAILURE, [new("userName", "foo"), new("realm", "bar")]); + + SetupFakes([ + HeaderLineSharedIdp(), + NextLineSharedIdp(), + NextLineSharedIdp(creationInfo), + NextLineSharedIdp() + ]); + + A.CallTo(() => _processLine(A._, A.That.Matches(info => CreationInfoMatchesSharedIdp(info, creationInfo)), A>._)) + .ReturnsLazily( + (CompanyNameIdpAliasData _, UserCreationRoleDataIdpInfo creationInfo, Action? _) => _fixture.Build<(Guid CompanyUserId, string UserName, string? Password, Exception? Error)>() + .With(x => x.CompanyUserId, Guid.NewGuid()) + .With(x => x.UserName, creationInfo.UserName) + .With(x => x.Error, detailError) + .Create()); + + var sut = new UserUploadBusinessLogic(_userProvisioningService, _identityProviderProvisioningService, _mailingProcessCreation, _identityService, _errorMessageService, _options); + + var result = await sut.UploadOwnCompanySharedIdpUsersAsync(_document, CancellationToken.None); + + A.CallTo(() => _processLine(A._, A.That.Matches(info => CreationInfoMatchesSharedIdp(info, creationInfo)), A>._)).MustHaveHappened(); + + result.Should().NotBeNull(); + result.Created.Should().Be(2); + result.Error.Should().Be(1); + result.Total.Should().Be(3); + result.Errors.Should().HaveCount(1); + result.Errors.Should().ContainSingle().Which.Should().Match(x => x.Line == 2 && x.Message.Contains("USER_CREATION_FAILURE")); + A.CallTo(() => _mailingProcessCreation.CreateMailProcess(A._, "NewUserTemplate", A>._)) + .MustHaveHappened(2, Times.Exactly); + A.CallTo(() => _mailingProcessCreation.CreateMailProcess(A._, "NewUserPasswordTemplate", A>._)) + .MustHaveHappened(2, Times.Exactly); + } + [Fact] public async Task TestUserCreationSharedIdpCreationError() {