Skip to content

Commit

Permalink
Merge branch 'main' into billing/AC-2576/replace-cqrs-services
Browse files Browse the repository at this point in the history
  • Loading branch information
amorask-bitwarden committed May 14, 2024
2 parents 54824b0 + fd173e8 commit e5c477e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/Api/Billing/Controllers/ProviderClientsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,17 @@ public class ProviderClientsController(
return TypedResults.Problem();
}

await providerBillingService.AssignSeatsToClientOrganization(
provider,
clientOrganization,
requestBody.AssignedSeats);
if (clientOrganization.Seats != requestBody.AssignedSeats)
{
await providerBillingService.AssignSeatsToClientOrganization(
provider,
clientOrganization,
requestBody.AssignedSeats);
}

clientOrganization.Name = requestBody.Name;

await organizationRepository.ReplaceAsync(clientOrganization);

return TypedResults.Ok();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ public class UpdateClientOrganizationRequestBody
[Required]
[Range(0, int.MaxValue, ErrorMessage = "You cannot assign negative seats to a client organization.")]
public int AssignedSeats { get; set; }

[Required]
public string Name { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public class ProviderClientsControllerTests
}

[Theory, BitAutoData]
public async Task UpdateAsync_NoContent(
public async Task UpdateAsync_AssignedSeats_NoContent(
Guid providerId,
Guid providerOrganizationId,
UpdateClientOrganizationRequestBody requestBody,
Expand Down Expand Up @@ -333,6 +333,50 @@ await sutProvider.GetDependency<IProviderBillingService>().Received(1)
organization,
requestBody.AssignedSeats);

await sutProvider.GetDependency<IOrganizationRepository>().Received(1)
.ReplaceAsync(Arg.Is<Organization>(org => org.Name == requestBody.Name));

Assert.IsType<Ok>(result);
}

[Theory, BitAutoData]
public async Task UpdateAsync_Name_NoContent(
Guid providerId,
Guid providerOrganizationId,
UpdateClientOrganizationRequestBody requestBody,
Provider provider,
ProviderOrganization providerOrganization,
Organization organization,
SutProvider<ProviderClientsController> sutProvider)
{
sutProvider.GetDependency<IFeatureService>().IsEnabled(FeatureFlagKeys.EnableConsolidatedBilling)
.Returns(true);

sutProvider.GetDependency<ICurrentContext>().ProviderProviderAdmin(providerId)
.Returns(true);

sutProvider.GetDependency<IProviderRepository>().GetByIdAsync(providerId)
.Returns(provider);

sutProvider.GetDependency<IProviderOrganizationRepository>().GetByIdAsync(providerOrganizationId)
.Returns(providerOrganization);

sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(providerOrganization.OrganizationId)
.Returns(organization);

requestBody.AssignedSeats = organization.Seats!.Value;

var result = await sutProvider.Sut.UpdateAsync(providerId, providerOrganizationId, requestBody);

await sutProvider.GetDependency<IAssignSeatsToClientOrganizationCommand>().DidNotReceiveWithAnyArgs()

Check failure on line 371 in test/Api.Test/Billing/Controllers/ProviderClientsControllerTests.cs

View workflow job for this annotation

GitHub Actions / Run tests

The type or namespace name 'IAssignSeatsToClientOrganizationCommand' could not be found (are you missing a using directive or an assembly reference?)
.AssignSeatsToClientOrganization(
Arg.Any<Provider>(),
Arg.Any<Organization>(),
Arg.Any<int>());

await sutProvider.GetDependency<IOrganizationRepository>().Received(1)
.ReplaceAsync(Arg.Is<Organization>(org => org.Name == requestBody.Name));

Assert.IsType<Ok>(result);
}
#endregion
Expand Down

0 comments on commit e5c477e

Please sign in to comment.