From 243488aece1731481a5aebd67f2b8de961987cbd Mon Sep 17 00:00:00 2001 From: Phil Schneider Date: Tue, 23 Jan 2024 10:06:20 +0100 Subject: [PATCH] fix(seeding): add purpose trace 3.1 id (#15) * remove type purpose * add policy "purpose" --------------------- Refs: CPLP-3635 Reviewed-By: Evelyn Gurschler --- .../PolicyHub.Entities/Enums/PolicyTypeId.cs | 3 +-- .../Migrations/20240122150103_0.1.0-rc.1.cs | 3 +-- .../PolicyHubContextModelSnapshot.cs | 8 ------ .../Seeder/Data/policies.json | 10 ++++++- .../Seeder/Data/policy_assigned_types.json | 5 ++-- .../Data/policy_assigned_use_cases.json | 5 ++-- .../Seeder/Data/policy_attributes.json | 8 +++++- .../Data/policy_kind_configurations.json | 2 +- .../Extensions/JsonGenerationExtensions.cs | 1 - .../PolicyRepositoryTests.cs | 5 ++-- .../PolicyHubBusinessLogicTests.cs | 27 +++---------------- .../Controllers/PolicyHubControllerTests.cs | 10 ++++--- .../JsonGenerationExtensionsTests.cs | 1 - 13 files changed, 38 insertions(+), 50 deletions(-) diff --git a/src/database/PolicyHub.Entities/Enums/PolicyTypeId.cs b/src/database/PolicyHub.Entities/Enums/PolicyTypeId.cs index c17689d..8e955e6 100644 --- a/src/database/PolicyHub.Entities/Enums/PolicyTypeId.cs +++ b/src/database/PolicyHub.Entities/Enums/PolicyTypeId.cs @@ -22,6 +22,5 @@ namespace Org.Eclipse.TractusX.PolicyHub.Entities.Enums; public enum PolicyTypeId { Access = 1, - Usage = 2, - Purpose = 3 + Usage = 2 } diff --git a/src/database/PolicyHub.Migrations/Migrations/20240122150103_0.1.0-rc.1.cs b/src/database/PolicyHub.Migrations/Migrations/20240122150103_0.1.0-rc.1.cs index 5054529..1a5e493 100644 --- a/src/database/PolicyHub.Migrations/Migrations/20240122150103_0.1.0-rc.1.cs +++ b/src/database/PolicyHub.Migrations/Migrations/20240122150103_0.1.0-rc.1.cs @@ -250,8 +250,7 @@ protected override void Up(MigrationBuilder migrationBuilder) values: new object[,] { { 1, true, "Access" }, - { 2, true, "Usage" }, - { 3, true, "Purpose" } + { 2, true, "Usage" } }); migrationBuilder.InsertData( diff --git a/src/database/PolicyHub.Migrations/Migrations/PolicyHubContextModelSnapshot.cs b/src/database/PolicyHub.Migrations/Migrations/PolicyHubContextModelSnapshot.cs index 60b0a41..a4563f1 100644 --- a/src/database/PolicyHub.Migrations/Migrations/PolicyHubContextModelSnapshot.cs +++ b/src/database/PolicyHub.Migrations/Migrations/PolicyHubContextModelSnapshot.cs @@ -23,8 +23,6 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Org.Eclipse.TractusX.PolicyHub.Entities; -#nullable disable - namespace Org.Eclipse.TractusX.PolicyHub.Migrations.Migrations { [DbContext(typeof(PolicyHubContext))] @@ -303,12 +301,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) Id = 2, IsActive = true, Label = "Usage" - }, - new - { - Id = 3, - IsActive = true, - Label = "Purpose" }); }); diff --git a/src/database/PolicyHub.Migrations/Seeder/Data/policies.json b/src/database/PolicyHub.Migrations/Seeder/Data/policies.json index e3e3c0c..cdfdb02 100644 --- a/src/database/PolicyHub.Migrations/Seeder/Data/policies.json +++ b/src/database/PolicyHub.Migrations/Seeder/Data/policies.json @@ -79,5 +79,13 @@ "description": "Company role defining a dismantler. Companies holding the credential are dismantler certified companies.", "is_active": true, "attribute_key_id": 4 + }, + { + "id": "01a0fba3-9b6e-435a-b045-e0e890c300c2", + "kind_id": 4, + "technical_key": "purpose", + "description": "", + "is_active": true, + "attribute_key_id": 3 } -] \ No newline at end of file +] diff --git a/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_types.json b/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_types.json index 5076b71..acd5385 100644 --- a/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_types.json +++ b/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_types.json @@ -11,5 +11,6 @@ { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b8", "policy_type_id": 2, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300b9", "policy_type_id": 2, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", "policy_type_id": 1, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", "policy_type_id": 2, "is_active": true } -] \ No newline at end of file + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", "policy_type_id": 2, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c2", "policy_type_id": 2, "is_active": true } +] diff --git a/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_use_cases.json b/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_use_cases.json index 2101e9e..dd48519 100644 --- a/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_use_cases.json +++ b/src/database/PolicyHub.Migrations/Seeder/Data/policy_assigned_use_cases.json @@ -20,5 +20,6 @@ { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", "use_case_id": 2, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", "use_case_id": 3, "is_active": true }, { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", "use_case_id": 4, "is_active": true }, - { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", "use_case_id": 5, "is_active": true } -] \ No newline at end of file + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c1", "use_case_id": 5, "is_active": true }, + { "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c2", "use_case_id": 1, "is_active": true } +] diff --git a/src/database/PolicyHub.Migrations/Seeder/Data/policy_attributes.json b/src/database/PolicyHub.Migrations/Seeder/Data/policy_attributes.json index a9bfd0b..8afec65 100644 --- a/src/database/PolicyHub.Migrations/Seeder/Data/policy_attributes.json +++ b/src/database/PolicyHub.Migrations/Seeder/Data/policy_attributes.json @@ -82,5 +82,11 @@ "key": 4, "attribute_value": "VW", "is_active": true + }, + { + "policy_id": "01a0fba3-9b6e-435a-b045-e0e890c300c2", + "key": 2, + "attribute_value": "ID Trace 3.1", + "is_active": true } -] \ No newline at end of file +] diff --git a/src/database/PolicyHub.Migrations/Seeder/Data/policy_kind_configurations.json b/src/database/PolicyHub.Migrations/Seeder/Data/policy_kind_configurations.json index be3fa56..f47fb46 100644 --- a/src/database/PolicyHub.Migrations/Seeder/Data/policy_kind_configurations.json +++ b/src/database/PolicyHub.Migrations/Seeder/Data/policy_kind_configurations.json @@ -1,3 +1,3 @@ [ { "policy_kind_id": 3, "right_operand_value": "active:{0}" } -] \ No newline at end of file +] diff --git a/src/hub/PolicyHub.Service/Extensions/JsonGenerationExtensions.cs b/src/hub/PolicyHub.Service/Extensions/JsonGenerationExtensions.cs index 80a66b7..1e21746 100644 --- a/src/hub/PolicyHub.Service/Extensions/JsonGenerationExtensions.cs +++ b/src/hub/PolicyHub.Service/Extensions/JsonGenerationExtensions.cs @@ -28,7 +28,6 @@ public static string TypeToJsonString(this PolicyTypeId type) => { PolicyTypeId.Access => "access", PolicyTypeId.Usage => "use", - PolicyTypeId.Purpose => "use", _ => throw new ArgumentOutOfRangeException(nameof(type), type, $"{type} is not a valid value") }; diff --git a/tests/database/PolicyHub.DbAccess.Tests/PolicyRepositoryTests.cs b/tests/database/PolicyHub.DbAccess.Tests/PolicyRepositoryTests.cs index 3134ba7..392d5fe 100644 --- a/tests/database/PolicyHub.DbAccess.Tests/PolicyRepositoryTests.cs +++ b/tests/database/PolicyHub.DbAccess.Tests/PolicyRepositoryTests.cs @@ -70,7 +70,7 @@ public async Task GetPolicyTypes_ReturnsExpectedResult() var result = await sut.GetPolicyTypes(null, null).ToListAsync().ConfigureAwait(false); // Assert - result.Should().NotBeEmpty().And.HaveCount(10).And.Satisfy( + result.Should().NotBeEmpty().And.HaveCount(11).And.Satisfy( x => x.TechnicalKey == "BusinessPartnerNumber", x => x.TechnicalKey == "Membership", x => x.TechnicalKey == "FrameworkAgreement.traceability", @@ -80,7 +80,8 @@ public async Task GetPolicyTypes_ReturnsExpectedResult() x => x.TechnicalKey == "purpose.trace.v1.TraceBattery", x => x.TechnicalKey == "purpose.trace.v1.aspects", x => x.TechnicalKey == "companyRole.dismantler", - x => x.TechnicalKey == "purpose.trace.v1.qualityanalysis" + x => x.TechnicalKey == "purpose.trace.v1.qualityanalysis", + x => x.TechnicalKey == "purpose" ); } diff --git a/tests/hub/PolicyHub.Service.Tests/BusinessLogic/PolicyHubBusinessLogicTests.cs b/tests/hub/PolicyHub.Service.Tests/BusinessLogic/PolicyHubBusinessLogicTests.cs index a838f01..12288fa 100644 --- a/tests/hub/PolicyHub.Service.Tests/BusinessLogic/PolicyHubBusinessLogicTests.cs +++ b/tests/hub/PolicyHub.Service.Tests/BusinessLogic/PolicyHubBusinessLogicTests.cs @@ -78,20 +78,7 @@ public async Task GetPolicyTypes_WithoutFilter_ReturnsExpected() var result = await _sut.GetPolicyTypes(null, null).ToListAsync().ConfigureAwait(false); // Assert - result.Should().HaveCount(3); - } - - [Fact] - public async Task GetPolicyTypes_WithPolicyTypeFilter_ReturnsExpected() - { - // Arrange - Setup_GetPolicyTypes(); - - // Act - var result = await _sut.GetPolicyTypes(PolicyTypeId.Purpose, null).ToListAsync().ConfigureAwait(false); - - // Assert - result.Should().ContainSingle(); + result.Should().HaveCount(2); } [Fact] @@ -104,7 +91,7 @@ public async Task GetPolicyTypes_WithUseCaseFilter_ReturnsExpected() var result = await _sut.GetPolicyTypes(null, UseCaseId.Sustainability).ToListAsync().ConfigureAwait(false); // Assert - result.Should().HaveCount(2); + result.Should().ContainSingle(); } #endregion @@ -410,17 +397,11 @@ private void Setup_GetPolicyTypes() .With(x => x.UseCase, Enumerable.Repeat(UseCaseId.Traceability, 1)) .With(x => x.Type, Enumerable.Repeat(PolicyTypeId.Access, 1)) .Create(); - var susPurpose = _fixture.Build() - .With(x => x.UseCase, Enumerable.Repeat(UseCaseId.Sustainability, 1)) - .With(x => x.Type, Enumerable.Repeat(PolicyTypeId.Purpose, 1)) - .Create(); A.CallTo(() => _policyRepository.GetPolicyTypes(null, null)) - .Returns(new[] { susAccess, traceAccess, susPurpose }.ToAsyncEnumerable()); - A.CallTo(() => _policyRepository.GetPolicyTypes(PolicyTypeId.Purpose, null)) - .Returns(new[] { susPurpose }.ToAsyncEnumerable()); + .Returns(new[] { susAccess, traceAccess }.ToAsyncEnumerable()); A.CallTo(() => _policyRepository.GetPolicyTypes(null, UseCaseId.Sustainability)) - .Returns(new[] { susAccess, susPurpose }.ToAsyncEnumerable()); + .Returns(new[] { susAccess }.ToAsyncEnumerable()); } #endregion diff --git a/tests/hub/PolicyHub.Service.Tests/Controllers/PolicyHubControllerTests.cs b/tests/hub/PolicyHub.Service.Tests/Controllers/PolicyHubControllerTests.cs index fc782d7..751b84c 100644 --- a/tests/hub/PolicyHub.Service.Tests/Controllers/PolicyHubControllerTests.cs +++ b/tests/hub/PolicyHub.Service.Tests/Controllers/PolicyHubControllerTests.cs @@ -78,7 +78,7 @@ public async Task GetPolicyTypes_WithoutFilter_ReturnsExpected() // Assert policies.Should().NotBeNull() - .And.HaveCount(10).And.Satisfy( + .And.HaveCount(11).And.Satisfy( x => x.TechnicalKey == "BusinessPartnerNumber", x => x.TechnicalKey == "Membership", x => x.TechnicalKey == "FrameworkAgreement.traceability", @@ -88,7 +88,8 @@ public async Task GetPolicyTypes_WithoutFilter_ReturnsExpected() x => x.TechnicalKey == "purpose.trace.v1.TraceBattery", x => x.TechnicalKey == "purpose.trace.v1.aspects", x => x.TechnicalKey == "companyRole.dismantler", - x => x.TechnicalKey == "purpose.trace.v1.qualityanalysis" + x => x.TechnicalKey == "purpose.trace.v1.qualityanalysis", + x => x.TechnicalKey == "purpose" ); } @@ -115,14 +116,15 @@ public async Task GetPolicyTypes_WithUseCaseFilter_ReturnsExpected() // Assert policies.Should().NotBeNull() - .And.HaveCount(7).And.Satisfy( + .And.HaveCount(8).And.Satisfy( x => x.TechnicalKey == "BusinessPartnerNumber", x => x.TechnicalKey == "Membership", x => x.TechnicalKey == "FrameworkAgreement.traceability", x => x.TechnicalKey == "purpose.trace.v1.TraceBattery", x => x.TechnicalKey == "purpose.trace.v1.aspects", x => x.TechnicalKey == "companyRole.dismantler", - x => x.TechnicalKey == "purpose.trace.v1.qualityanalysis" + x => x.TechnicalKey == "purpose.trace.v1.qualityanalysis", + x => x.TechnicalKey == "purpose" ); } diff --git a/tests/hub/PolicyHub.Service.Tests/Extensions/JsonGenerationExtensionsTests.cs b/tests/hub/PolicyHub.Service.Tests/Extensions/JsonGenerationExtensionsTests.cs index 1b82571..a64db63 100644 --- a/tests/hub/PolicyHub.Service.Tests/Extensions/JsonGenerationExtensionsTests.cs +++ b/tests/hub/PolicyHub.Service.Tests/Extensions/JsonGenerationExtensionsTests.cs @@ -27,7 +27,6 @@ public class JsonGenerationExtensionsTests [Theory] [InlineData(PolicyTypeId.Access, "access")] [InlineData(PolicyTypeId.Usage, "use")] - [InlineData(PolicyTypeId.Purpose, "use")] public void TypeToJsonString_WithValidData_ReturnsExpected(PolicyTypeId policyTypeId, string result) { // Act