Skip to content

Commit

Permalink
Removed the indentifier response
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <[email protected]>
  • Loading branch information
nyagamunene committed Apr 22, 2024
1 parent b8a2968 commit e27b595
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
36 changes: 18 additions & 18 deletions consumers/notifiers/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestCreateSubscription(t *testing.T) {
id string
err error
identifyErr error
identityRes *magistrala.IdentityRes
userID string
}{
{
desc: "test success",
Expand All @@ -57,7 +57,7 @@ func TestCreateSubscription(t *testing.T) {
id: uuid.Prefix + fmt.Sprintf("%012d", 1),
err: nil,
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
{
desc: "test already existing",
Expand All @@ -66,7 +66,7 @@ func TestCreateSubscription(t *testing.T) {
id: "",
err: repoerr.ErrConflict,
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
{
desc: "test with empty token",
Expand All @@ -79,7 +79,7 @@ func TestCreateSubscription(t *testing.T) {
}

for _, tc := range cases {
repoCall := auth.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.identityRes, tc.identifyErr)
repoCall := auth.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.userID}, tc.identifyErr)
repoCall1 := repo.On("Save", context.Background(), mock.Anything).Return(tc.id, tc.err)
id, err := svc.CreateSubscription(context.Background(), tc.token, tc.sub)
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
Expand All @@ -105,7 +105,7 @@ func TestViewSubscription(t *testing.T) {
sub notifiers.Subscription
err error
identifyErr error
identityRes *magistrala.IdentityRes
userID string
}{
{
desc: "test success",
Expand All @@ -114,7 +114,7 @@ func TestViewSubscription(t *testing.T) {
sub: sub,
err: nil,
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
{
desc: "test not existing",
Expand All @@ -123,7 +123,7 @@ func TestViewSubscription(t *testing.T) {
sub: notifiers.Subscription{},
err: svcerr.ErrNotFound,
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
{
desc: "test with empty token",
Expand All @@ -136,7 +136,7 @@ func TestViewSubscription(t *testing.T) {
}

for _, tc := range cases {
repoCall := auth.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.identityRes, tc.identifyErr)
repoCall := auth.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.userID}, tc.identifyErr)
repoCall1 := repo.On("Retrieve", context.Background(), tc.id).Return(tc.sub, tc.err)
sub, err := svc.ViewSubscription(context.Background(), tc.token, tc.id)
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestListSubscriptions(t *testing.T) {
page notifiers.Page
err error
identifyErr error
identityRes *magistrala.IdentityRes
userID string
}{
{
desc: "test success",
Expand All @@ -194,7 +194,7 @@ func TestListSubscriptions(t *testing.T) {
Total: total,
},
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
{
desc: "test not existing",
Expand All @@ -206,7 +206,7 @@ func TestListSubscriptions(t *testing.T) {
page: notifiers.Page{},
err: svcerr.ErrNotFound,
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
{
desc: "test with empty token",
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestListSubscriptions(t *testing.T) {
},
err: nil,
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
{
desc: "test with contact and offset",
Expand All @@ -258,12 +258,12 @@ func TestListSubscriptions(t *testing.T) {
},
err: nil,
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
}

for _, tc := range cases {
repoCall := auth.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.identityRes, tc.identifyErr)
repoCall := auth.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.userID}, tc.identifyErr)
repoCall1 := repo.On("RetrieveAll", context.Background(), tc.pageMeta).Return(tc.page, tc.err)
page, err := svc.ListSubscriptions(context.Background(), tc.token, tc.pageMeta)
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
Expand All @@ -288,23 +288,23 @@ func TestRemoveSubscription(t *testing.T) {
id string
err error
identifyErr error
identityRes *magistrala.IdentityRes
userID string
}{
{
desc: "test success",
token: exampleUser1,
id: sub.ID,
err: nil,
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
{
desc: "test not existing",
token: exampleUser1,
id: "not_exist",
err: svcerr.ErrNotFound,
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
{
desc: "test with empty token",
Expand All @@ -316,7 +316,7 @@ func TestRemoveSubscription(t *testing.T) {
}

for _, tc := range cases {
repoCall := auth.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.identityRes, tc.identifyErr)
repoCall := auth.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.userID}, tc.identifyErr)
repoCall1 := repo.On("Remove", context.Background(), tc.id).Return(tc.err)
err := svc.RemoveSubscription(context.Background(), tc.token, tc.id)
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
Expand Down
36 changes: 17 additions & 19 deletions pkg/sdk/go/consumers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestCreateSubscription(t *testing.T) {
empty bool
id string
identifyErr error
identityRes *magistrala.IdentityRes
userID string
}{
{
desc: "create new subscription",
Expand All @@ -79,7 +79,7 @@ func TestCreateSubscription(t *testing.T) {
empty: false,
id: ID,
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
{
desc: "create new subscription with empty token",
Expand All @@ -89,7 +89,6 @@ func TestCreateSubscription(t *testing.T) {
empty: true,
id: "",
identifyErr: svcerr.ErrAuthorization,
identityRes: nil,
},
{
desc: "create new subscription with invalid token",
Expand All @@ -99,7 +98,6 @@ func TestCreateSubscription(t *testing.T) {
empty: true,
id: "",
identifyErr: svcerr.ErrAuthorization,
identityRes: nil,
},
{
desc: "create new empty subscription",
Expand All @@ -109,12 +107,12 @@ func TestCreateSubscription(t *testing.T) {
empty: true,
id: "",
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
}

for _, tc := range cases {
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(tc.identityRes, tc.identifyErr)
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.userID}, tc.identifyErr)
repoCall1 := repo.On("Save", mock.Anything, mock.Anything).Return(tc.id, tc.err)
loc, err := mgsdk.CreateSubscription(tc.subscription.Topic, tc.subscription.Contact, tc.token)
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected error %s, got %s", tc.desc, tc.err, err))
Expand Down Expand Up @@ -142,7 +140,7 @@ func TestViewSubscription(t *testing.T) {
err errors.SDKError
response sdk.Subscription
identifyErr error
identityRes *magistrala.IdentityRes
userID string
}{
{
desc: "get existing subscription",
Expand All @@ -151,7 +149,7 @@ func TestViewSubscription(t *testing.T) {
err: nil,
response: sub1,
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
{
desc: "get non-existent subscription",
Expand All @@ -160,7 +158,7 @@ func TestViewSubscription(t *testing.T) {
err: errors.NewSDKErrorWithStatus(svcerr.ErrNotFound, http.StatusNotFound),
response: sdk.Subscription{},
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
{
desc: "get subscription with invalid token",
Expand All @@ -173,7 +171,7 @@ func TestViewSubscription(t *testing.T) {
}

for _, tc := range cases {
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(tc.identityRes, tc.identifyErr)
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.userID}, tc.identifyErr)
repoCall1 := repo.On("Retrieve", mock.Anything, mock.Anything).Return(notifiers.Subscription{Contact: sub1.Contact, Topic: sub1.Topic}, tc.err)
respSub, err := mgsdk.ViewSubscription(tc.subID, tc.token)
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected error %s, got %s", tc.desc, tc.err, err))
Expand Down Expand Up @@ -206,7 +204,7 @@ func TestListSubscription(t *testing.T) {
response []sdk.Subscription
Page notifiers.Page
identifyErr error
identityRes *magistrala.IdentityRes
userID string
}{
{
desc: "list all subscription",
Expand All @@ -222,7 +220,7 @@ func TestListSubscription(t *testing.T) {
Subscriptions: subSlice(subs, 0, 10),
},
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
{
desc: "list subscription with specific topic",
Expand All @@ -239,7 +237,7 @@ func TestListSubscription(t *testing.T) {
Subscriptions: subSlice(subs, 0, 1),
},
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
{
desc: "list subscription with specific contact",
Expand All @@ -256,12 +254,12 @@ func TestListSubscription(t *testing.T) {
Subscriptions: subSlice(subs, 0, 1),
},
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
}

for _, tc := range cases {
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(tc.identityRes, tc.identifyErr)
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.userID}, tc.identifyErr)
repoCall1 := repo.On("RetrieveAll", mock.Anything, mock.Anything).Return(tc.Page, tc.err)
subs, err := mgsdk.ListSubscriptions(tc.page, tc.token)
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected error %s, got %s", tc.desc, tc.err, err))
Expand Down Expand Up @@ -289,7 +287,7 @@ func TestDeleteSubscription(t *testing.T) {
err errors.SDKError
response sdk.Subscription
identifyErr error
identityRes *magistrala.IdentityRes
userID string
}{
{
desc: "delete existing subscription",
Expand All @@ -298,7 +296,7 @@ func TestDeleteSubscription(t *testing.T) {
err: nil,
response: sub1,
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
{
desc: "delete non-existent subscription",
Expand All @@ -307,7 +305,7 @@ func TestDeleteSubscription(t *testing.T) {
err: errors.NewSDKErrorWithStatus(svcerr.ErrNotFound, http.StatusNotFound),
response: sdk.Subscription{},
identifyErr: nil,
identityRes: &magistrala.IdentityRes{Id: validID},
userID: validID,
},
{
desc: "delete subscription with invalid token",
Expand All @@ -320,7 +318,7 @@ func TestDeleteSubscription(t *testing.T) {
}

for _, tc := range cases {
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(tc.identityRes, tc.err)
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.userID}, tc.err)
repoCall1 := repo.On("Remove", mock.Anything, mock.Anything).Return(tc.err)
err := mgsdk.DeleteSubscription(tc.subID, tc.token)
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected error %s, got %s", tc.desc, tc.err, err))
Expand Down

0 comments on commit e27b595

Please sign in to comment.