Skip to content

Commit

Permalink
fix inconsistent test-data and unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ntruchsess committed Nov 13, 2024
1 parent a98388f commit a05159c
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,10 @@ public OfferSubscription AttachAndModifyOfferSubscription(Guid offerSubscription
/// <inheritdoc />
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<Guid, Guid, string?, string, Guid, string>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<OfferProviderSubscriptionDetail>(x =>
x.Name == "Project Implementation: Earth Commerce" &&
x.Customer == "Bayerische Motorenwerke AG" &&
x.Bpn == "BPNL00000003AYRE" &&
x.Contact.SequenceEqual(new[] { "[email protected]" }) &&
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();
Expand All @@ -262,8 +285,8 @@ public async Task GetOfferSubscriptionDetailForProviderAsync_ReturnsExpected()
x.Customer == "CX-Operator" &&
x.Contact.SequenceEqual(new[] { "[email protected]" }) &&
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PortalEntities.Views.OfferSubscriptionView>(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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Models.CompanyServiceAccountData>(y =>
.And.AllSatisfy(x => x.Should().Match<CompanyServiceAccountData>(y =>
y.TechnicalUserTypeId == TechnicalUserTypeId.OWN &&
y.UserStatusId == UserStatusId.ACTIVE))
.And.BeInAscendingOrder(x => x.Name)
Expand Down

0 comments on commit a05159c

Please sign in to comment.