From 0fcfe0173738b1dc8b50786cde8214279821e56e Mon Sep 17 00:00:00 2001 From: Timo Glastra Date: Thu, 25 Apr 2024 10:46:36 +0200 Subject: [PATCH] test: const value tests Signed-off-by: Timo Glastra --- test/PEX.spec.ts | 15 +++++++++- test/resources/pd_const_values.json | 46 +++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/resources/pd_const_values.json diff --git a/test/PEX.spec.ts b/test/PEX.spec.ts index a9709c95..b1b07809 100644 --- a/test/PEX.spec.ts +++ b/test/PEX.spec.ts @@ -12,7 +12,7 @@ import { WrappedW3CVerifiableCredential, } from '@sphereon/ssi-types'; -import { EvaluationResults, PEX, Validated } from '../lib'; +import { EvaluationResults, PEX, PEXv2, Validated } from '../lib'; import { VerifiablePresentationResult } from '../lib/signing/types'; import { SSITypesBuilder } from '../lib/types'; @@ -198,6 +198,19 @@ describe('evaluate', () => { expect(result).toEqual([{ message: 'ok', status: 'info', tag: 'root' }]); }); + it('correct handles presentation definition with const values in filter', () => { + const pdSchema: PresentationDefinitionV2 = getFileAsJson('./test/resources/pd_const_values.json').presentation_definition; + const result = PEXv2.validateDefinition(pdSchema); + + expect(result).toEqual([ + { + tag: 'root', + status: 'info', + message: 'ok', + }, + ]); + }); + it('Evaluate presentationDefinition v2', () => { const pd: PresentationDefinitionV2 = getPresentationDefinitionV2(); const result: Validated = PEX.validateDefinition(pd); diff --git a/test/resources/pd_const_values.json b/test/resources/pd_const_values.json new file mode 100644 index 00000000..ea76a776 --- /dev/null +++ b/test/resources/pd_const_values.json @@ -0,0 +1,46 @@ +{ + "presentation_definition": { + "id": "56e001a9-c41f-49c5-9b12-440ad4861f58", + "name": "DIIP v3 compliance", + "purpose": "Prove you're compliant with DIIP v3", + "input_descriptors": [ + { + "id": "b2a1f1d3-37ee-4494-98e2-ef9853b28197", + "name": "DIIP v3 compliance", + "purpose": "Prove you're compliant with DIIP v3", + "format": { + "vc+sd-jwt": {} + }, + "constraints": { + "limit_disclosure": "preferred", + "fields": [ + { + "path": ["$.compliant"], + "name": "compliant", + "filter": { + "type": "boolean", + "const": true + } + }, + { + "path": ["$.name"], + "name": "name", + "filter": { + "type": "string", + "const": "name" + } + }, + { + "path": ["$.age"], + "name": "age", + "filter": { + "type": "number", + "const": 12 + } + } + ] + } + } + ] + } +}