amocrm/pkg/amoClient/amo_test.go

72 lines
2.7 KiB
Go
Raw Normal View History

package amoClient
import (
2024-04-17 12:21:06 +00:00
"amocrm/internal/models"
"encoding/json"
"fmt"
"github.com/gofiber/fiber/v2"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"testing"
)
func Test_CreateWebhook(t *testing.T) {
cfgLogger := zap.NewDevelopmentConfig()
cfgLogger.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
cfgLogger.EncoderConfig.ConsoleSeparator = " "
logger, err := cfgLogger.Build()
if err != nil {
fmt.Println(err)
}
amoclient := NewAmoClient(AmoDeps{
BaseApiURL: "BaseApiURL",
Logger: logger,
RedirectionURL: "RedirectionURL",
IntegrationID: "IntegrationID",
IntegrationSecret: "IntegrationSecret",
})
2024-04-17 12:21:06 +00:00
req1 := models.UpdateWebHookReq{
GrantType: "refresh_token",
RefreshToken: "refresh_token",
}
2024-04-17 12:21:06 +00:00
req2 := models.CreateWebHookReq{
GrantType: "authorization_code",
Code: "Code",
}
_, _ = amoclient.CreateWebHook(&req1)
_, _ = amoclient.CreateWebHook(&req2)
}
func Test_CustomersMode(t *testing.T) {
fiberClient := fiber.AcquireClient()
uri := fmt.Sprint("https://penadigitaltech.amocrm.ru/api/v4/customers/mode")
bodyBytes, err := json.Marshal(struct {
Mode string `json:"mode"`
ISenabled bool `json:"is_enabled"`
}{
Mode: "segments",
ISenabled: true,
})
if err != nil {
fmt.Println(err)
}
agent := fiberClient.Patch(uri)
agent.Set("Content-Type", "application/json").Body(bodyBytes)
agent.Set("Authorization", "Bearer "+"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjFkMmZlNjFlMjFkZGZjOGRmN2MyNWRhYjc3MTJkMDM5MDVhZWEwYzkyYjJmZTU0Njc4OTgzYmUzM2Q0NWExYjQ2YmI1ZDY2MjJkNDA2Y2ZjIn0.eyJhdWQiOiIyZGJkNjMyOS05YmU2LTQxZjItYWE1Zi05NjRiOWU3MjNlNDkiLCJqdGkiOiIxZDJmZTYxZTIxZGRmYzhkZjdjMjVkYWI3NzEyZDAzOTA1YWVhMGM5MmIyZmU1NDY3ODk4M2JlMzNkNDVhMWI0NmJiNWQ2NjIyZDQwNmNmYyIsImlhdCI6MTcxNDY0NDA3OSwibmJmIjoxNzE0NjQ0MDc5LCJleHAiOjE3MTQ3MzA0NzksInN1YiI6IjgxMTA3MjYiLCJncmFudF90eXBlIjoiIiwiYWNjb3VudF9pZCI6MzAyMjg5OTcsImJhc2VfZG9tYWluIjoiYW1vY3JtLnJ1IiwidmVyc2lvbiI6Miwic2NvcGVzIjpbInB1c2hfbm90aWZpY2F0aW9ucyIsImNybSIsIm5vdGlmaWNhdGlvbnMiXSwiaGFzaF91dWlkIjoiZWUyNjFjMDgtOGZiMC00NTkzLTlmNmQtOWVhNDFhZTljNTJhIn0.qUaJwH95LnU3xMA4GMQ0wtK1_vA_bMM8kd5BlRYNpL6ohEhl4CPk8EdR0qXmtBonsh4Z2kwXXAcPtiysZ6XA4kO1JLrgMN3cxthwEO2Z3UxI5O0L5W3DJvCco_4PCbRgUZWxlrR48NxmZ_bWkrhQb07txygvOOhB2T6lpX2CnkDPlS914jYP9QT8BBREEkERbr1zehVSt4NCCXNSC_Tnj9uXOj5GeYnm2Sw5OUXKEJspmDKEOoX4m_FKwlg3ywQfbWKDemVQYuHgmaPalDLLnAC8iydE50NLol07pQvhkK8zOjgz_zif7vENFH4152P9-ltFEvJVmwyqoN23Xuo7Aw")
statusCode, resBody, errs := agent.Bytes()
if len(errs) > 0 {
fmt.Printf("request failed: %v", errs[0])
}
if statusCode != fiber.StatusOK {
errorMessage := fmt.Sprintf("received an incorrect response from AddLeadsFields: %s", string(resBody))
fmt.Println(errorMessage)
}
fmt.Println(string(resBody))
}