mirror of
https://github.com/retailcrm/api-client-go.git
synced 2025-04-02 20:56:17 +03:00
correct implementation for update-scopes method
This commit is contained in:
parent
1309825638
commit
ce57e6fe9d
3 changed files with 14 additions and 14 deletions
|
@ -2171,13 +2171,16 @@ func (c *Client) IntegrationModuleEdit(integrationModule IntegrationModule) (
|
|||
// if data.Success == true {
|
||||
// fmt.Printf("%v\n", data.APIKey)
|
||||
// }
|
||||
func (c *Client) UpdateScopes(code string, request UpdateScopesRequest) (UpdateScopesResponse, int, error) {
|
||||
func (c *Client) UpdateScopes(code string, request ScopesRequired) (UpdateScopesResponse, int, error) {
|
||||
var resp UpdateScopesResponse
|
||||
updateJSON, _ := json.Marshal(&request)
|
||||
|
||||
p := url.Values{
|
||||
"requires": {string(updateJSON)},
|
||||
}
|
||||
|
||||
data, status, err := c.PostRequest(
|
||||
fmt.Sprintf("/integration-modules/%s/update-scopes", code),
|
||||
bytes.NewBuffer(updateJSON))
|
||||
fmt.Sprintf("/integration-modules/%s/update-scopes", code), p)
|
||||
if err != nil {
|
||||
return resp, status, err
|
||||
}
|
||||
|
|
|
@ -6572,13 +6572,14 @@ func TestClient_UpdateScopes(t *testing.T) {
|
|||
|
||||
defer gock.Off()
|
||||
|
||||
request := UpdateScopesRequest{Requires: ScopesRequired{Scopes: []string{"scope1", "scope2"}}}
|
||||
|
||||
request := ScopesRequired{Scopes: []string{"scope1", "scope2"}}
|
||||
jr, _ := json.Marshal(&request)
|
||||
|
||||
gock.New(crmURL).
|
||||
Post(fmt.Sprintf("/integration-modules/%s/update-scopes", code)).
|
||||
BodyString(string(jr[:])).
|
||||
BodyString((url.Values{
|
||||
"requires": {string(jr)},
|
||||
}).Encode()).
|
||||
Reply(200).
|
||||
BodyString(`{"success": true, "apiKey": "newApiKey"}`)
|
||||
|
||||
|
@ -6603,13 +6604,14 @@ func TestClient_UpdateScopes_Fail(t *testing.T) {
|
|||
|
||||
defer gock.Off()
|
||||
|
||||
request := UpdateScopesRequest{Requires: ScopesRequired{Scopes: []string{"scope1", "scope2"}}}
|
||||
|
||||
request := ScopesRequired{Scopes: []string{"scope1", "scope2"}}
|
||||
jr, _ := json.Marshal(&request)
|
||||
|
||||
gock.New(crmURL).
|
||||
Post(fmt.Sprintf("/integration-modules/%s/update-scopes", code)).
|
||||
BodyString(string(jr[:])).
|
||||
BodyString((url.Values{
|
||||
"requires": {string(jr)},
|
||||
}).Encode()).
|
||||
Reply(400).
|
||||
BodyString(`{"success": false, "errorMsg": "Not enabled simple connection"}`)
|
||||
|
||||
|
|
5
types.go
5
types.go
|
@ -976,11 +976,6 @@ type IntegrationModule struct {
|
|||
Integrations *Integrations `json:"integrations,omitempty"`
|
||||
}
|
||||
|
||||
// UpdateScopesRequest type.
|
||||
type UpdateScopesRequest struct {
|
||||
Requires ScopesRequired `json:"requires"`
|
||||
}
|
||||
|
||||
type ScopesRequired struct {
|
||||
Scopes []string
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue