Skip to content
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

fix(subscriptionConfig): adjust url null case #783

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ private async Task SetOfferProviderCompanyDetailsInternalAsync(ProviderDetailDat
var providerDetailData = await companyRepository
.GetProviderCompanyDetailsExistsForUser(companyId)
.ConfigureAwait(ConfigureAwaitOptions.None);
var hasChanges = false;
if (providerDetailData == default && data.Url != null)
{
await HandleCreateProviderCompanyDetails(data, companyId, companyRepository);
hasChanges = true;
}
else if (data.Url != null)
else if (providerDetailData != default && data.Url != null)
{
companyRepository.AttachAndModifyProviderCompanyDetails(
providerDetailData.ProviderCompanyDetailId,
Expand All @@ -96,13 +98,18 @@ private async Task SetOfferProviderCompanyDetailsInternalAsync(ProviderDetailDat
details.AutoSetupUrl = data.Url;
details.DateLastChanged = DateTimeOffset.UtcNow;
});
hasChanges = true;
}
else
else if (providerDetailData != default && data.Url == null)
{
companyRepository.RemoveProviderCompanyDetails(providerDetailData.ProviderCompanyDetailId);
hasChanges = true;
}

await _portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
if (hasChanges)
{
await _portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);
}
}

private static async Task HandleCreateProviderCompanyDetails(ProviderDetailData data, Guid companyId, ICompanyRepository companyRepository)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,30 @@ public async Task SetProviderCompanyDetailsAsync_EmptyProviderDetailsId_ReturnsE
// Assert
A.CallTo(() => _companyRepository.CreateProviderCompanyDetail(A<Guid>._, A<string>._, A<Action<ProviderCompanyDetail>>._)).MustHaveHappened();
A.CallTo(() => _companyRepository.AttachAndModifyProviderCompanyDetails(A<Guid>._, A<Action<ProviderCompanyDetail>>._, A<Action<ProviderCompanyDetail>>._)).MustNotHaveHappened();
A.CallTo(() => _portalRepositories.SaveAsync()).MustHaveHappened(1, Times.OrMore);
A.CallTo(() => _portalRepositories.SaveAsync()).MustHaveHappenedOnceExactly();
_serviceProviderDetails.Should().ContainSingle();
}

[Fact]
public async Task SetProviderCompanyDetailsAsync_WithNotExistingAndUrlNull_DoesNothing()
{
// Arrange
SetupProviderCompanyDetails();
var providerDetailData = new ProviderDetailData(null, null);
A.CallTo(() => _companyRepository.GetProviderCompanyDetailsExistsForUser(ExistingCompanyId))
.Returns((Guid.Empty, null!));

// Act
await _sut.SetProviderCompanyDetailsAsync(providerDetailData);

// Assert
A.CallTo(() => _companyRepository.CreateProviderCompanyDetail(A<Guid>._, A<string>._, A<Action<ProviderCompanyDetail>>._)).MustNotHaveHappened();
A.CallTo(() => _companyRepository.RemoveProviderCompanyDetails(A<Guid>._)).MustNotHaveHappened();
A.CallTo(() => _companyRepository.AttachAndModifyProviderCompanyDetails(A<Guid>._, A<Action<ProviderCompanyDetail>>._, A<Action<ProviderCompanyDetail>>._)).MustNotHaveHappened();
A.CallTo(() => _portalRepositories.SaveAsync()).MustNotHaveHappened();
_serviceProviderDetails.Should().BeEmpty();
}

[Fact]
public async Task SetProviderCompanyDetailsAsync_WithProviderDetailsAndNoUrl_RemovesProviderDetails()
{
Expand Down Expand Up @@ -255,7 +275,7 @@ public async Task SetProviderCompanyDetailsAsync_WithServiceProviderDetailsId_Re
//Assert
A.CallTo(() => _companyRepository.CreateProviderCompanyDetail(A<Guid>._, A<string>._, null)).MustNotHaveHappened();
A.CallTo(() => _companyRepository.AttachAndModifyProviderCompanyDetails(detailsId, A<Action<ProviderCompanyDetail>>._, A<Action<ProviderCompanyDetail>>._)).MustHaveHappenedOnceExactly();
A.CallTo(() => _portalRepositories.SaveAsync()).MustHaveHappened(1, Times.OrMore);
A.CallTo(() => _portalRepositories.SaveAsync()).MustHaveHappenedOnceExactly();
initialDetail.Should().NotBeNull();
initialDetail!.AutoSetupUrl.Should().Be(existingUrl);
modifyDetail.Should().NotBeNull();
Expand Down
Loading