Skip to content

Commit

Permalink
feat(apps & services): enhance offer endpoints with DateLastChanged u…
Browse files Browse the repository at this point in the history
…pdate (#152)

add DateLastChanged update to offer endpoints

------

Refs: CPLP-2886
Reviewed-By: Phil Schneider <[email protected]>
  • Loading branch information
qxz2mqe authored Jul 24, 2023
1 parent 17d259f commit 2da1244
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ private async Task<IEnumerable<AppRoleData>> InsertActiveAppUserRoleAsync(Guid a
await _provisioningManager.AddRolesToClientAsync(clientId, userRoles.Select(x => x.Role)).ConfigureAwait(false);
}

_portalRepositories.GetInstance<IOfferRepository>().AttachAndModifyOffer(appId, offer =>
offer.DateLastChanged = DateTimeOffset.UtcNow);

var notificationContent = new
{
AppName = result.AppName,
Expand Down Expand Up @@ -125,6 +128,8 @@ public async Task CreateOrUpdateAppDescriptionByIdAsync(Guid appId, Guid company
await ValidateAndGetAppDescription(appId, companyId, offerRepository),
offerDescriptionDatas.Select(od => new ValueTuple<string, string, string>(od.LanguageCode, od.LongDescription, od.ShortDescription)));

offerRepository.AttachAndModifyOffer(appId, offer =>
offer.DateLastChanged = DateTimeOffset.UtcNow);
await _portalRepositories.SaveAsync().ConfigureAwait(false);
}

Expand Down Expand Up @@ -189,6 +194,8 @@ public async Task UploadOfferAssignedAppLeadImageDocumentByIdAsync(Guid appId, (
offerRepository.RemoveOfferAssignedDocuments(result.documentStatusDatas.Select(data => (appId, data.DocumentId)));
documentRepository.RemoveDocuments(result.documentStatusDatas.Select(data => data.DocumentId));

offerRepository.AttachAndModifyOffer(appId, offer =>
offer.DateLastChanged = DateTimeOffset.UtcNow);
await _portalRepositories.SaveAsync().ConfigureAwait(false);
}

Expand Down Expand Up @@ -246,6 +253,9 @@ private async Task UpdateTenantUrlAsyncInternal(Guid offerId, Guid subscriptionI
os.AppSubscriptionUrl = url;
});

_portalRepositories.GetInstance<IOfferRepository>().AttachAndModifyOffer(offerId, offer =>
offer.DateLastChanged = DateTimeOffset.UtcNow);

if (!string.IsNullOrEmpty(detailData.ClientClientId))
{
await _provisioningManager.UpdateClient(detailData.ClientClientId, url, url.AppendToPathEncoded("*")).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ private async Task<IEnumerable<AppRoleData>> InsertAppUserRoleAsync(Guid appId,
throw new ForbiddenException($"Company {companyId} is not the provider company of app {appId}");
}
var roleData = AppExtensions.CreateUserRolesWithDescriptions(_portalRepositories.GetInstance<IUserRolesRepository>(), appId, userRoles);

_portalRepositories.GetInstance<IOfferRepository>().AttachAndModifyOffer(appId, offer =>
offer.DateLastChanged = DateTimeOffset.UtcNow);
await _portalRepositories.SaveAsync().ConfigureAwait(false);
return roleData;
}
Expand Down Expand Up @@ -259,6 +262,7 @@ private async Task<Guid> CreateAppAsync(AppRequestModel appRequestModel, Guid co
app.ContactNumber = appRequestModel.ContactNumber;
app.MarketingUrl = appRequestModel.ProviderUri;
app.LicenseTypeId = LicenseTypeId.COTS;
app.DateLastChanged = DateTimeOffset.UtcNow;
}).Id;
appRepository.AddOfferDescriptions(appRequestModel.Descriptions.Select(d =>
(appId, d.LanguageCode, d.LongDescription, d.ShortDescription)));
Expand Down Expand Up @@ -339,6 +343,7 @@ public async Task UpdateAppReleaseAsync(Guid appId, AppRequestModel appRequestMo
app.ContactEmail = appData.ContactEmail;
app.ContactNumber = appData.ContactNumber;
app.MarketingUrl = appData.MarketingUrl;
app.DateLastChanged = DateTimeOffset.UtcNow;
});

_offerService.UpsertRemoveOfferDescription(appId, appRequestModel.Descriptions, appData.OfferDescriptions);
Expand Down
4 changes: 4 additions & 0 deletions src/marketplace/Offers.Library.Web/OfferDocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public async Task UploadDocumentAsync(Guid id, DocumentTypeId documentTypeId, IF
x.CompanyUserId = identity.UserId;
});
_portalRepositories.GetInstance<IOfferRepository>().CreateOfferAssignedDocument(id, doc.Id);

offerRepository.AttachAndModifyOffer(id, offer =>
offer.DateLastChanged = DateTimeOffset.UtcNow);

await _portalRepositories.SaveAsync().ConfigureAwait(false);
}
}
13 changes: 12 additions & 1 deletion src/marketplace/Offers.Library/Service/OfferService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ public async Task<IEnumerable<ConsentStatusData>> CreateOrUpdateProviderOfferAgr
companyUserId,
DateTimeOffset.UtcNow)
.Select(consent => new ConsentStatusData(consent.AgreementId, consent.ConsentStatusId));

_portalRepositories.GetInstance<IOfferRepository>().AttachAndModifyOffer(offerId, offer =>
offer.DateLastChanged = DateTimeOffset.UtcNow);

await _portalRepositories.SaveAsync().ConfigureAwait(false);
return ConsentStatusdata;
}
Expand Down Expand Up @@ -233,6 +237,7 @@ public async Task<Guid> CreateServiceOfferingAsync(ServiceOfferingData data, (Gu
service.ProviderCompanyId = identity.CompanyId;
service.MarketingUrl = data.ProviderUri;
service.LicenseTypeId = LicenseTypeId.COTS;
service.DateLastChanged = DateTimeOffset.UtcNow;
});
var licenseId = offerRepository.CreateOfferLicenses(data.Price).Id;
offerRepository.CreateOfferAssignedLicense(service.Id, licenseId);
Expand Down Expand Up @@ -629,7 +634,10 @@ public async Task DeactivateOfferIdAsync(Guid offerId, Guid companyId, OfferType
throw new ConflictException($"offerStatus is in Incorrect State");
}
offerRepository.AttachAndModifyOffer(offerId, offer =>
offer.OfferStatusId = OfferStatusId.INACTIVE);
{
offer.OfferStatusId = OfferStatusId.INACTIVE;
offer.DateReleased = DateTime.UtcNow;
});
await _portalRepositories.SaveAsync().ConfigureAwait(false);
}

Expand Down Expand Up @@ -784,6 +792,9 @@ public async Task UpdateTechnicalUserProfiles(Guid offerId, OfferTypeId offerTyp
x => x.TechnicalUserProfileId)
.Select(x => x.TechnicalUserProfileId));

_portalRepositories.GetInstance<IOfferRepository>().AttachAndModifyOffer(offerId, offer =>
offer.DateLastChanged = DateTimeOffset.UtcNow);

await _portalRepositories.SaveAsync().ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ public async Task UpdateServiceAsync(Guid serviceId, ServiceUpdateRequestData da
offer =>
{
offer.SalesManagerId = serviceData.SalesManagerId;
offer.DateLastChanged = DateTimeOffset.UtcNow;
});

_offerService.UpsertRemoveOfferDescription(serviceId, data.Descriptions, serviceData.Descriptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public async Task AddFavouriteAppForUser_ExecutesSuccessfully()
{
// Arrange
var appId = _fixture.Create<Guid>();

var sut = new AppsBusinessLogic(_portalRepositories, null!, null!, null!, Options.Create(new AppsSettings()), null!);

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,14 @@ public async Task AddActiveAppUserRoleAsync_ExecutesSuccessfully()
userRoleDescriptions.Add(createdUserRoleDescriptions);
return createdUserRoleDescriptions;
});

var existingOffer = _fixture.Create<Offer>();
existingOffer.DateLastChanged = DateTimeOffset.UtcNow;
A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A<Action<Offer>>._, A<Action<Offer>?>._))
.Invokes((Guid _, Action<Offer> setOptionalParameters, Action<Offer>? initializeParemeters) =>
{
initializeParemeters?.Invoke(existingOffer);
setOptionalParameters(existingOffer);
});
A.CallTo(() => _notificationService.CreateNotifications(A<IEnumerable<UserRoleConfig>>._, A<Guid>._, A<IEnumerable<(string? content, NotificationTypeId notificationTypeId)>>._, A<Guid>._, A<bool?>._))
.Returns(_fixture.CreateMany<Guid>(4).AsFakeIAsyncEnumerable(out var createNotificationsResultAsyncEnumerator));

Expand Down Expand Up @@ -169,7 +176,7 @@ public async Task AddActiveAppUserRoleAsync_ExecutesSuccessfully()
x => x.Should().HaveCount(2).And.Satisfy(
x => x.UserRoleId == userRoles!.ElementAt(2).Id && x.LanguageShortName == appAssignedRoleDesc[2].Descriptions.ElementAt(0).LanguageCode && x.Description == appAssignedRoleDesc[2].Descriptions.ElementAt(0).Description,
x => x.UserRoleId == userRoles!.ElementAt(2).Id && x.LanguageShortName == appAssignedRoleDesc[2].Descriptions.ElementAt(1).LanguageCode && x.Description == appAssignedRoleDesc[2].Descriptions.ElementAt(1).Description));

A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A<Action<Offer>>._, A<Action<Offer>?>._)).MustHaveHappenedOnceExactly();
A.CallTo(() => _notificationService.CreateNotifications(A<IEnumerable<UserRoleConfig>>._, A<Guid>._, A<IEnumerable<(string? content, NotificationTypeId notificationTypeId)>>._, A<Guid>._, A<bool?>._))
.MustHaveHappenedOnceExactly();
A.CallTo(() => createNotificationsResultAsyncEnumerator.MoveNextAsync())
Expand Down Expand Up @@ -201,7 +208,7 @@ public async Task AddActiveAppUserRoleAsync_WithCompanyUserIdNotSet_ThrowsForbid
var clientIds = new[] { "client" };
A.CallTo(() => _offerRepository.GetInsertActiveAppUserRoleDataAsync(appId, OfferTypeId.APP))
.Returns((true, appName, Guid.NewGuid(), clientIds));

var existingOffer = _fixture.Create<Offer>();
//Act
async Task Act() => await _sut.AddActiveAppUserRoleAsync(appId, appAssignedRoleDesc, (_identity.UserId, _identity.CompanyId)).ConfigureAwait(false);

Expand Down Expand Up @@ -347,13 +354,21 @@ public async Task CreateOrUpdateAppDescriptionByIdAsync_withEmptyExistingDescrip

A.CallTo(() => _offerRepository.GetActiveOfferDescriptionDataByIdAsync(appId, OfferTypeId.APP, _identity.CompanyId))
.Returns(appDescriptionData);

var existingOffer = _fixture.Create<Offer>();
existingOffer.DateLastChanged = DateTimeOffset.UtcNow;
A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A<Action<Offer>>._, A<Action<Offer>?>._))
.Invokes((Guid _, Action<Offer> setOptionalParameters, Action<Offer>? initializeParemeters) =>
{
initializeParemeters?.Invoke(existingOffer);
setOptionalParameters(existingOffer);
});
// Act
await _sut.CreateOrUpdateAppDescriptionByIdAsync(appId, _identity.CompanyId, updateDescriptionData).ConfigureAwait(false);

// Assert
A.CallTo(() => _offerRepository.CreateUpdateDeleteOfferDescriptions(appId, A<IEnumerable<LocalizedDescription>>._, A<IEnumerable<(string, string, string)>>.That.IsSameSequenceAs(updateDescriptionData.Select(x => new ValueTuple<string, string, string>(x.LanguageCode, x.LongDescription, x.ShortDescription)))))
.MustHaveHappenedOnceExactly();
A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A<Action<Offer>>._, A<Action<Offer>?>._)).MustHaveHappenedOnceExactly();
}

[Fact]
Expand Down Expand Up @@ -480,7 +495,14 @@ public async Task UploadOfferAssignedAppLeadImageDocumentById_ExpectedCalls()
var offerAssignedDocument = new OfferAssignedDocument(offerId, docId);
offerAssignedDocuments.Add(offerAssignedDocument);
});

var existingOffer = _fixture.Create<Offer>();
existingOffer.DateLastChanged = DateTimeOffset.UtcNow;
A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A<Action<Offer>>._, A<Action<Offer>?>._))
.Invokes((Guid _, Action<Offer> setOptionalParameters, Action<Offer>? initializeParemeters) =>
{
initializeParemeters?.Invoke(existingOffer);
setOptionalParameters(existingOffer);
});
// Act
await _sut.UploadOfferAssignedAppLeadImageDocumentByIdAsync(appId, (_identity.UserId, _identity.CompanyId), file, CancellationToken.None);

Expand All @@ -490,6 +512,7 @@ public async Task UploadOfferAssignedAppLeadImageDocumentById_ExpectedCalls()
A.CallTo(() => _offerRepository.CreateOfferAssignedDocument(A<Guid>._, A<Guid>._)).MustHaveHappenedOnceExactly();
A.CallTo(() => _offerRepository.RemoveOfferAssignedDocuments(A<IEnumerable<(Guid OfferId, Guid DocumentId)>>.That.IsSameSequenceAs(documentStatusData.Select(data => new ValueTuple<Guid, Guid>(appId, data.DocumentId))))).MustHaveHappenedOnceExactly();
A.CallTo(() => _documentRepository.RemoveDocuments(A<IEnumerable<Guid>>.That.IsSameSequenceAs(documentStatusData.Select(data => data.DocumentId)))).MustHaveHappenedOnceExactly();
A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A<Action<Offer>>._, A<Action<Offer>?>._)).MustHaveHappenedOnceExactly();
A.CallTo(() => _portalRepositories.SaveAsync()).MustHaveHappenedOnceExactly();
documents.Should().ContainSingle().Which.Should().Match<Document>(x => x.Id == documentId && x.MediaTypeId == MediaTypeId.JPEG && x.DocumentTypeId == DocumentTypeId.APP_LEADIMAGE && x.DocumentStatusId == DocumentStatusId.LOCKED);
offerAssignedDocuments.Should().ContainSingle().Which.Should().Match<OfferAssignedDocument>(x => x.DocumentId == documentId && x.OfferId == appId);
Expand Down Expand Up @@ -622,13 +645,21 @@ public async Task UpdateTenantUrlAsync_WithValidData_CallsExpected()
initialize?.Invoke(details);
setParameters.Invoke(details);
});

var existingOffer = _fixture.Create<Offer>();
existingOffer.DateLastChanged = DateTimeOffset.UtcNow;
A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A<Action<Offer>>._, A<Action<Offer>?>._))
.Invokes((Guid _, Action<Offer> setOptionalParameters, Action<Offer>? initializeParemeters) =>
{
initializeParemeters?.Invoke(existingOffer);
setOptionalParameters(existingOffer);
});
// Act
await _sut.UpdateTenantUrlAsync(appId, subscriptionId, data, _identity.CompanyId).ConfigureAwait(false);

// Assert
A.CallTo(() => _provisioningManager.UpdateClient(clientClientId, data.Url, A<string>._)).MustHaveHappenedOnceExactly();
A.CallTo(() => _notificationService.CreateNotifications(A<IEnumerable<UserRoleConfig>>._, A<Guid?>._, A<IEnumerable<(string? content, NotificationTypeId notificationTypeId)>>._, A<Guid>._, A<bool?>._)).MustNotHaveHappened();
A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A<Action<Offer>>._, A<Action<Offer>?>._)).MustHaveHappenedOnceExactly();
notifications.Should().ContainSingle().Which
.NotificationTypeId.Should().Be(NotificationTypeId.SUBSCRIPTION_URL_UPDATE);
details.AppSubscriptionUrl.Should().Be(data.Url);
Expand Down Expand Up @@ -668,14 +699,22 @@ public async Task UpdateTenantUrlAsync_WithoutRequesterButValidData_CallsExpecte
initialize?.Invoke(details);
setParameters.Invoke(details);
});

var existingOffer = _fixture.Create<Offer>();
existingOffer.DateLastChanged = DateTimeOffset.UtcNow;
A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A<Action<Offer>>._, A<Action<Offer>?>._))
.Invokes((Guid _, Action<Offer> setOptionalParameters, Action<Offer>? initializeParemeters) =>
{
initializeParemeters?.Invoke(existingOffer);
setOptionalParameters(existingOffer);
});
// Act
await _sut.UpdateTenantUrlAsync(appId, subscriptionId, data, _identity.CompanyId).ConfigureAwait(false);

// Assert
A.CallTo(() => _provisioningManager.UpdateClient(clientClientId, data.Url, A<string>._)).MustHaveHappenedOnceExactly();
A.CallTo(() => createNotificationsResultAsyncEnumerator.MoveNextAsync())
.MustHaveHappened(5, Times.Exactly);
A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A<Action<Offer>>._, A<Action<Offer>?>._)).MustHaveHappenedOnceExactly();
notifications.Should().BeEmpty();
details.AppSubscriptionUrl.Should().Be(data.Url);
}
Expand Down Expand Up @@ -711,13 +750,21 @@ public async Task UpdateTenantUrlAsync_WithoutClientId_CallsExpected()
initialize?.Invoke(details);
setParameters.Invoke(details);
});

var existingOffer = _fixture.Create<Offer>();
existingOffer.DateLastChanged = DateTimeOffset.UtcNow;
A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A<Action<Offer>>._, A<Action<Offer>?>._))
.Invokes((Guid _, Action<Offer> setOptionalParameters, Action<Offer>? initializeParemeters) =>
{
initializeParemeters?.Invoke(existingOffer);
setOptionalParameters(existingOffer);
});
// Act
await _sut.UpdateTenantUrlAsync(appId, subscriptionId, data, _identity.CompanyId).ConfigureAwait(false);

// Assert
A.CallTo(() => _provisioningManager.UpdateClient(clientClientId, data.Url, A<string>._)).MustNotHaveHappened();
A.CallTo(() => _notificationService.CreateNotifications(A<IEnumerable<UserRoleConfig>>._, A<Guid?>._, A<IEnumerable<(string? content, NotificationTypeId notificationTypeId)>>._, A<Guid>._, A<bool?>._)).MustHaveHappenedOnceExactly();
A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A<Action<Offer>>._, A<Action<Offer>?>._)).MustHaveHappenedOnceExactly();
notifications.Should().BeEmpty();
details.AppSubscriptionUrl.Should().Be(data.Url);
}
Expand All @@ -735,7 +782,6 @@ public async Task UpdateTenantUrlAsync_WithSameUrl_CallsNothing()
var detailId = _fixture.Create<Guid>();
A.CallTo(() => _offerSubscriptionsRepository.GetUpdateUrlDataAsync(appId, subscriptionId, _identity.CompanyId))
.Returns(new OfferUpdateUrlData("testApp", false, true, Guid.Empty, subscribingCompany, OfferSubscriptionStatusId.ACTIVE, new OfferUpdateUrlSubscriptionDetailData(detailId, clientClientId, oldUrl)));

// Act
await _sut.UpdateTenantUrlAsync(appId, subscriptionId, data, _identity.CompanyId).ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,14 @@ public async Task CreateServiceOffering_WithValidDataAndEmptyDescriptions_Return
userRoleDescriptions.Add(createdUserRoleDescriptions);
return createdUserRoleDescriptions;
});

var existingOffer = _fixture.Create<Offer>();
existingOffer.DateLastChanged = DateTimeOffset.UtcNow;
A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A<Action<Offer>>._, A<Action<Offer>?>._))
.Invokes((Guid _, Action<Offer> setOptionalParameters, Action<Offer>? initializeParemeters) =>
{
initializeParemeters?.Invoke(existingOffer);
setOptionalParameters(existingOffer);
});
// Act
var result = await _sut.AddAppUserRoleAsync(appId, appUserRoles, _identity.CompanyId).ConfigureAwait(false);

Expand All @@ -176,7 +183,7 @@ public async Task CreateServiceOffering_WithValidDataAndEmptyDescriptions_Return
x => x.UserRoleText == appUserRoles[1].Role,
x => x.UserRoleText == appUserRoles[2].Role
);

A.CallTo(() => _offerRepository.AttachAndModifyOffer(appId, A<Action<Offer>>._, A<Action<Offer>?>._)).MustHaveHappenedOnceExactly();
A.CallTo(() => _userRolesRepository.CreateAppUserRoleDescriptions(A<IEnumerable<(Guid, string, string)>>._)).MustHaveHappened(appUserRoles.Length, Times.Exactly);
userRoleDescriptions.Should()
.HaveSameCount(appUserRoles)
Expand Down
Loading

0 comments on commit 2da1244

Please sign in to comment.