Skip to content

Commit

Permalink
fix(notifiers): wrap with create entity error
Browse files Browse the repository at this point in the history
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
  • Loading branch information
rodneyosodo committed Jun 12, 2024
1 parent a6252c3 commit 544c3b0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion certs/api/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"github.com/absmach/magistrala/certs"
httpapi "github.com/absmach/magistrala/certs/api"
"github.com/absmach/magistrala/certs/mocks"
"github.com/absmach/magistrala/internal/apiutil"
"github.com/absmach/magistrala/internal/testsutil"
mglog "github.com/absmach/magistrala/logger"
"github.com/absmach/magistrala/pkg/apiutil"
"github.com/absmach/magistrala/pkg/errors"
svcerr "github.com/absmach/magistrala/pkg/errors/service"
"github.com/stretchr/testify/assert"
Expand Down
7 changes: 6 additions & 1 deletion consumers/notifiers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/absmach/magistrala"
"github.com/absmach/magistrala/consumers"
"github.com/absmach/magistrala/pkg/errors"
svcerr "github.com/absmach/magistrala/pkg/errors/service"
"github.com/absmach/magistrala/pkg/messaging"
)

Expand Down Expand Up @@ -72,7 +73,11 @@ func (ns *notifierService) CreateSubscription(ctx context.Context, token string,
}

sub.OwnerID = res.GetId()
return ns.subs.Save(ctx, sub)
id, err := ns.subs.Save(ctx, sub)
if err != nil {
return "", errors.Wrap(svcerr.ErrCreateEntity, err)
}
return id, nil
}

func (ns *notifierService) ViewSubscription(ctx context.Context, token, id string) (Subscription, error) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/auth/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"github.com/absmach/magistrala"
authgrpcapi "github.com/absmach/magistrala/auth/api/grpc"
"github.com/absmach/magistrala/auth/mocks"
"github.com/absmach/magistrala/internal/server"
grpcserver "github.com/absmach/magistrala/internal/server/grpc"
mglog "github.com/absmach/magistrala/logger"
"github.com/absmach/magistrala/pkg/auth"
"github.com/absmach/magistrala/pkg/errors"
"github.com/absmach/magistrala/pkg/server"
grpcserver "github.com/absmach/magistrala/pkg/server/grpc"
thingsgrpcapi "github.com/absmach/magistrala/things/api/grpc"
thmocks "github.com/absmach/magistrala/things/mocks"
"github.com/stretchr/testify/assert"
Expand All @@ -29,7 +29,7 @@ func TestSetupAuth(t *testing.T) {
registerAuthServiceServer := func(srv *grpc.Server) {
magistrala.RegisterAuthServiceServer(srv, authgrpcapi.NewServer(new(mocks.Service)))
}
gs := grpcserver.New(ctx, cancel, "auth", server.Config{Port: "12345"}, registerAuthServiceServer, mglog.NewMock())
gs := grpcserver.NewServer(ctx, cancel, "auth", server.Config{Port: "12345"}, registerAuthServiceServer, mglog.NewMock())
go func() {
err := gs.Start()
assert.Nil(t, err, fmt.Sprintf(`"Unexpected error creating server %s"`, err))
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestSetupAuthz(t *testing.T) {
registerAuthaServiceServer := func(srv *grpc.Server) {
magistrala.RegisterAuthzServiceServer(srv, thingsgrpcapi.NewServer(new(thmocks.Service)))
}
gs := grpcserver.New(ctx, cancel, "things", server.Config{Port: "12345"}, registerAuthaServiceServer, mglog.NewMock())
gs := grpcserver.NewServer(ctx, cancel, "things", server.Config{Port: "12345"}, registerAuthaServiceServer, mglog.NewMock())
go func() {
err := gs.Start()
assert.Nil(t, err, fmt.Sprintf(`"Unexpected error creating server %s"`, err))
Expand Down

0 comments on commit 544c3b0

Please sign in to comment.