Skip to content

Commit

Permalink
[pm-17217] Address code review
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyVo16 committed Jan 24, 2025
1 parent 6a32457 commit 70c2287
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ public async Task Accept(Guid orgId, Guid organizationUserId, [FromBody] Organiz

private async Task<bool> ShouldHandleResetPasswordAsync(Guid orgId)
{
var organization = await _organizationRepository.GetByIdAsync(orgId);
var organizationAbility = await _applicationCacheService.GetOrganizationAbilityAsync(orgId);

if (organization is not { UsePolicies: true })
if (organizationAbility is not { UsePolicies: true })
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ public async Task Accept_WhenOrganizationUsePoliciesIsEnabledAndResetPolicyIsEna
OrganizationUserAcceptRequestModel model, User user, SutProvider<OrganizationUsersController> sutProvider)
{
// Arrange
var providerUserRepository = sutProvider.GetDependency<IOrganizationRepository>();
providerUserRepository.GetByIdAsync(orgId).Returns(new Organization { UsePolicies = true });
var applicationCacheService = sutProvider.GetDependency<IApplicationCacheService>();
applicationCacheService.GetOrganizationAbilityAsync(orgId).Returns(new OrganizationAbility { UsePolicies = true });

var policy = new Policy
{
Expand All @@ -138,6 +138,7 @@ public async Task Accept_WhenOrganizationUsePoliciesIsEnabledAndResetPolicyIsEna
var userService = sutProvider.GetDependency<IUserService>();
userService.GetUserByPrincipalAsync(default).ReturnsForAnyArgs(user);


var policyRepository = sutProvider.GetDependency<IPolicyRepository>();
policyRepository.GetByOrganizationIdTypeAsync(orgId,
PolicyType.ResetPassword).Returns(policy);
Expand All @@ -151,8 +152,8 @@ await sutProvider.GetDependency<IAcceptOrgUserCommand>().Received(1)
await sutProvider.GetDependency<IOrganizationService>().Received(1)
.UpdateUserResetPasswordEnrollmentAsync(orgId, user.Id, model.ResetPasswordKey, user.Id);


await userService.Received(1).GetUserByPrincipalAsync(default);
await applicationCacheService.Received(1).GetOrganizationAbilityAsync(orgId);
await policyRepository.Received(1).GetByOrganizationIdTypeAsync(orgId, PolicyType.ResetPassword);

}
Expand All @@ -163,8 +164,8 @@ public async Task Accept_WhenOrganizationUsePoliciesIsDisabled_ShouldNotHandleRe
OrganizationUserAcceptRequestModel model, User user, SutProvider<OrganizationUsersController> sutProvider)
{
// Arrange
var providerUserRepository = sutProvider.GetDependency<IOrganizationRepository>();
providerUserRepository.GetByIdAsync(orgId).Returns(new Organization { UsePolicies = false });
var applicationCacheService = sutProvider.GetDependency<IApplicationCacheService>();
applicationCacheService.GetOrganizationAbilityAsync(orgId).Returns(new OrganizationAbility { UsePolicies = false });

var policy = new Policy
{
Expand All @@ -185,10 +186,11 @@ public async Task Accept_WhenOrganizationUsePoliciesIsDisabled_ShouldNotHandleRe
await userService.Received(1).GetUserByPrincipalAsync(default);
await sutProvider.GetDependency<IAcceptOrgUserCommand>().Received(1)
.AcceptOrgUserByEmailTokenAsync(orgUserId, user, model.Token, userService);

await sutProvider.GetDependency<IOrganizationService>().Received(0)
.UpdateUserResetPasswordEnrollmentAsync(orgId, user.Id, model.ResetPasswordKey, user.Id);

await policyRepository.Received(0).GetByOrganizationIdTypeAsync(orgId, PolicyType.ResetPassword);
await applicationCacheService.Received(1).GetOrganizationAbilityAsync(orgId);
}

[Theory]
Expand Down

0 comments on commit 70c2287

Please sign in to comment.