Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul committed Jan 8, 2024
1 parent dee1924 commit 0478cd6
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
70 changes: 70 additions & 0 deletions discovery/api/v1/wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package v1

import (
"errors"
"github.com/nuts-foundation/go-did/did"
"github.com/nuts-foundation/go-did/vc"
"github.com/nuts-foundation/nuts-node/discovery"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -102,6 +103,75 @@ func TestWrapper_RegisterPresentation(t *testing.T) {
})
}

func TestWrapper_StartRegisteringPresentation(t *testing.T) {
t.Run("ok", func(t *testing.T) {
test := newMockContext(t)
expectedDID := "did:web:example.com"
test.client.EXPECT().StartRegistration(gomock.Any(), serviceID, did.MustParseDID(expectedDID)).Return(nil)

response, err := test.wrapper.StartRegisteringPresentation(nil, StartRegisteringPresentationRequestObject{
ServiceID: serviceID,
Did: expectedDID,
})

assert.NoError(t, err)
assert.IsType(t, StartRegisteringPresentation200Response{}, response)
})
t.Run("ok, but registration failed", func(t *testing.T) {
test := newMockContext(t)
expectedDID := "did:web:example.com"
test.client.EXPECT().StartRegistration(gomock.Any(), gomock.Any(), gomock.Any()).Return(discovery.ErrRegistrationFailed)

response, err := test.wrapper.StartRegisteringPresentation(nil, StartRegisteringPresentationRequestObject{
ServiceID: serviceID,
Did: expectedDID,
})

assert.NoError(t, err)
assert.IsType(t, StartRegisteringPresentation202JSONResponse{}, response)
})
t.Run("other error", func(t *testing.T) {
test := newMockContext(t)
expectedDID := "did:web:example.com"
test.client.EXPECT().StartRegistration(gomock.Any(), gomock.Any(), gomock.Any()).Return(errors.New("foo"))

_, err := test.wrapper.StartRegisteringPresentation(nil, StartRegisteringPresentationRequestObject{
ServiceID: serviceID,
Did: expectedDID,
})

assert.Error(t, err)
})
}

func TestWrapper_StopRegisteringPresentation(t *testing.T) {
t.Run("ok", func(t *testing.T) {
test := newMockContext(t)
expectedDID := "did:web:example.com"
test.client.EXPECT().StopRegistration(gomock.Any(), serviceID, did.MustParseDID(expectedDID)).Return(nil)

response, err := test.wrapper.StopRegisteringPresentation(nil, StopRegisteringPresentationRequestObject{
ServiceID: serviceID,
Did: expectedDID,
})

assert.NoError(t, err)
assert.IsType(t, StopRegisteringPresentation200Response{}, response)
})
t.Run("error", func(t *testing.T) {
test := newMockContext(t)
expectedDID := "did:web:example.com"
test.client.EXPECT().StopRegistration(gomock.Any(), serviceID, did.MustParseDID(expectedDID)).Return(errors.New("foo"))

_, err := test.wrapper.StopRegisteringPresentation(nil, StopRegisteringPresentationRequestObject{
ServiceID: serviceID,
Did: expectedDID,
})

assert.Error(t, err)
})
}

func TestWrapper_ResolveStatusCode(t *testing.T) {
expected := map[error]int{
discovery.ErrServerModeDisabled: http.StatusBadRequest,
Expand Down
5 changes: 0 additions & 5 deletions discovery/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,3 @@ func DefaultConfig() Config {
},
}
}

// IsServer returns true if the node act as Discovery Server.
func (c Config) IsServer() bool {
return len(c.Server.DefinitionIDs) > 0
}
10 changes: 10 additions & 0 deletions discovery/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package discovery

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestDefaultConfig(t *testing.T) {
assert.NotEmpty(t, DefaultConfig().Client.RegistrationRefreshInterval)
}

0 comments on commit 0478cd6

Please sign in to comment.