Skip to content

Commit

Permalink
test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul committed Dec 11, 2023
1 parent 06b48b6 commit b7ab286
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions discovery/api/v1/wapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
package v1

import (
"errors"
"github.com/nuts-foundation/go-did/vc"
"github.com/nuts-foundation/nuts-node/discovery"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
"net/http"
"testing"
)

Expand Down Expand Up @@ -62,6 +64,14 @@ func TestWrapper_GetPresentations(t *testing.T) {
assert.Equal(t, latestTag, discovery.Tag(response.(GetPresentations200JSONResponse).Tag))
assert.Equal(t, presentations, response.(GetPresentations200JSONResponse).Entries)
})
t.Run("error", func(t *testing.T) {
test := newMockContext(t)
test.server.EXPECT().Get(serviceID, nil).Return(nil, nil, errors.New("foo"))

_, err := test.wrapper.GetPresentations(nil, GetPresentationsRequestObject{ServiceID: serviceID})

assert.Error(t, err)
})
}

func TestWrapper_RegisterPresentation(t *testing.T) {
Expand Down Expand Up @@ -92,6 +102,20 @@ func TestWrapper_RegisterPresentation(t *testing.T) {
})
}

func TestWrapper_ResolveStatusCode(t *testing.T) {
expected := map[error]int{
discovery.ErrServerModeDisabled: http.StatusBadRequest,
discovery.ErrInvalidPresentation: http.StatusBadRequest,
errors.New("foo"): http.StatusInternalServerError,
}
wrapper := Wrapper{}
for err, expectedCode := range expected {
t.Run(err.Error(), func(t *testing.T) {
assert.Equal(t, expectedCode, wrapper.ResolveStatusCode(err))
})
}
}

type mockContext struct {
ctrl *gomock.Controller
server *discovery.MockServer
Expand Down

0 comments on commit b7ab286

Please sign in to comment.