Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul committed Nov 3, 2023
1 parent e8f2a55 commit 9129d70
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions vcr/pe/submission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,8 @@ func TestParsePresentationSubmission(t *testing.T) {
}

func TestPresentationSubmission_Credentials(t *testing.T) {
credential1ID := ssi.MustParseURI("cred-1")
credential1 := vc.VerifiableCredential{
ID: &credential1ID,
}
credential2ID := ssi.MustParseURI("cred-2")
credential2 := vc.VerifiableCredential{
ID: &credential2ID,
}
credential1 := makeTestCredential(t, ssi.MustParseURI("cred-1"))
credential2 := makeTestCredential(t, ssi.MustParseURI("cred-2"))

t.Run("1 input descriptor", func(t *testing.T) {
vp := vc.VerifiablePresentation{
Expand All @@ -69,7 +63,7 @@ func TestPresentationSubmission_Credentials(t *testing.T) {
credentials, err := submission.Credentials(vp)

require.NoError(t, err)
assert.Equal(t, []vc.VerifiableCredential{credential1}, credentials)
assert.Equal(t, map[string]vc.VerifiableCredential{"1": credential1}, credentials)
})
t.Run("2 input descriptors", func(t *testing.T) {
vp := vc.VerifiablePresentation{
Expand All @@ -96,7 +90,7 @@ func TestPresentationSubmission_Credentials(t *testing.T) {
credentials, err := submission.Credentials(vp)

require.NoError(t, err)
assert.Equal(t, []vc.VerifiableCredential{credential1, credential2}, credentials)
assert.Equal(t, map[string]vc.VerifiableCredential{"1": credential1, "2": credential2}, credentials)
})
t.Run("input descriptor does not match", func(t *testing.T) {
vp := vc.VerifiablePresentation{
Expand Down Expand Up @@ -145,7 +139,7 @@ func TestPresentationSubmission_Credentials(t *testing.T) {
credentials, err := submission.Credentials(vp)

require.NoError(t, err)
assert.Equal(t, []vc.VerifiableCredential{credential1}, credentials)
assert.Equal(t, map[string]vc.VerifiableCredential{"1": credential1, "2": credential1}, credentials)
})
t.Run("no input descriptors", func(t *testing.T) {
vp := vc.VerifiablePresentation{
Expand Down Expand Up @@ -204,7 +198,22 @@ func TestPresentationSubmission_Credentials(t *testing.T) {

credentials, err := submission.Credentials(vp)

assert.EqualError(t, err, "descriptor '1' evaluates to an invalid VC in the VP: json: cannot unmarshal string into Go value of type map[string]interface {}")
assert.ErrorContains(t, err, "descriptor '1' evaluates to an invalid VC in the VP")
assert.Empty(t, credentials)
})
}

func makeTestCredential(t *testing.T, id ssi.URI) vc.VerifiableCredential {
// Back and forth marshalling to make sure optional values are set,
// and because you can only compare VCs for equalness after they're parsed (since they have private fields)
jsonBytes, err := vc.VerifiableCredential{}.MarshalJSON()
require.NoError(t, err)
var credential vc.VerifiableCredential
err = json.Unmarshal(jsonBytes, &credential)
require.NoError(t, err)
credential.ID = &id
jsonBytes, _ = credential.MarshalJSON()
result, err := vc.ParseVerifiableCredential(string(jsonBytes))
require.NoError(t, err)
return *result
}

0 comments on commit 9129d70

Please sign in to comment.