-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AC-2471] Prevent calls to Stripe when unlinking client org has no Stripe objects #3999
Merged
amorask-bitwarden
merged 10 commits into
main
from
billing/AC-2471/unlink-client-without-stripe
May 9, 2024
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2f153c8
Prevent calls to Stripe when unlinking client org has no Stripe objects
amorask-bitwarden bb65f38
Merge branch 'main' into billing/AC-2471/unlink-client-without-stripe
amorask-bitwarden 2dad72a
Thomas' feedback
amorask-bitwarden fe3ad0b
Merge branch 'main' into billing/AC-2471/unlink-client-without-stripe
amorask-bitwarden 6003d10
Merge branch 'main' into billing/AC-2471/unlink-client-without-stripe
amorask-bitwarden fd2f396
Merge branch 'main' into billing/AC-2471/unlink-client-without-stripe
cturnbull-bitwarden cca6d2d
Merge branch 'main' into billing/AC-2471/unlink-client-without-stripe
amorask-bitwarden fe59e0a
Check for stripe when org unlinked from org page
amorask-bitwarden 4f071e8
Merge branch 'main' into billing/AC-2471/unlink-client-without-stripe
amorask-bitwarden 564dd15
Merge branch 'main' into billing/AC-2471/unlink-client-without-stripe
amorask-bitwarden File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
using NSubstitute; | ||
using Stripe; | ||
using Xunit; | ||
using IMailService = Bit.Core.Services.IMailService; | ||
|
||
namespace Bit.Commercial.Core.Test.AdminConsole.ProviderFeatures; | ||
|
||
|
@@ -80,6 +81,55 @@ public class RemoveOrganizationFromProviderCommandTests | |
Assert.Equal("Organization must have at least one confirmed owner.", exception.Message); | ||
} | ||
|
||
[Theory, BitAutoData] | ||
public async Task RemoveOrganizationFromProvider_NoStripeObjects_MakesCorrectInvocations( | ||
Provider provider, | ||
ProviderOrganization providerOrganization, | ||
Organization organization, | ||
SutProvider<RemoveOrganizationFromProviderCommand> sutProvider) | ||
{ | ||
organization.GatewayCustomerId = null; | ||
organization.GatewaySubscriptionId = null; | ||
|
||
providerOrganization.ProviderId = provider.Id; | ||
|
||
var organizationRepository = sutProvider.GetDependency<IOrganizationRepository>(); | ||
|
||
sutProvider.GetDependency<IOrganizationService>().HasConfirmedOwnersExceptAsync( | ||
providerOrganization.OrganizationId, | ||
Array.Empty<Guid>(), | ||
includeProvider: false) | ||
.Returns(true); | ||
|
||
var organizationOwnerEmails = new List<string> { "[email protected]", "[email protected]" }; | ||
|
||
organizationRepository.GetOwnerEmailAddressesById(organization.Id).Returns(organizationOwnerEmails); | ||
|
||
await sutProvider.Sut.RemoveOrganizationFromProvider(provider, providerOrganization, organization); | ||
|
||
await organizationRepository.Received(1).ReplaceAsync(Arg.Is<Organization>( | ||
org => org.Id == organization.Id && org.BillingEmail == "[email protected]")); | ||
|
||
var stripeAdapter = sutProvider.GetDependency<IStripeAdapter>(); | ||
|
||
await stripeAdapter.DidNotReceiveWithAnyArgs().CustomerUpdateAsync(Arg.Any<string>(), Arg.Any<CustomerUpdateOptions>()); | ||
|
||
await stripeAdapter.DidNotReceiveWithAnyArgs().SubscriptionUpdateAsync(Arg.Any<string>(), Arg.Any<SubscriptionUpdateOptions>()); | ||
|
||
await sutProvider.GetDependency<IMailService>().DidNotReceiveWithAnyArgs().SendProviderUpdatePaymentMethod( | ||
Arg.Any<Guid>(), | ||
Arg.Any<string>(), | ||
Arg.Any<string>(), | ||
Arg.Any<IEnumerable<string>>()); | ||
|
||
await sutProvider.GetDependency<IProviderOrganizationRepository>().Received(1) | ||
.DeleteAsync(providerOrganization); | ||
|
||
await sutProvider.GetDependency<IEventService>().Received(1).LogProviderOrganizationEventAsync( | ||
providerOrganization, | ||
EventType.ProviderOrganization_Removed); | ||
} | ||
|
||
[Theory, BitAutoData] | ||
public async Task RemoveOrganizationFromProvider_MakesCorrectInvocations( | ||
Provider provider, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be part of the command? Or are you trying to avoid calling a command from within a command?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, originally I had
RemoveOrganizationFromProviderCommand
invokeRemovePaymentMethodCommand
, but I was told not to do so when this was originally implemented.