Skip to content

Commit

Permalink
fix(seeding): add purpose trace 3.1 id (#15)
Browse files Browse the repository at this point in the history
* remove type purpose
* add policy "purpose"
---------------------
Refs: CPLP-3635
Reviewed-By: Evelyn Gurschler <[email protected]>
  • Loading branch information
Phil91 authored Jan 23, 2024
1 parent 7fb9c93 commit 243488a
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 50 deletions.
3 changes: 1 addition & 2 deletions src/database/PolicyHub.Entities/Enums/PolicyTypeId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ namespace Org.Eclipse.TractusX.PolicyHub.Entities.Enums;
public enum PolicyTypeId
{
Access = 1,
Usage = 2,
Purpose = 3
Usage = 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -303,12 +301,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
Id = 2,
IsActive = true,
Label = "Usage"
},
new
{
Id = 3,
IsActive = true,
Label = "Purpose"
});
});

Expand Down
10 changes: 9 additions & 1 deletion src/database/PolicyHub.Migrations/Seeder/Data/policies.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
]
{ "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 }
]
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
]
{ "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 }
]
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[
{ "policy_kind_id": 3, "right_operand_value": "active:{0}" }
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -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")
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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<PolicyTypeResponse>()
.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
);
}

Expand All @@ -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"
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 243488a

Please sign in to comment.