Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
woutslakhorst committed Oct 31, 2023
1 parent ce97c65 commit 4c145c0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 64 deletions.
3 changes: 3 additions & 0 deletions vcr/pe/submission_requirement.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 37 additions & 0 deletions vcr/pe/submission_requirement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
4 changes: 2 additions & 2 deletions vcr/pe/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
}
62 changes: 0 additions & 62 deletions vcr/pe/types_test.go

This file was deleted.

0 comments on commit 4c145c0

Please sign in to comment.