forked from eclipse-tractusx/traceability-foss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
132 additions
and
6 deletions.
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
...app/modules/page/admin/presentation/policy-management/policies/policies.assembler.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { PoliciesAssembler } from '@page/admin/presentation/policy-management/policies/policy.assembler'; | ||
import { OperatorType, Policy, PolicyAction, PolicyEntry, PolicyResponseMap } from '@page/policies/model/policy.model'; | ||
|
||
// Mock data | ||
const mockPolicy: Policy = { | ||
policyId: 'policy123', | ||
createdOn: '2024-01-01T00:00:00Z', | ||
validUntil: '2024-12-31T23:59:59Z', | ||
permissions: [ | ||
{ | ||
action: 'use' as PolicyAction, | ||
constraint: { | ||
and: [ | ||
{ | ||
leftOperand: 'left1', | ||
operator: { '@id': OperatorType.EQ }, | ||
operatorTypeResponse: OperatorType.EQ, | ||
'odrl:rightOperand': 'right1', | ||
}, | ||
], | ||
or: [ | ||
{ | ||
leftOperand: 'left2', | ||
operator: { '@id': OperatorType.NEQ }, | ||
operatorTypeResponse: OperatorType.NEQ, | ||
'odrl:rightOperand': 'right2', | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
constraints: [], | ||
}; | ||
|
||
const mockPolicy2: Policy = { | ||
policyId: 'policy123', | ||
createdOn: '2024-01-01T00:00:00Z', | ||
validUntil: '2024-12-31T23:59:59Z', | ||
permissions: [ | ||
{ | ||
action: 'use' as PolicyAction, | ||
constraints: { | ||
and: [ | ||
{ | ||
leftOperand: 'left1', | ||
operator: { '@id': OperatorType.EQ }, | ||
operatorTypeResponse: OperatorType.EQ, | ||
rightOperand: 'right1', | ||
}, | ||
], | ||
or: [ | ||
{ | ||
leftOperand: 'left2', | ||
operator: { '@id': OperatorType.NEQ }, | ||
operatorTypeResponse: OperatorType.NEQ, | ||
rightOperand: 'right2', | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
constraints: [], | ||
}; | ||
|
||
const mockPolicyResponse: PolicyResponseMap = { | ||
'bpn123': [ | ||
{ | ||
payload: { | ||
'@context': { | ||
odrl: 'test', | ||
}, | ||
'@id': 'entry123', | ||
policy: mockPolicy, | ||
}, | ||
validUntil: '2024-01-01T00:00:00Z', | ||
}, | ||
], | ||
}; | ||
|
||
describe('PoliciesAssembler', () => { | ||
it('should assemble policy', () => { | ||
const assembledPolicy = PoliciesAssembler.assemblePolicy(mockPolicy); | ||
expect(assembledPolicy.policyName).toBe(mockPolicy.policyId); | ||
expect(assembledPolicy.createdOn).toBe('2024-01-01T00:00'); | ||
expect(assembledPolicy.validUntil).toBe('2024-12-31T23:59'); | ||
expect(assembledPolicy.accessType).toBe('USE'); | ||
expect(assembledPolicy.constraints).toEqual([]); | ||
}); | ||
|
||
it('should map policy response to policy entry list', () => { | ||
const policyEntryList = PoliciesAssembler.mapToPolicyEntryList(mockPolicyResponse); | ||
expect(policyEntryList.length).toBe(1); | ||
expect(policyEntryList[0].payload.policy.bpn).toBe('bpn123'); | ||
expect(policyEntryList[0].payload.policy.policyName).toBe('entry123'); | ||
}); | ||
|
||
it('should map display props to policy root level from policy entry', () => { | ||
const policyEntry: PolicyEntry = { | ||
validUntil: '2024-01-01T00:00:00Z', | ||
payload: { | ||
'@context': { | ||
odrl: 'test', | ||
}, | ||
'@id': 'entry123', | ||
policy: mockPolicy, | ||
}, | ||
}; | ||
const constraints = PoliciesAssembler.mapDisplayPropsToPolicyRootLevelFromPolicyEntry(policyEntry); | ||
expect(constraints).toEqual([ | ||
'left1', '=', 'right1', 'left2', '!=', 'right2', | ||
]); | ||
}); | ||
|
||
it('should map display props to policy root level from policy', () => { | ||
const constraints = PoliciesAssembler.mapDisplayPropsToPolicyRootLevelFromPolicy(mockPolicy2); | ||
expect(constraints).toEqual([ | ||
'left1', '=', 'right1', 'left2', '!=', 'right2', | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters