From 4c145c0043214045c55f824d892c3008be2777c7 Mon Sep 17 00:00:00 2001 From: Wout Slakhorst Date: Tue, 31 Oct 2023 09:23:41 +0100 Subject: [PATCH] PR feedback --- vcr/pe/submission_requirement.go | 3 ++ vcr/pe/submission_requirement_test.go | 37 ++++++++++++++++ vcr/pe/types.go | 4 +- vcr/pe/types_test.go | 62 --------------------------- 4 files changed, 42 insertions(+), 64 deletions(-) delete mode 100644 vcr/pe/types_test.go diff --git a/vcr/pe/submission_requirement.go b/vcr/pe/submission_requirement.go index 7b4141318d..0dfa5649a8 100644 --- a/vcr/pe/submission_requirement.go +++ b/vcr/pe/submission_requirement.go @@ -48,6 +48,9 @@ func (submissionRequirement SubmissionRequirement) match(availableGroups map[str if submissionRequirement.From != "" && len(submissionRequirement.FromNested) > 0 { return nil, fmt.Errorf("submission requirement (%s) contains both 'from' and 'from_nested'", submissionRequirement.Name) } + if submissionRequirement.From == "" && len(submissionRequirement.FromNested) == 0 { + return nil, fmt.Errorf("submission requirement (%s) is missing 'from' or 'from_nested'", submissionRequirement.Name) + } if !(submissionRequirement.Rule == "all" || submissionRequirement.Rule == "pick") { return nil, fmt.Errorf("submission requirement (%s) contains unknown rule (%s)", submissionRequirement.Name, submissionRequirement.Rule) diff --git a/vcr/pe/submission_requirement_test.go b/vcr/pe/submission_requirement_test.go index e053251081..5b7308304d 100644 --- a/vcr/pe/submission_requirement_test.go +++ b/vcr/pe/submission_requirement_test.go @@ -37,3 +37,40 @@ func Test_match(t *testing.T) { assert.EqualError(t, err, "submission requirement (test) contains both 'from' and 'from_nested'") }) } + +func TestSubmissionRequirement_Groups(t *testing.T) { + t.Run("group from a single requirement", func(t *testing.T) { + requirement := SubmissionRequirement{ + From: "A", + } + + groups := requirement.Groups() + + assert.Equal(t, []string{"A"}, groups) + }) + t.Run("groups from nested requirements", func(t *testing.T) { + requirement := SubmissionRequirement{ + From: "A", + FromNested: []*SubmissionRequirement{ + {From: "B"}, + }, + } + + groups := requirement.Groups() + + assert.Equal(t, []string{"A", "B"}, groups) + }) + t.Run("deduplicate groups", func(t *testing.T) { + requirement := SubmissionRequirement{ + From: "A", + FromNested: []*SubmissionRequirement{ + {From: "B"}, + {From: "A"}, + }, + } + + groups := requirement.Groups() + + assert.Equal(t, []string{"A", "B"}, groups) + }) +} diff --git a/vcr/pe/types.go b/vcr/pe/types.go index 9e84fc7cf5..31fb145708 100644 --- a/vcr/pe/types.go +++ b/vcr/pe/types.go @@ -104,7 +104,7 @@ type Statuses struct { Suspended *StatusDirective `json:"suspended,omitempty"` } -// Field describes a field in a presentation submission, predicate feature is not implemented +// Field describes a constraints field in a presentation definition's input descriptor. The predicate feature is not implemented type Field struct { Id *string `json:"id,omitempty"` Optional *bool `json:"optional,omitempty"` @@ -135,5 +135,5 @@ type SubmissionRequirement struct { Max *int `json:"max,omitempty"` Min *int `json:"min,omitempty"` Name string `json:"name,omitempty"` - Rule string `json:"rule,omitempty"` + Rule string `json:"rule"` } diff --git a/vcr/pe/types_test.go b/vcr/pe/types_test.go deleted file mode 100644 index 0cfbbb0674..0000000000 --- a/vcr/pe/types_test.go +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2023 Nuts community - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package pe - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestSubmissionRequirement_Groups(t *testing.T) { - t.Run("group from a single requirement", func(t *testing.T) { - requirement := SubmissionRequirement{ - From: "A", - } - - groups := requirement.Groups() - - assert.Equal(t, []string{"A"}, groups) - }) - t.Run("groups from nested requirements", func(t *testing.T) { - requirement := SubmissionRequirement{ - From: "A", - FromNested: []*SubmissionRequirement{ - {From: "B"}, - }, - } - - groups := requirement.Groups() - - assert.Equal(t, []string{"A", "B"}, groups) - }) - t.Run("deduplicate groups", func(t *testing.T) { - requirement := SubmissionRequirement{ - From: "A", - FromNested: []*SubmissionRequirement{ - {From: "B"}, - {From: "A"}, - }, - } - - groups := requirement.Groups() - - assert.Equal(t, []string{"A", "B"}, groups) - }) -}