diff --git a/src/marketplace/Services.Service/ViewModels/ProviderSubscriptionDetailData.cs b/src/marketplace/Services.Service/ViewModels/ProviderSubscriptionDetailData.cs index ff85494847..95b97dd579 100644 --- a/src/marketplace/Services.Service/ViewModels/ProviderSubscriptionDetailData.cs +++ b/src/marketplace/Services.Service/ViewModels/ProviderSubscriptionDetailData.cs @@ -47,4 +47,4 @@ public record ProviderSubscriptionDetailData( IEnumerable ConnectorData, ProcessStepTypeId? ProcessStepTypeId, SubscriptionExternalServiceData ExternalService -); \ No newline at end of file +); diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/OfferSubscriptionsRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/OfferSubscriptionsRepository.cs index 35e6cd6346..04edf67fec 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Repositories/OfferSubscriptionsRepository.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/OfferSubscriptionsRepository.cs @@ -166,9 +166,10 @@ public OfferSubscription AttachAndModifyOfferSubscription(Guid offerSubscription /// public IAsyncEnumerable<(Guid OfferId, Guid SubscriptionId, string? OfferName, string SubscriptionUrl, Guid LeadPictureId, string Provider)> GetAllBusinessAppDataForUserIdAsync(Guid userId) => dbContext.CompanyUsers.AsNoTracking() - .Where(user => user.Id == userId) + .Where(user => user.Id == userId && user.Identity!.IdentityTypeId == IdentityTypeId.COMPANY_USER) .SelectMany(user => user.Identity!.Company!.OfferSubscriptions.Where(subscription => - subscription.Offer!.UserRoles.Any(ur => ur.IdentityAssignedRoles.Any(cu => cu.IdentityId == user.Id && cu.Identity!.IdentityTypeId == IdentityTypeId.COMPANY_USER)) && + subscription.Offer!.OfferTypeId == OfferTypeId.APP && + subscription.Offer.UserRoles.Any(ur => ur.IdentityAssignedRoles.Any(iar => iar.IdentityId == userId)) && subscription.AppSubscriptionDetail!.AppInstance != null && subscription.AppSubscriptionDetail.AppSubscriptionUrl != null)) .Select(offerSubscription => new ValueTuple( diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/OfferSubscriptionRepositoryTest.cs b/tests/portalbackend/PortalBackend.DBAccess.Tests/OfferSubscriptionRepositoryTest.cs index 9787dc396d..3d3c580a5a 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/OfferSubscriptionRepositoryTest.cs +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/OfferSubscriptionRepositoryTest.cs @@ -122,13 +122,13 @@ public async Task GetAllBusinessAppDataForUserIdAsync_WithValidUser_ReturnsExpec var (sut, _) = await CreateSut(); // Act - var result = await sut.GetAllBusinessAppDataForUserIdAsync(new("ac1cf001-7fbc-1f2f-817f-bce058020006")).ToListAsync(); + var result = await sut.GetAllBusinessAppDataForUserIdAsync(new("8b42e6de-7b59-4217-a63c-198e83d93776")).ToListAsync(); // Assert - result.Should().NotBeNullOrEmpty(); - result.Should().HaveCount(1); - result.First().SubscriptionUrl.Should().Be("https://ec-qas.d13fe27.kyma.ondemand.com"); - result.First().OfferId.Should().Be(new Guid("a16e73b9-5277-4b69-9f8d-3b227495dfea")); + result.Should().ContainSingle().Which.Should().Match<(Guid OfferId, Guid SubscriptionId, string? OfferName, string SubscriptionUrl, Guid LeadPictureId, string Provider)>(x => + x.SubscriptionUrl == "https://ec-qas.d13fe27.kyma.ondemand.com" && + x.OfferId == new Guid("ac1cf001-7fbc-1f2f-817f-bce05744000b") + ); } #endregion @@ -246,7 +246,30 @@ public async Task GetOfferDetailsAndCheckUser_WithSubscriptionForOfferWithoutApp #region GetOfferSubscriptionDetailForProviderAsync [Fact] - public async Task GetOfferSubscriptionDetailForProviderAsync_ReturnsExpected() + public async Task GetOfferSubscriptionDetailForAppProviderAsync_ReturnsExpected() + { + // Arrange + var (sut, _) = await CreateSut(); + + // Act + var result = await sut.GetOfferSubscriptionDetailsForProviderAsync(new Guid("ac1cf001-7fbc-1f2f-817f-bce05744000b"), new Guid("0b2ca541-206d-48ad-bc02-fb61fbcb5552"), new Guid("0dcd8209-85e2-4073-b130-ac094fb47106"), OfferTypeId.APP, new[] { new Guid("7410693c-c893-409e-852f-9ee886ce94a6") }); + + // Assert + result.Exists.Should().BeTrue(); + result.IsUserOfCompany.Should().BeTrue(); + result.Details.Should().NotBeNull().And.Match(x => + x.Name == "Project Implementation: Earth Commerce" && + x.Customer == "Bayerische Motorenwerke AG" && + x.Bpn == "BPNL00000003AYRE" && + x.Contact.SequenceEqual(new[] { "test@email.com" }) && + x.OfferSubscriptionStatus == OfferSubscriptionStatusId.ACTIVE && + x.TenantUrl == "https://ec-qas.d13fe27.kyma.ondemand.com" && + x.AppInstanceId == "https://catenax-int-dismantler-s66pftcc.authentication.eu10.hana.ondemand.com" && + x.ProcessSteps.Count() == 0); + } + + [Fact] + public async Task GetOfferSubscriptionDetailForServiceProviderAsync_ReturnsExpected() { // Arrange var (sut, _) = await CreateSut(); @@ -262,8 +285,8 @@ public async Task GetOfferSubscriptionDetailForProviderAsync_ReturnsExpected() x.Customer == "CX-Operator" && x.Contact.SequenceEqual(new[] { "tobeadded@cx.com" }) && x.OfferSubscriptionStatus == OfferSubscriptionStatusId.ACTIVE && - x.TenantUrl == "https://ec-qas.d13fe27.kyma.ondemand.com" && - x.AppInstanceId == "https://catenax-int-dismantler-s66pftcc.authentication.eu10.hana.ondemand.com" && + x.TenantUrl == null && + x.AppInstanceId == null && x.ProcessSteps.Count() == 3 && x.ProcessSteps.Count(y => y.ProcessStepTypeId == ProcessStepTypeId.AWAIT_START_AUTOSETUP && y.ProcessStepStatusId == ProcessStepStatusId.TODO) == 1); } diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/OfferSubscriptionViewTests.cs b/tests/portalbackend/PortalBackend.DBAccess.Tests/OfferSubscriptionViewTests.cs index a21fb09929..3b9ae1f273 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/OfferSubscriptionViewTests.cs +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/OfferSubscriptionViewTests.cs @@ -56,16 +56,20 @@ public async Task OfferSubscriptionView_GetAll_ReturnsExpected() public async Task OfferSubscriptionView_GetSpecific_ReturnsExpected() { // Arrange - var subscriptionId = new Guid("3de6a31f-a5d1-4f60-aa3a-4b1a769becbf"); + var subscriptionId = new Guid("0b2ca541-206d-48ad-bc02-fb61fbcb5552"); var sut = await CreateContext(); // Act - var result = await sut.OfferSubscriptionView.SingleOrDefaultAsync(x => x.SubscriptionId == subscriptionId); - result.Should().NotBeNull(); - result!.SubscriptionId.Should().Be(subscriptionId); - result.OfferTypeId.Should().Be(OfferTypeId.SERVICE); - result.TechnicalUser.Should().Be(new Guid("d0c8ae19-d4f3-49cc-9cb4-6c766d4680f2")); - result.AppInstance.Should().Be(new Guid("ab25c218-9ab3-4f1a-b6f4-6394fbc33c5b")); + var result = await sut.OfferSubscriptionView.Where(x => x.SubscriptionId == subscriptionId).ToListAsync(); + result.Should().HaveCount(2) + .And.AllSatisfy(x => + x.Should().Match(x => + x.SubscriptionId == subscriptionId && + x.OfferTypeId == OfferTypeId.APP && + x.AppInstance == new Guid("ab25c218-9ab3-4f1a-b6f4-6394fbc33c5a"))) + .And.Satisfy( + x => x.TechnicalUser == new Guid("93eecd4e-ca47-4dd2-85bf-775ea72eb000"), + x => x.TechnicalUser == new Guid("d0c8ae19-d4f3-49cc-9cb4-6c766d4680f3")); } #endregion diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/app_subscription_details.unittest.json b/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/app_subscription_details.unittest.json index 2bdb86932e..c7e15ad196 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/app_subscription_details.unittest.json +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/app_subscription_details.unittest.json @@ -6,13 +6,6 @@ "app_subscription_url": "https://ec-qas.d13fe27.kyma.ondemand.com", "last_editor_id": null }, - { - "id": "88b0661c-cc22-4a4a-9721-fc4f3cec21f9", - "offer_subscription_id": "3de6a31f-a5d1-4f60-aa3a-4b1a769becbf", - "app_instance_id": "ab25c218-9ab3-4f1a-b6f4-6394fbc33c5b", - "app_subscription_url": "https://ec-qas.d13fe27.kyma.ondemand.com", - "last_editor_id": null - }, { "id": "bedb45bf-7094-4da0-9e69-0695db782a16", "offer_subscription_id": "ed4de48d-fd4b-4384-a72f-ecae3c6cc5ba", diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/identity_assigned_roles.unittest.json b/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/identity_assigned_roles.unittest.json index 67e4b02a52..77430f9f61 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/identity_assigned_roles.unittest.json +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/identity_assigned_roles.unittest.json @@ -68,5 +68,15 @@ "identity_id": "8b42e6de-7b59-4217-a63c-198e83d93777", "user_role_id": "7410693c-c893-409e-852f-9ee886ce94a6", "last_editor_id": null - } + }, + { + "identity_id": "8b42e6de-7b59-4217-a63c-198e83d93776", + "user_role_id": "7410693c-c893-409e-852f-9ee886ce94a6", + "last_editor_id": null + }, + { + "identity_id": "8b42e6de-7b59-4217-a63c-198e83d93776", + "user_role_id": "efc20368-9e82-46ff-b88f-6495b9810253", + "last_editor_id": null + } ] diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/technical_users.unittest.json b/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/technical_users.unittest.json index f6866ec5d7..3049e8ea9d 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/technical_users.unittest.json +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/technical_users.unittest.json @@ -1,13 +1,4 @@ [ - { - "id": "d0c8ae19-d4f3-49cc-9cb4-6c766d4680f2", - "name": "sa-test", - "description": "SA for offer subscription", - "technical_user_type_id": 2, - "technical_user_kind_id": 1, - "offer_subscription_id": "3DE6A31F-A5D1-4F60-AA3A-4B1A769BECBF", - "client_client_id":"sa-x-4" - }, { "id": "d0c8ae19-d4f3-49cc-9cb4-6c766d4680f3", "name": "sa-test", diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/user_roles.unittest.json b/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/user_roles.unittest.json index 3bfc0f7f23..c8cf3c65ab 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/user_roles.unittest.json +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/user_roles.unittest.json @@ -14,19 +14,19 @@ { "id": "aabcdfeb-6669-4c74-89f0-19cda090873e", "user_role": "test", - "offer_id": "a16e73b9-5277-4b69-9f8d-3b227495dfea", + "offer_id": "9b957704-3505-4445-822c-d7ef80f27fcd", "last_editor_id": null }, { "id": "efc20368-9e82-46ff-b88f-6495b9810254", "user_role": "Company Admin", - "offer_id": "a16e73b9-5277-4b69-9f8d-3b227495dfea", + "offer_id": "9b957704-3505-4445-822c-d7ef80f27fcd", "last_editor_id": null }, { "id": "efc20368-9e82-46ff-b88f-6495b9810255", "user_role": "IT Admin", - "offer_id": "a16e73b9-5277-4b69-9f8d-3b227495dfea", + "offer_id": "9b957704-3505-4445-822c-d7ef80f27fcd", "last_editor_id": null }, { diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/TechnicalUserRepositoryTests.cs b/tests/portalbackend/PortalBackend.DBAccess.Tests/TechnicalUserRepositoryTests.cs index 257ee388ff..9a2ffbaaa2 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/TechnicalUserRepositoryTests.cs +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/TechnicalUserRepositoryTests.cs @@ -292,9 +292,9 @@ public async Task GetOwnCompanyServiceAccountsUntracked_WithOwnerTrue_ReturnsExp // Assert result.Should().NotBeNull(); - result!.Count.Should().Be(22); + result!.Count.Should().Be(21); result.Data.Should().HaveCount(10) - .And.AllSatisfy(x => x.Should().Match(y => + .And.AllSatisfy(x => x.Should().Match(y => y.TechnicalUserTypeId == TechnicalUserTypeId.OWN && y.UserStatusId == UserStatusId.ACTIVE)) .And.BeInAscendingOrder(x => x.Name)