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(apps and services):- post offerId/agreementconsent #173

Merged
Show file tree
Hide file tree
Changes from all 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 @@ -158,18 +158,15 @@ public async Task<OfferAgreementConsent> GetOfferAgreementConsentById(Guid appId
}

/// <inheritdoc/>
public Task<IEnumerable<ConsentStatusData>> SubmitOfferConsentAsync(Guid appId, OfferAgreementConsent offerAgreementConsents, Guid companyId)
public Task<IEnumerable<ConsentStatusData>> SubmitOfferConsentAsync(Guid appId, OfferAgreementConsent offerAgreementConsents, (Guid UserId, Guid CompanyId) identity)
{
if (appId == Guid.Empty)
{
throw new ControllerArgumentException($"AppId must not be empty");
}
return SubmitOfferConsentInternalAsync(appId, offerAgreementConsents, companyId);
return _offerService.CreateOrUpdateProviderOfferAgreementConsent(appId, offerAgreementConsents, identity, OfferTypeId.APP);
}

private Task<IEnumerable<ConsentStatusData>> SubmitOfferConsentInternalAsync(Guid appId, OfferAgreementConsent offerAgreementConsents, Guid companyId) =>
_offerService.CreateOrUpdateProviderOfferAgreementConsent(appId, offerAgreementConsents, companyId, OfferTypeId.APP);

/// <inheritdoc/>
public async Task<AppProviderResponse> GetAppDetailsForStatusAsync(Guid appId, Guid companyId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public interface IAppReleaseBusinessLogic
/// </summary>
/// <param name="appId"></param>
/// <param name="offerAgreementConsents"></param>
/// <param name="companyId"></param>
/// <param name="identity"></param>
/// <returns></returns>
Task<IEnumerable<ConsentStatusData>> SubmitOfferConsentAsync(Guid appId, OfferAgreementConsent offerAgreementConsents, Guid companyId);
Task<IEnumerable<ConsentStatusData>> SubmitOfferConsentAsync(Guid appId, OfferAgreementConsent offerAgreementConsents, (Guid UserId, Guid CompanyId) identity);

/// <summary>
/// Return Offer with Consent Status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ public Task<OfferAgreementConsent> GetOfferAgreementConsentById([FromRoute] Guid
/// <response code="400">App Id is incorrect.</response>
[HttpPost]
[Authorize(Roles = "edit_apps")]
[Authorize(Policy = PolicyTypes.ValidCompany)]
[Authorize(Policy = PolicyTypes.CompanyUser)]
[Route("consent/{appId}/agreementConsents")]
[ProducesResponseType(typeof(IEnumerable<ConsentStatusData>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status403Forbidden)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
public Task<IEnumerable<ConsentStatusData>> SubmitOfferConsentToAgreementsAsync([FromRoute] Guid appId, [FromBody] OfferAgreementConsent offerAgreementConsents) =>
this.WithCompanyId(companyId => _appReleaseBusinessLogic.SubmitOfferConsentAsync(appId, offerAgreementConsents, companyId));
this.WithUserIdAndCompanyId(identity => _appReleaseBusinessLogic.SubmitOfferConsentAsync(appId, offerAgreementConsents, identity));

/// <summary>
/// Return app detail with status
Expand Down
4 changes: 2 additions & 2 deletions src/marketplace/Offers.Library/Service/IOfferService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ Task CreateOrUpdateOfferSubscriptionAgreementConsentAsync(Guid subscriptionId,
/// </summary>
/// <param name="offerId"></param>
/// <param name="offerAgreementConsent"></param>
/// <param name="companyId"></param>
/// <param name="identity"></param>
/// <param name="offerTypeId">OfferTypeId the agreements are associated with</param>
/// <returns></returns>
Task<IEnumerable<ConsentStatusData>> CreateOrUpdateProviderOfferAgreementConsent(Guid offerId, OfferAgreementConsent offerAgreementConsent, Guid companyId, OfferTypeId offerTypeId);
Task<IEnumerable<ConsentStatusData>> CreateOrUpdateProviderOfferAgreementConsent(Guid offerId, OfferAgreementConsent offerAgreementConsent, (Guid UserId, Guid CompanyId) identity, OfferTypeId offerTypeId);

/// <summary>
/// Creates a new service offering
Expand Down
8 changes: 4 additions & 4 deletions src/marketplace/Offers.Library/Service/OfferService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ public async Task<OfferAgreementConsent> GetProviderOfferAgreementConsentById(Gu
return result.OfferAgreementConsent;
}

public async Task<IEnumerable<ConsentStatusData>> CreateOrUpdateProviderOfferAgreementConsent(Guid offerId, OfferAgreementConsent offerAgreementConsent, Guid companyId, OfferTypeId offerTypeId)
public async Task<IEnumerable<ConsentStatusData>> CreateOrUpdateProviderOfferAgreementConsent(Guid offerId, OfferAgreementConsent offerAgreementConsent, (Guid UserId, Guid CompanyId) identity, OfferTypeId offerTypeId)
{
var (companyUserId, dbAgreements, requiredAgreementIds) = await GetProviderOfferAgreementConsent(offerId, companyId, OfferStatusId.CREATED, offerTypeId).ConfigureAwait(false);
var (dbAgreements, requiredAgreementIds) = await GetProviderOfferAgreementConsent(offerId, identity.CompanyId, OfferStatusId.CREATED, offerTypeId).ConfigureAwait(false);
var invalidConsents = offerAgreementConsent.Agreements.ExceptBy(requiredAgreementIds, consent => consent.AgreementId);
if (invalidConsents.Any())
{
Expand All @@ -177,8 +177,8 @@ public async Task<IEnumerable<ConsentStatusData>> CreateOrUpdateProviderOfferAgr
dbAgreements,
offerAgreementConsent.Agreements,
offerId,
companyId,
companyUserId,
identity.CompanyId,
identity.UserId,
DateTimeOffset.UtcNow)
.Select(consent => new ConsentStatusData(consent.AgreementId, consent.ConsentStatusId));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public interface IServiceReleaseBusinessLogic
/// </summary>
/// <param name="serviceId">Id of the service</param>
/// <param name="offerAgreementConsents">Data of the consents for the agreements</param>
/// <param name="companyId">Id of the users company</param>
Task<IEnumerable<ConsentStatusData>> SubmitOfferConsentAsync(Guid serviceId, OfferAgreementConsent offerAgreementConsents, Guid companyId);
/// <param name="identity">Id of the users company</param>
Task<IEnumerable<ConsentStatusData>> SubmitOfferConsentAsync(Guid serviceId, OfferAgreementConsent offerAgreementConsents, (Guid UserId, Guid CompanyId) identity);

/// <summary>
/// Retrieves all in review status offer in the marketplace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,16 @@ public async Task<ServiceProviderResponse> GetServiceDetailsForStatusAsync(Guid
}

/// <inheritdoc/>
public Task<IEnumerable<ConsentStatusData>> SubmitOfferConsentAsync(Guid serviceId, OfferAgreementConsent offerAgreementConsents, Guid companyId)
public Task<IEnumerable<ConsentStatusData>> SubmitOfferConsentAsync(Guid serviceId, OfferAgreementConsent offerAgreementConsents, (Guid UserId, Guid CompanyId) identity)
{
if (serviceId == Guid.Empty)
{
throw new ControllerArgumentException("ServiceId must not be empty");
}

return SubmitOfferConsentInternalAsync(serviceId, offerAgreementConsents, companyId);
return _offerService.CreateOrUpdateProviderOfferAgreementConsent(serviceId, offerAgreementConsents, identity, OfferTypeId.SERVICE);
}

private Task<IEnumerable<ConsentStatusData>> SubmitOfferConsentInternalAsync(Guid serviceId, OfferAgreementConsent offerAgreementConsents, Guid companyId) =>
_offerService.CreateOrUpdateProviderOfferAgreementConsent(serviceId, offerAgreementConsents, companyId, OfferTypeId.SERVICE);

/// <inheritdoc/>
public Task<Pagination.Response<InReviewServiceData>> GetAllInReviewStatusServiceAsync(int page, int size, OfferSorting? sorting, string? serviceName, string? languageShortName, ServiceReleaseStatusIdFilter? statusId) =>
Pagination.CreateResponseAsync(page, size, 15,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ public Task<ServiceProviderResponse> GetServiceDetailsForStatusAsync([FromRoute]
[HttpPost]
[Route("consent/{serviceId}/agreementConsents")]
[Authorize(Roles = "add_service_offering")]
[Authorize(Policy = PolicyTypes.ValidCompany)]
[Authorize(Policy = PolicyTypes.CompanyUser)]
[ProducesResponseType(typeof(IEnumerable<ConsentStatusData>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status403Forbidden)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
public async Task<IEnumerable<ConsentStatusData>> SubmitOfferConsentToAgreementsAsync([FromRoute] Guid serviceId, [FromBody] OfferAgreementConsent offerAgreementConsents) =>
await this.WithCompanyId(companyId => _serviceReleaseBusinessLogic.SubmitOfferConsentAsync(serviceId, offerAgreementConsents, companyId));
await this.WithUserIdAndCompanyId(identity => _serviceReleaseBusinessLogic.SubmitOfferConsentAsync(serviceId, offerAgreementConsents, identity));

/// <summary>
/// Retrieves all in review status service in the marketplace .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ public record OfferAgreementConsent(IEnumerable<AgreementConsentStatus> Agreemen

public record AppAgreementConsentStatus(Guid AgreementId, Guid ConsentId, ConsentStatusId ConsentStatusId);

public record OfferAgreementConsentUpdate(Guid CompanyUserId, IEnumerable<AppAgreementConsentStatus> ExistingAgreements, IEnumerable<Guid> RequiredAgreementIds);
public record OfferAgreementConsentUpdate(IEnumerable<AppAgreementConsentStatus> ExistingAgreements, IEnumerable<Guid> RequiredAgreementIds);
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public IAsyncEnumerable<AgreementDocumentData> GetAgreementDataForOfferType(Offe
offer.OfferTypeId == offerTypeId)
.Select(offer => new ValueTuple<OfferAgreementConsentUpdate, bool>(
new OfferAgreementConsentUpdate(
offer.ProviderCompany!.Identities.Select(companyUser => companyUser.Id).SingleOrDefault(),
offer.ConsentAssignedOffers.Select(consentAssignedOffer => new AppAgreementConsentStatus(
consentAssignedOffer.Consent!.AgreementId,
consentAssignedOffer.Consent.Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ public async Task SubmitAppReleaseRequestAsync_CallsOfferService()
public async Task SubmitOfferConsentAsync_WithEmptyAppId_ThrowsControllerArgumentException()
{
// Act
async Task Act() => await _sut.SubmitOfferConsentAsync(Guid.Empty, _fixture.Create<OfferAgreementConsent>(), _identity.CompanyId).ConfigureAwait(false);
var identitytestdata = (_identity.UserId, _identity.CompanyId);
async Task Act() => await _sut.SubmitOfferConsentAsync(Guid.Empty, _fixture.Create<OfferAgreementConsent>(), identitytestdata).ConfigureAwait(false);

// Assert
var ex = await Assert.ThrowsAsync<ControllerArgumentException>(Act).ConfigureAwait(false);
Expand All @@ -539,13 +540,14 @@ public async Task SubmitOfferConsentAsync_WithEmptyAppId_ThrowsControllerArgumen
public async Task SubmitOfferConsentAsync_WithAppId_CallsOfferService()
{
// Arrange
var identitytestdata = (_identity.UserId, _identity.CompanyId);
var data = _fixture.Create<OfferAgreementConsent>();

// Act
await _sut.SubmitOfferConsentAsync(_existingAppId, data, _identity.CompanyId).ConfigureAwait(false);
await _sut.SubmitOfferConsentAsync(_existingAppId, data, identitytestdata).ConfigureAwait(false);

// Assert
A.CallTo(() => _offerService.CreateOrUpdateProviderOfferAgreementConsent(_existingAppId, data, _identity.CompanyId, OfferTypeId.APP)).MustHaveHappenedOnceExactly();
A.CallTo(() => _offerService.CreateOrUpdateProviderOfferAgreementConsent(_existingAppId, data, identitytestdata, OfferTypeId.APP)).MustHaveHappenedOnceExactly();
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using AutoFixture;
using FakeItEasy;
using FluentAssertions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Org.Eclipse.TractusX.Portal.Backend.Apps.Service.BusinessLogic;
using Org.Eclipse.TractusX.Portal.Backend.Apps.Service.ViewModels;
Expand Down Expand Up @@ -64,8 +63,6 @@ public async Task UpdateApp_ReturnsNoContent()
"https://test.provider.com",
null,
null);
A.CallTo(() => _logic.UpdateAppAsync(A<Guid>._, A<AppEditableDetail>._, A<Guid>._))
.ReturnsLazily(() => Task.CompletedTask);

// Act
var result = await this._controller.UpdateApp(appId, data).ConfigureAwait(false);
Expand All @@ -83,9 +80,6 @@ public async Task UpdateAppDocument_ReturnsExpectedResult()
var documentTypeId = DocumentTypeId.ADDITIONAL_DETAILS;
var file = FormFileHelper.GetFormFile("this is just a test", "superFile.pdf", "application/pdf");

A.CallTo(() => _logic.CreateAppDocumentAsync(A<Guid>._, A<DocumentTypeId>._, A<FormFile>._, A<ValueTuple<Guid, Guid>>.That.Matches(x => x.Item1 == _identity.UserId && x.Item2 == _identity.CompanyId), A<CancellationToken>._))
.ReturnsLazily(() => Task.CompletedTask);

//Act
await this._controller.UpdateAppDocumentAsync(appId, documentTypeId, file, CancellationToken.None).ConfigureAwait(false);

Expand Down Expand Up @@ -155,15 +149,16 @@ public async Task SubmitOfferConsentToAgreementsAsync_ReturnsExpectedResult()
var appId = Guid.NewGuid();
var data = _fixture.Create<OfferAgreementConsent>();
var consentStatusData = new ConsentStatusData(Guid.NewGuid(), ConsentStatusId.ACTIVE);
A.CallTo(() => _logic.SubmitOfferConsentAsync(A<Guid>._, A<OfferAgreementConsent>._, A<Guid>._))
.ReturnsLazily(() => Enumerable.Repeat(consentStatusData, 1));
var identitydatas = (_identity.UserId, _identity.CompanyId);
A.CallTo(() => _logic.SubmitOfferConsentAsync(A<Guid>._, A<OfferAgreementConsent>._, A<(Guid, Guid)>._))
.Returns(Enumerable.Repeat(consentStatusData, 1));

//Act
var result = await this._controller.SubmitOfferConsentToAgreementsAsync(appId, data).ConfigureAwait(false);

// Assert
result.Should().HaveCount(1);
A.CallTo(() => _logic.SubmitOfferConsentAsync(appId, data, _identity.CompanyId))
A.CallTo(() => _logic.SubmitOfferConsentAsync(appId, data, identitydatas))
.MustHaveHappenedOnceExactly();
}

Expand All @@ -174,7 +169,7 @@ public async Task GetAppDetailsForStatusAsync_ReturnsExpectedResult()
var appId = Guid.NewGuid();
var data = _fixture.Create<AppProviderResponse>();
A.CallTo(() => _logic.GetAppDetailsForStatusAsync(A<Guid>._, A<Guid>._))
.ReturnsLazily(() => data);
.Returns(data);

//Act
var result = await this._controller.GetAppDetailsForStatusAsync(appId).ConfigureAwait(false);
Expand All @@ -191,8 +186,6 @@ public async Task DeleteAppRoleAsync_ReturnsExpectedResult()
//Arrange
var appId = Guid.NewGuid();
var roleId = Guid.NewGuid();
A.CallTo(() => _logic.DeleteAppRoleAsync(A<Guid>._, A<Guid>._, A<Guid>._))
.ReturnsLazily(() => Task.CompletedTask);

//Act
var result = await this._controller.DeleteAppRoleAsync(appId, roleId).ConfigureAwait(false);
Expand All @@ -209,7 +202,7 @@ public async Task GetAppProviderSalesManagerAsync_ReturnsExpectedResult()
//Arrange
var data = _fixture.CreateMany<CompanyUserNameData>(5).ToAsyncEnumerable();
A.CallTo(() => _logic.GetAppProviderSalesManagersAsync(A<Guid>._))
.ReturnsLazily(() => data);
.Returns(data);

//Act
var result = await this._controller.GetAppProviderSalesManagerAsync().ToListAsync().ConfigureAwait(false);
Expand All @@ -227,7 +220,7 @@ public async Task ExecuteAppCreation_ReturnsExpectedId()
var appId = _fixture.Create<Guid>();
var data = _fixture.Create<AppRequestModel>();
A.CallTo(() => _logic.AddAppAsync(A<AppRequestModel>._, _identity.CompanyId))
.ReturnsLazily(() => appId);
.Returns(appId);

//Act
var result = await this._controller.ExecuteAppCreation(data).ConfigureAwait(false);
Expand Down Expand Up @@ -268,8 +261,6 @@ public async Task UpdateAppRelease_ReturnsNoContent()
"[email protected]",
"9456321678"
);
A.CallTo(() => _logic.UpdateAppReleaseAsync(A<Guid>._, A<AppRequestModel>._, _identity.CompanyId))
.ReturnsLazily(() => Task.CompletedTask);

// Act
var result = await this._controller.UpdateAppRelease(appId, data).ConfigureAwait(false);
Expand All @@ -285,7 +276,7 @@ public async Task GetAllInReviewStatusAppsAsync_ReturnsExpectedCount()
//Arrange
var paginationResponse = new Pagination.Response<InReviewAppData>(new Pagination.Metadata(15, 1, 1, 15), _fixture.CreateMany<InReviewAppData>(5));
A.CallTo(() => _logic.GetAllInReviewStatusAppsAsync(A<int>._, A<int>._, A<OfferSorting?>._, null))
.ReturnsLazily(() => paginationResponse);
.Returns(paginationResponse);

//Act
var result = await this._controller.GetAllInReviewStatusAppsAsync().ConfigureAwait(false);
Expand All @@ -300,8 +291,6 @@ public async Task SubmitAppReleaseRequest_ReturnsExpectedCount()
{
//Arrange
var appId = _fixture.Create<Guid>();
A.CallTo(() => _logic.SubmitAppReleaseRequestAsync(appId, A<Guid>._))
.ReturnsLazily(() => Task.CompletedTask);

//Act
var result = await this._controller.SubmitAppReleaseRequest(appId).ConfigureAwait(false);
Expand All @@ -316,8 +305,6 @@ public async Task ApproveAppRequest_ReturnsExpectedCount()
{
//Arrange
var appId = _fixture.Create<Guid>();
A.CallTo(() => _logic.ApproveAppRequestAsync(appId, A<Guid>._))
.ReturnsLazily(() => Task.CompletedTask);

//Act
var result = await this._controller.ApproveAppRequest(appId).ConfigureAwait(false);
Expand All @@ -333,8 +320,6 @@ public async Task DeclineAppRequest_ReturnsNoContent()
//Arrange
var appId = _fixture.Create<Guid>();
var data = new OfferDeclineRequest("Just a test");
A.CallTo(() => _logic.DeclineAppRequestAsync(A<Guid>._, A<Guid>._, A<OfferDeclineRequest>._))
.ReturnsLazily(() => Task.CompletedTask);

//Act
var result = await this._controller.DeclineAppRequest(appId, data).ConfigureAwait(false);
Expand Down Expand Up @@ -368,8 +353,6 @@ public async Task DeleteAppDocumentsAsync_ReturnsExpectedResult()
{
//Arrange
var documentId = Guid.NewGuid();
A.CallTo(() => _logic.DeleteAppDocumentsAsync(A<Guid>._, A<Guid>._))
.ReturnsLazily(() => Task.CompletedTask);

//Act
var result = await this._controller.DeleteAppDocumentsAsync(documentId).ConfigureAwait(false);
Expand All @@ -385,8 +368,6 @@ public async Task DeleteAppAsync_ReturnsExpectedResult()
{
//Arrange
var appId = _fixture.Create<Guid>();
A.CallTo(() => _logic.DeleteAppAsync(A<Guid>._, A<Guid>._))
.ReturnsLazily(() => Task.CompletedTask);

//Act
var result = await this._controller.DeleteAppAsync(appId).ConfigureAwait(false);
Expand Down
Loading
Loading