mirror of
https://github.com/absmach/supermq.git
synced 2026-06-23 06:20:18 +00:00
NOISSUE - List domain invitations on SDK (#3038)
Continuous Delivery / Build and Push (push) Has been cancelled
Check the consistency of generated files / check-generated-files (push) Has been cancelled
Check License Header / check-license (push) Has been cancelled
Deploy GitHub Pages / swagger-ui (push) Has been cancelled
Continuous Delivery / Build and Push (push) Has been cancelled
Check the consistency of generated files / check-generated-files (push) Has been cancelled
Check License Header / check-license (push) Has been cancelled
Deploy GitHub Pages / swagger-ui (push) Has been cancelled
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
This commit is contained in:
committed by
GitHub
parent
9b77130f6e
commit
f4417ecb78
@@ -218,7 +218,7 @@ func TestCreateChannel(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = smqauthn.Session{DomainUserID: domainID + "_" + validID, UserID: validID, DomainID: domainID}
|
||||
tc.session = smqauthn.Session{DomainUserID: fmt.Sprintf("%s_%s", domainID, validID), UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := gsvc.On("CreateChannels", mock.Anything, tc.session, []channels.Channel{tc.createChannelReq}).Return(tc.svcRes, []roles.RoleProvision{}, tc.svcErr)
|
||||
@@ -339,7 +339,7 @@ func TestCreateChannels(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = smqauthn.Session{DomainUserID: domainID + "_" + validID, UserID: validID, DomainID: domainID}
|
||||
tc.session = smqauthn.Session{DomainUserID: fmt.Sprintf("%s_%s", domainID, validID), UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := gsvc.On("CreateChannels", mock.Anything, tc.session, tc.createChannelsReq).Return(tc.svcRes, []roles.RoleProvision{}, tc.svcErr)
|
||||
|
||||
+26
-5
@@ -6,6 +6,7 @@ package sdk
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -46,7 +47,7 @@ func (sdk mgSDK) SendInvitation(ctx context.Context, invitation Invitation, toke
|
||||
return errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := sdk.domainsURL + "/" + domainsEndpoint + "/" + invitation.DomainID + "/" + invitationsEndpoint
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.domainsURL, domainsEndpoint, invitation.DomainID, invitationsEndpoint)
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(ctx, http.MethodPost, url, token, data, nil, http.StatusCreated)
|
||||
|
||||
@@ -54,7 +55,7 @@ func (sdk mgSDK) SendInvitation(ctx context.Context, invitation Invitation, toke
|
||||
}
|
||||
|
||||
func (sdk mgSDK) Invitation(ctx context.Context, userID, domainID, token string) (invitation Invitation, err error) {
|
||||
url := sdk.domainsURL + "/" + domainsEndpoint + "/" + domainID + "/" + invitationsEndpoint + "/" + userID
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s", sdk.domainsURL, domainsEndpoint, domainID, invitationsEndpoint, userID)
|
||||
|
||||
_, body, sdkerr := sdk.processRequest(ctx, http.MethodGet, url, token, nil, nil, http.StatusOK)
|
||||
if sdkerr != nil {
|
||||
@@ -68,6 +69,26 @@ func (sdk mgSDK) Invitation(ctx context.Context, userID, domainID, token string)
|
||||
return invitation, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) DomainInvitations(ctx context.Context, pm PageMetadata, token, domainID string) (invitations InvitationPage, err error) {
|
||||
url := fmt.Sprintf("%s/%s/%s", domainsEndpoint, domainID, invitationsEndpoint)
|
||||
url, err = sdk.withQueryParams(sdk.domainsURL, url, pm)
|
||||
if err != nil {
|
||||
return InvitationPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
_, body, sdkerr := sdk.processRequest(ctx, http.MethodGet, url, token, nil, nil, http.StatusOK)
|
||||
if sdkerr != nil {
|
||||
return InvitationPage{}, sdkerr
|
||||
}
|
||||
|
||||
var invPage InvitationPage
|
||||
if err := json.Unmarshal(body, &invPage); err != nil {
|
||||
return InvitationPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
return invPage, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) Invitations(ctx context.Context, pm PageMetadata, token string) (invitations InvitationPage, err error) {
|
||||
url, err := sdk.withQueryParams(sdk.domainsURL, invitationsEndpoint, pm)
|
||||
if err != nil {
|
||||
@@ -98,7 +119,7 @@ func (sdk mgSDK) AcceptInvitation(ctx context.Context, domainID, token string) (
|
||||
return errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := sdk.domainsURL + "/" + invitationsEndpoint + "/" + acceptEndpoint
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.domainsURL, invitationsEndpoint, acceptEndpoint)
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(ctx, http.MethodPost, url, token, data, nil, http.StatusNoContent)
|
||||
|
||||
@@ -116,7 +137,7 @@ func (sdk mgSDK) RejectInvitation(ctx context.Context, domainID, token string) (
|
||||
return errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := sdk.domainsURL + "/" + invitationsEndpoint + "/" + rejectEndpoint
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.domainsURL, invitationsEndpoint, rejectEndpoint)
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(ctx, http.MethodPost, url, token, data, nil, http.StatusNoContent)
|
||||
|
||||
@@ -124,7 +145,7 @@ func (sdk mgSDK) RejectInvitation(ctx context.Context, domainID, token string) (
|
||||
}
|
||||
|
||||
func (sdk mgSDK) DeleteInvitation(ctx context.Context, userID, domainID, token string) (err error) {
|
||||
url := sdk.domainsURL + "/" + domainsEndpoint + "/" + domainID + "/" + invitationsEndpoint + "/" + userID
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s", sdk.domainsURL, domainsEndpoint, domainID, invitationsEndpoint, userID)
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(ctx, http.MethodDelete, url, token, nil, nil, http.StatusNoContent)
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ func TestSendInvitation(t *testing.T) {
|
||||
tc.session = smqauthn.Session{
|
||||
UserID: tc.sendInvitationReq.InviteeUserID,
|
||||
DomainID: tc.sendInvitationReq.DomainID,
|
||||
DomainUserID: tc.sendInvitationReq.DomainID + "_" + tc.sendInvitationReq.InviteeUserID,
|
||||
DomainUserID: fmt.Sprintf("%s_%s", tc.sendInvitationReq.DomainID, tc.sendInvitationReq.InviteeUserID),
|
||||
}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
@@ -214,7 +214,7 @@ func TestViewInvitation(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == valid {
|
||||
tc.session = smqauthn.Session{UserID: tc.userID, DomainID: tc.domainID, DomainUserID: tc.domainID + "_" + tc.userID}
|
||||
tc.session = smqauthn.Session{UserID: tc.userID, DomainID: tc.domainID, DomainUserID: fmt.Sprintf("%s_%s", tc.domainID, tc.userID)}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("ViewInvitation", mock.Anything, tc.session, tc.userID, tc.domainID).Return(tc.svcRes, tc.svcErr)
|
||||
@@ -528,7 +528,7 @@ func TestDeleteInvitation(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == valid {
|
||||
tc.session = smqauthn.Session{UserID: tc.inviteeUserID, DomainID: tc.domainID, DomainUserID: tc.domainID + "_" + tc.inviteeUserID}
|
||||
tc.session = smqauthn.Session{UserID: tc.inviteeUserID, DomainID: tc.domainID, DomainUserID: fmt.Sprintf("%s_%s", tc.domainID, tc.inviteeUserID)}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("DeleteInvitation", mock.Anything, tc.session, tc.inviteeUserID, tc.domainID).Return(tc.svcErr)
|
||||
|
||||
@@ -330,7 +330,7 @@ func TestRetrieveJournal(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = smqauthn.Session{DomainUserID: domainID + "_" + validID, UserID: validID, DomainID: domainID}
|
||||
tc.session = smqauthn.Session{DomainUserID: fmt.Sprintf("%s_%s", domainID, validID), UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := authn.On("Authenticate", mock.Anything, mock.Anything).Return(tc.session, tc.authnErr)
|
||||
svcCall := svc.On("RetrieveAll", mock.Anything, tc.session, tc.svcReq).Return(tc.svcRes, tc.svcErr)
|
||||
|
||||
@@ -3920,6 +3920,84 @@ func (_c *SDK_Domain_Call) RunAndReturn(run func(ctx context.Context, domainID s
|
||||
return _c
|
||||
}
|
||||
|
||||
// DomainInvitations provides a mock function for the type SDK
|
||||
func (_mock *SDK) DomainInvitations(ctx context.Context, pm sdk.PageMetadata, token string, domainID string) (sdk.InvitationPage, error) {
|
||||
ret := _mock.Called(ctx, pm, token, domainID)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for DomainInvitations")
|
||||
}
|
||||
|
||||
var r0 sdk.InvitationPage
|
||||
var r1 error
|
||||
if returnFunc, ok := ret.Get(0).(func(context.Context, sdk.PageMetadata, string, string) (sdk.InvitationPage, error)); ok {
|
||||
return returnFunc(ctx, pm, token, domainID)
|
||||
}
|
||||
if returnFunc, ok := ret.Get(0).(func(context.Context, sdk.PageMetadata, string, string) sdk.InvitationPage); ok {
|
||||
r0 = returnFunc(ctx, pm, token, domainID)
|
||||
} else {
|
||||
r0 = ret.Get(0).(sdk.InvitationPage)
|
||||
}
|
||||
if returnFunc, ok := ret.Get(1).(func(context.Context, sdk.PageMetadata, string, string) error); ok {
|
||||
r1 = returnFunc(ctx, pm, token, domainID)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// SDK_DomainInvitations_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DomainInvitations'
|
||||
type SDK_DomainInvitations_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// DomainInvitations is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - pm sdk.PageMetadata
|
||||
// - token string
|
||||
// - domainID string
|
||||
func (_e *SDK_Expecter) DomainInvitations(ctx interface{}, pm interface{}, token interface{}, domainID interface{}) *SDK_DomainInvitations_Call {
|
||||
return &SDK_DomainInvitations_Call{Call: _e.mock.On("DomainInvitations", ctx, pm, token, domainID)}
|
||||
}
|
||||
|
||||
func (_c *SDK_DomainInvitations_Call) Run(run func(ctx context.Context, pm sdk.PageMetadata, token string, domainID string)) *SDK_DomainInvitations_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
var arg0 context.Context
|
||||
if args[0] != nil {
|
||||
arg0 = args[0].(context.Context)
|
||||
}
|
||||
var arg1 sdk.PageMetadata
|
||||
if args[1] != nil {
|
||||
arg1 = args[1].(sdk.PageMetadata)
|
||||
}
|
||||
var arg2 string
|
||||
if args[2] != nil {
|
||||
arg2 = args[2].(string)
|
||||
}
|
||||
var arg3 string
|
||||
if args[3] != nil {
|
||||
arg3 = args[3].(string)
|
||||
}
|
||||
run(
|
||||
arg0,
|
||||
arg1,
|
||||
arg2,
|
||||
arg3,
|
||||
)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *SDK_DomainInvitations_Call) Return(invitations sdk.InvitationPage, err error) *SDK_DomainInvitations_Call {
|
||||
_c.Call.Return(invitations, err)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *SDK_DomainInvitations_Call) RunAndReturn(run func(ctx context.Context, pm sdk.PageMetadata, token string, domainID string) (sdk.InvitationPage, error)) *SDK_DomainInvitations_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// DomainRole provides a mock function for the type SDK
|
||||
func (_mock *SDK) DomainRole(ctx context.Context, id string, roleID string, token string) (sdk.Role, errors.SDKError) {
|
||||
ret := _mock.Called(ctx, id, roleID, token)
|
||||
|
||||
+12
-2
@@ -1326,6 +1326,16 @@ type SDK interface {
|
||||
// journals, _ := sdk.Journal("client", "clientID","domainID", PageMetadata{Offset: 0, Limit: 10, Operation: "client.create"}, "token")
|
||||
// fmt.Println(journals)
|
||||
Journal(ctx context.Context, entityType, entityID, domainID string, pm PageMetadata, token string) (journal JournalsPage, err error)
|
||||
|
||||
// DomainInvitations returns a list of invitations for a specific domain.
|
||||
// For example:
|
||||
// pm := sdk.PageMetadata{
|
||||
// Offset: 0,
|
||||
// Limit: 10,
|
||||
// }
|
||||
// invitations, _ := sdk.DomainInvitations("domainID", pm, "token")
|
||||
// fmt.Println(invitations)
|
||||
DomainInvitations(ctx context.Context, pm PageMetadata, token, domainID string) (invitations InvitationPage, err error)
|
||||
}
|
||||
|
||||
type mgSDK struct {
|
||||
@@ -1391,7 +1401,7 @@ func NewSDK(conf Config) SDK {
|
||||
// It then returns the response headers, the response body, and the associated error(s) (if any).
|
||||
func (sdk mgSDK) processRequest(ctx context.Context, method, reqUrl, token string, data []byte, headers map[string]string, expectedRespCodes ...int) (http.Header, []byte, errors.SDKError) {
|
||||
if sdk.roles {
|
||||
reqUrl = reqUrl + fmt.Sprintf("?roles=%v", true)
|
||||
reqUrl = fmt.Sprintf("%s?roles=%v", reqUrl, true)
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, method, reqUrl, bytes.NewReader(data))
|
||||
if err != nil {
|
||||
@@ -1408,7 +1418,7 @@ func (sdk mgSDK) processRequest(ctx context.Context, method, reqUrl, token strin
|
||||
|
||||
if token != "" {
|
||||
if !strings.Contains(token, ClientPrefix) {
|
||||
token = BearerPrefix + token
|
||||
token = fmt.Sprintf("%s%s", BearerPrefix, token)
|
||||
}
|
||||
req.Header.Set("Authorization", token)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user