Skip to content

Commit

Permalink
fix review points
Browse files Browse the repository at this point in the history
  • Loading branch information
tfjanjua committed Dec 23, 2024
1 parent e0c0f5f commit 4084a3a
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ await _mailingProcessCreation.RoleBaseSendMail(

public async Task<Guid> RemoveOfferSubscriptionAsync(Guid subscriptionId, OfferTypeId offerTypeId, string basePortalAddress)
{
var offerSubscriptionsRepository = _portalRepositories.GetInstance<IOfferSubscriptionsRepository>();
var offerSubscriptionDetails = await offerSubscriptionsRepository.GetOfferDetailsAndCheckProviderCompany(subscriptionId, _identityData.CompanyId, offerTypeId) ?? throw new NotFoundException($"Subscription {subscriptionId} does not exist.");
var offerSubscriptionDetails = await _portalRepositories.GetInstance<IOfferSubscriptionsRepository>()
.GetOfferDetailsAndCheckProviderCompany(subscriptionId, _identityData.CompanyId, offerTypeId) ?? throw new NotFoundException($"Subscription {subscriptionId} does not exist.");
var offerId = offerSubscriptionDetails.OfferId;

if (string.IsNullOrEmpty(offerSubscriptionDetails.OfferName))
Expand All @@ -117,12 +117,12 @@ public async Task<Guid> RemoveOfferSubscriptionAsync(Guid subscriptionId, OfferT
{
throw new ForbiddenException("Only the providing company can decline the subscription request.");
}
if (offerSubscriptionDetails.Status == OfferSubscriptionStatusId.INACTIVE)
if (offerSubscriptionDetails.Status != OfferSubscriptionStatusId.PENDING)
{
throw new ConflictException($"Subscription of {offerSubscriptionDetails.OfferName} is already {offerSubscriptionDetails.Status}");
throw new ConflictException($"Subscription of {offerSubscriptionDetails.OfferName} should be in {OfferSubscriptionStatusId.PENDING} state.");
}

var offerSubscription = offerSubscriptionsRepository.DeleteOfferSubscription(subscriptionId, offerId, offerSubscriptionDetails.CompanyId, offerSubscriptionDetails.Status, offerSubscriptionDetails.RequesterId);
var offerSubscription = _portalRepositories.Remove(new OfferSubscription(subscriptionId, offerId, offerSubscriptionDetails.CompanyId, offerSubscriptionDetails.Status, offerSubscriptionDetails.RequesterId, DateTimeOffset.UtcNow));
SendNotificationsToRequester(offerId, offerTypeId, basePortalAddress, offerSubscriptionDetails);
await _portalRepositories.SaveAsync().ConfigureAwait(ConfigureAwaitOptions.None);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ public interface IOfferSubscriptionsRepository
/// <param name="creatorId">id of the creator</param>
OfferSubscription CreateOfferSubscription(Guid offerId, Guid companyId, OfferSubscriptionStatusId offerSubscriptionStatusId, Guid requesterId);

/// <summary>
/// Deletes the given company assigned offer's subscription from the database
/// </summary>
/// <param name="offerId">Id of the assigned offer</param>
/// <param name="companyId">Id of the company</param>
/// <param name="offerSubscriptionStatusId">id of the offer subscription</param>
/// <param name="requesterId">id of the user that requested the subscription of the offer</param>
/// <param name="creatorId">id of the creator</param>
OfferSubscription DeleteOfferSubscription(Guid subscriptionId, Guid offerId, Guid companyId, OfferSubscriptionStatusId offerSubscriptionStatusId, Guid requesterId);

/// <summary>
/// Gets the provided offer subscription statuses for the user and given company
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public class OfferSubscriptionsRepository(PortalDbContext dbContext) : IOfferSub
public OfferSubscription CreateOfferSubscription(Guid offerId, Guid companyId, OfferSubscriptionStatusId offerSubscriptionStatusId, Guid requesterId) =>
dbContext.OfferSubscriptions.Add(new OfferSubscription(Guid.NewGuid(), offerId, companyId, offerSubscriptionStatusId, requesterId, DateTimeOffset.UtcNow)).Entity;

/// <inheritdoc />
public OfferSubscription DeleteOfferSubscription(Guid subscriptionId, Guid offerId, Guid companyId, OfferSubscriptionStatusId offerSubscriptionStatusId, Guid requesterId) =>
dbContext.OfferSubscriptions.Remove(new OfferSubscription(subscriptionId, offerId, companyId, offerSubscriptionStatusId, requesterId, DateTimeOffset.UtcNow)).Entity;

/// <inheritdoc />
public Func<int, int, Task<Pagination.Source<OfferCompanySubscriptionStatusData>?>> GetOwnCompanyProvidedOfferSubscriptionStatusesUntrackedAsync(Guid userCompanyId, OfferTypeId offerTypeId, SubscriptionStatusSorting? sorting, IEnumerable<OfferSubscriptionStatusId> statusIds, Guid? offerId, string? companyName) =>
(skip, take) => Pagination.CreateSourceQueryAsync(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
using Microsoft.EntityFrameworkCore.Migrations;
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

// <auto-generated />
using System;
using System.Text.Json;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,16 +493,15 @@ public async Task RemoveOfferSubscription_ReturnsExpected(OfferTypeId offerTypeI
var subscription = new OfferSubscription();

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning test

This assignment to
subscription
is useless, since its value is never read.
A.CallTo(() => _offerSubscriptionsRepository.GetOfferDetailsAndCheckProviderCompany(A<Guid>._, A<Guid>._, offerTypeId))
.Returns(offerSubscriptionDetails);
A.CallTo(() => _offerSubscriptionsRepository.DeleteOfferSubscription(A<Guid>._, A<Guid>._, A<Guid>._, A<OfferSubscriptionStatusId>._, A<Guid>._))
.Returns(subscription);
A.CallTo(() => _portalRepositories.Remove(A<OfferSubscription>._));

// Act
await _sut.RemoveOfferSubscriptionAsync(_validSubscriptionId, offerTypeId, BasePortalUrl);

// Assert
A.CallTo(() => _offerSubscriptionsRepository.GetOfferDetailsAndCheckProviderCompany(_validSubscriptionId, _identity.CompanyId, offerTypeId))
.MustHaveHappenedOnceExactly();
A.CallTo(() => _offerSubscriptionsRepository.DeleteOfferSubscription(_validSubscriptionId, offerSubscriptionDetails.OfferId, offerSubscriptionDetails.CompanyId, offerSubscriptionDetails.Status, offerSubscriptionDetails.RequesterId))
A.CallTo(() => _portalRepositories.Remove(A<OfferSubscription>._))
.MustHaveHappenedOnceExactly();
A.CallTo(() => _notificationRepository.CreateNotification(offerSubscriptionDetails.RequesterId,
offerTypeId == OfferTypeId.SERVICE
Expand All @@ -517,6 +516,7 @@ public async Task RemoveOfferSubscription_ReturnsExpected(OfferTypeId offerTypeI
&& x["url"] == BasePortalUrl
&& x["requesterName"] == string.Format("{0} {1}", offerSubscriptionDetails.RequesterFirstname, offerSubscriptionDetails.RequesterLastname))
)).MustHaveHappenedOnceExactly();
A.CallTo(() => _portalRepositories.SaveAsync()).MustHaveHappenedOnceExactly();
}

[Theory]
Expand All @@ -538,7 +538,7 @@ public async Task RemoveOfferSubscription_NoOfferDetails_ThrowsNotFoundException
var ex = await Assert.ThrowsAsync<NotFoundException>(Action);
A.CallTo(() => _offerSubscriptionsRepository.GetOfferDetailsAndCheckProviderCompany(_validSubscriptionId, _identity.CompanyId, offerTypeId))
.MustHaveHappenedOnceExactly();
A.CallTo(() => _offerSubscriptionsRepository.DeleteOfferSubscription(_validSubscriptionId, A<Guid>._, A<Guid>._, A<OfferSubscriptionStatusId>._, A<Guid>._))
A.CallTo(() => _portalRepositories.Remove(A<OfferSubscription>._))
.MustNotHaveHappened();
A.CallTo(() => _notificationRepository.CreateNotification(A<Guid>._, A<NotificationTypeId>._, false, A<Action<Notification>>._))
.MustNotHaveHappened();
Expand Down Expand Up @@ -566,7 +566,7 @@ public async Task RemoveOfferSubscription_NotProviderCompany_ThrowsForbiddenExce
var ex = await Assert.ThrowsAsync<ForbiddenException>(Action);
A.CallTo(() => _offerSubscriptionsRepository.GetOfferDetailsAndCheckProviderCompany(_validSubscriptionId, _identity.CompanyId, offerTypeId))
.MustHaveHappenedOnceExactly();
A.CallTo(() => _offerSubscriptionsRepository.DeleteOfferSubscription(_validSubscriptionId, A<Guid>._, A<Guid>._, A<OfferSubscriptionStatusId>._, A<Guid>._))
A.CallTo(() => _portalRepositories.Remove(A<OfferSubscription>._))
.MustNotHaveHappened();
A.CallTo(() => _notificationRepository.CreateNotification(A<Guid>._, A<NotificationTypeId>._, false, A<Action<Notification>>._))
.MustNotHaveHappened();
Expand Down Expand Up @@ -595,13 +595,13 @@ public async Task RemoveOfferSubscription_AlreadyInActiveSubscription_ThrowsConf
var ex = await Assert.ThrowsAsync<ConflictException>(Action);
A.CallTo(() => _offerSubscriptionsRepository.GetOfferDetailsAndCheckProviderCompany(_validSubscriptionId, _identity.CompanyId, offerTypeId))
.MustHaveHappenedOnceExactly();
A.CallTo(() => _offerSubscriptionsRepository.DeleteOfferSubscription(_validSubscriptionId, A<Guid>._, A<Guid>._, A<OfferSubscriptionStatusId>._, A<Guid>._))
A.CallTo(() => _portalRepositories.Remove(A<OfferSubscription>._))
.MustNotHaveHappened();
A.CallTo(() => _notificationRepository.CreateNotification(A<Guid>._, A<NotificationTypeId>._, false, A<Action<Notification>>._))
.MustNotHaveHappened();
A.CallTo(() => _mailingProcessCreation.CreateMailProcess(A<string>._, A<string>._, A<IReadOnlyDictionary<string, string>>._))
.MustNotHaveHappened();
ex.Message.Should().Be($"Subscription of {offerSubscriptionDetails.OfferName} is already {offerSubscriptionDetails.Status}");
ex.Message.Should().Be($"Subscription of {offerSubscriptionDetails.OfferName} should be in {OfferSubscriptionStatusId.PENDING} state.");
}

[Theory]
Expand All @@ -620,8 +620,8 @@ public async Task RemoveOfferSubscription_NoSubscriptionDetails_ThrowsNotFoundEx
var ex = await Assert.ThrowsAsync<NotFoundException>(Action);
A.CallTo(() => _offerSubscriptionsRepository.GetOfferDetailsAndCheckProviderCompany(_validSubscriptionId, _identity.CompanyId, offerTypeId))
.MustHaveHappenedOnceExactly();
A.CallTo(() => _offerSubscriptionsRepository.DeleteOfferSubscription(_validSubscriptionId, A<Guid>._, A<Guid>._, A<OfferSubscriptionStatusId>._, A<Guid>._))
.MustNotHaveHappened();
A.CallTo(() => _portalRepositories.Remove(A<OfferSubscription>._)).
MustNotHaveHappened();
A.CallTo(() => _notificationRepository.CreateNotification(A<Guid>._, A<NotificationTypeId>._, false, A<Action<Notification>>._))
.MustNotHaveHappened();
A.CallTo(() => _mailingProcessCreation.CreateMailProcess(A<string>._, A<string>._, A<IReadOnlyDictionary<string, string>>._))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1156,15 +1156,17 @@ public async Task CreateOfferSubscription_ReturnsExpectedResult()
public async Task DeleteOfferSubscription_ReturnsExpectedResult()
{
// Arrange
var (sut, context) = await CreateSut();
var context = await _dbTestDbFixture.GetPortalDbContext();
var sut = new PortalRepositories(context);

// Act
var results = sut.DeleteOfferSubscription(
var results = sut.Remove(new OfferSubscription(
new Guid("eb98bdf5-14e1-4feb-a954-453eac0b93cd"),
new Guid("ac1cf001-7fbc-1f2f-817f-bce0572c0007"),
new Guid("2dc4249f-b5ca-4d42-bef1-7a7a950a4f87"),
OfferSubscriptionStatusId.PENDING,
new Guid("0dcd8209-85e2-4073-b130-ac094fb47106"));
new Guid("0dcd8209-85e2-4073-b130-ac094fb47106"),
DateTimeOffset.UtcNow));

// Assert
var changeTracker = context.ChangeTracker;
Expand Down

0 comments on commit 4084a3a

Please sign in to comment.