2024-09-20 14:41:33 +00:00
|
|
|
|
package bitrixClient
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"go.uber.org/zap"
|
2024-10-17 22:00:41 +00:00
|
|
|
|
"penahub.gitlab.yandexcloud.net/backend/quiz/bitrix/internal/models"
|
2024-09-20 14:41:33 +00:00
|
|
|
|
"penahub.gitlab.yandexcloud.net/backend/quiz/bitrix/internal/workers/limiter"
|
2024-10-20 12:42:00 +00:00
|
|
|
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
2024-09-20 14:41:33 +00:00
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestGetListFields(t *testing.T) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
lim := limiter.NewRateLimiter(ctx, 50, 2*time.Second)
|
|
|
|
|
logger := zap.NewNop()
|
|
|
|
|
b := NewBitrixClient(BitrixDeps{
|
|
|
|
|
Logger: logger,
|
|
|
|
|
RedirectionURL: "test",
|
|
|
|
|
IntegrationID: "test",
|
|
|
|
|
IntegrationSecret: "test",
|
|
|
|
|
RateLimiter: lim,
|
|
|
|
|
})
|
|
|
|
|
|
2024-09-29 14:57:21 +00:00
|
|
|
|
//result, err := b.GetUserList("262df9660000071b00717f9200000001000007c9148fd5a4211fc98142ea9bc41fc8d3", "b24-ld76ub.bitrix24.ru")
|
|
|
|
|
//if err != nil {
|
|
|
|
|
// t.Fatal(err)
|
|
|
|
|
//}
|
|
|
|
|
//fmt.Println(result)
|
|
|
|
|
|
|
|
|
|
//arr := []model.FieldsType{model.FieldTypeLead, model.FieldTypeCompany, model.FieldTypeContact, model.FieldTypeDeal}
|
2024-09-26 10:52:30 +00:00
|
|
|
|
//
|
|
|
|
|
//for i, tipe := range arr {
|
|
|
|
|
// req := models.AddFields{
|
|
|
|
|
// EditFormLabel: fmt.Sprintf("EditFormLabel %d", i),
|
|
|
|
|
// ListColumnLabel: fmt.Sprintf("ListColumnLabel %d", i),
|
|
|
|
|
// UserTypeID: "string",
|
|
|
|
|
// Settings: map[string]interface{}{
|
|
|
|
|
// "DEFAULT_VALUE": "GOGOGOGOGOGOGO!",
|
|
|
|
|
// }}
|
|
|
|
|
// req.GenFieldName()
|
|
|
|
|
// result, err := b.AddFields(req, tipe, "9c7cf1660000071b00717f9200000001000007b3c27dd12d61d2e90dd1e630638b8346", "b24-ld76ub.bitrix24.ru")
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// fmt.Println(err)
|
|
|
|
|
// }
|
|
|
|
|
// fmt.Println(result)
|
|
|
|
|
//}
|
|
|
|
|
//
|
2024-10-22 20:59:45 +00:00
|
|
|
|
fieldAnswer := make(map[string]string)
|
2024-10-24 15:19:27 +00:00
|
|
|
|
fieldAnswer["UF_CRM_1729778229491"] = "хуккккк"
|
2024-10-22 20:59:45 +00:00
|
|
|
|
|
2024-09-26 14:21:38 +00:00
|
|
|
|
//
|
|
|
|
|
//createContactReq := models.CreateContactReq{
|
|
|
|
|
// Fields: models.ContactFields{
|
|
|
|
|
// Name: "Контакт фром апи",
|
|
|
|
|
// SecondName: "SecondName",
|
|
|
|
|
// LastName: "LastName",
|
|
|
|
|
// Opened: "Y",
|
|
|
|
|
// LeadID: 1,
|
|
|
|
|
// UtmSource: "UtmSource",
|
|
|
|
|
// UtmMedium: "UtmMedium",
|
|
|
|
|
// UtmCampaign: "UtmCampaign",
|
|
|
|
|
// UtmContent: "UtmContent",
|
|
|
|
|
// UtmTerm: "UtmTerm",
|
|
|
|
|
// },
|
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
//reqMap := models.FormattingToMap(&createContactReq, fieldAnswer)
|
|
|
|
|
//
|
|
|
|
|
//contactResult, err := b.CreateContact(reqMap, "ad5df5660000071b00717f920000000100000783b6e19c671e64c3655e5c7aff197e14", "b24-ld76ub.bitrix24.ru")
|
|
|
|
|
//if err != nil {
|
|
|
|
|
// fmt.Println(err)
|
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
//createCompanyReq := models.CompanyReq{
|
|
|
|
|
// Fields: models.CompanyFields{
|
|
|
|
|
// Title: "TEST FORMATTER",
|
|
|
|
|
// Opened: "Y",
|
|
|
|
|
// LeadID: 1,
|
|
|
|
|
// UtmSource: "UtmSource",
|
|
|
|
|
// UtmMedium: "UtmMedium",
|
|
|
|
|
// UtmCampaign: "UtmCampaign",
|
|
|
|
|
// UtmContent: "UtmContent",
|
|
|
|
|
// UtmTerm: "UtmTerm",
|
|
|
|
|
// ContactID: contactResult,
|
|
|
|
|
// },
|
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
//reqMap = models.FormattingToMap(&createCompanyReq, fieldAnswer)
|
|
|
|
|
//companyResult, err := b.CreateCompany(reqMap, "ad5df5660000071b00717f920000000100000783b6e19c671e64c3655e5c7aff197e14", "b24-ld76ub.bitrix24.ru")
|
|
|
|
|
//if err != nil {
|
|
|
|
|
// fmt.Println(err)
|
|
|
|
|
//}
|
|
|
|
|
//
|
2024-10-22 20:59:45 +00:00
|
|
|
|
createDealReq := models.CreatingDealReq{
|
|
|
|
|
Fields: models.CreateDealFields{
|
|
|
|
|
Title: "ТЕСТ ОТ ГОУ АПИ 10/10",
|
|
|
|
|
TypeID: "SALE",
|
|
|
|
|
StageID: "NEW",
|
2024-10-23 09:21:14 +00:00
|
|
|
|
CompanyID: 383,
|
|
|
|
|
ContactIDs: []int32{235},
|
2024-10-22 20:59:45 +00:00
|
|
|
|
Opened: "Y",
|
|
|
|
|
AssignedByID: 1,
|
|
|
|
|
CategoryID: 1,
|
|
|
|
|
SourceID: "CALL",
|
|
|
|
|
UtmSource: "UtmSource",
|
|
|
|
|
UtmMedium: "UtmMedium",
|
|
|
|
|
UtmCampaign: "UtmCampaign",
|
|
|
|
|
UtmContent: "UtmContent",
|
|
|
|
|
UtmTerm: "UtmTerm",
|
|
|
|
|
},
|
|
|
|
|
}
|
2024-09-26 14:21:38 +00:00
|
|
|
|
//
|
2024-10-22 20:59:45 +00:00
|
|
|
|
reqMap := models.FormattingToMap(&createDealReq, fieldAnswer)
|
2024-10-23 09:21:14 +00:00
|
|
|
|
fmt.Println(reqMap)
|
2024-10-24 15:17:57 +00:00
|
|
|
|
result, err := b.CreatingDeal(reqMap, "e16b1a670000071b007254120000000100000759485bd49a2206c79f84e8a150522f43", "b24-s5jg6c.bitrix24.ru")
|
2024-10-22 20:59:45 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
}
|
|
|
|
|
fmt.Println(result)
|
2024-09-26 10:52:30 +00:00
|
|
|
|
//
|
|
|
|
|
//for _, tipe := range model.CategoryArr {
|
2024-09-29 14:57:21 +00:00
|
|
|
|
// result, err := b.GetListPipelines(tipe, "9d5bf9660000071b00717f9200000001000007b8da5b64a2142c5a0abcfb3e65f89b0c", "b24-ld76ub.bitrix24.ru")
|
2024-09-26 10:52:30 +00:00
|
|
|
|
// if err != nil {
|
|
|
|
|
// fmt.Println(err)
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// r, _ := json.Marshal(result)
|
|
|
|
|
// fmt.Println(string(r))
|
|
|
|
|
//}
|
|
|
|
|
//
|
2024-09-29 14:57:21 +00:00
|
|
|
|
//for _, tipe := range arr {
|
|
|
|
|
// result, err := b.GetListFields(tipe, "07cff6660000071b00717f92000000010000079e5af88b052dbcfe9e9d98cac38710ad", "b24-ld76ub.bitrix24.ru")
|
|
|
|
|
// if err != nil {
|
|
|
|
|
// fmt.Println(err)
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// r, _ := json.Marshal(result)
|
|
|
|
|
// fmt.Println(string(r))
|
|
|
|
|
// fmt.Println(tipe)
|
|
|
|
|
//}
|
2024-09-26 14:21:38 +00:00
|
|
|
|
//arr2 := []model.TypeStepsEntityID{model.StatusStepsEntityID, model.DealTypeStepsEntityID, model.DealStageStepsEntityID, model.SourceStepsEntityID, model.ContactTypeStepsEntityID, model.CompanyTypeStepsEntityID, model.EmployeesStepsEntityID, model.IndustryStepsEntityID, model.SmartInvoiceStageStepsEntityID, model.QuoteStatusStepsEntityID, model.HonorificStepsEntityID, model.CallListStepsEntityID, model.SmartDocumentStageStepsEntityID}
|
|
|
|
|
//for _, stepType := range arr2 {
|
2024-10-22 20:59:45 +00:00
|
|
|
|
//result, err := b.GetListSteps("9d5bf9660000071b00717f9200000001000007b8da5b64a2142c5a0abcfb3e65f89b0c", "b24-ld76ub.bitrix24.ru")
|
|
|
|
|
//if err != nil {
|
|
|
|
|
// fmt.Println(err)
|
|
|
|
|
//}
|
|
|
|
|
//for _, i := range result.Result {
|
|
|
|
|
// fmt.Println(i.ID)
|
|
|
|
|
//}
|
2024-09-26 12:43:25 +00:00
|
|
|
|
//}
|
|
|
|
|
//
|
|
|
|
|
//"CATEGORY_ID":"1"
|
2024-09-20 14:41:33 +00:00
|
|
|
|
}
|
2024-10-17 22:00:41 +00:00
|
|
|
|
|
|
|
|
|
func Test_Auth(t *testing.T) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
lim := limiter.NewRateLimiter(ctx, 50, 2*time.Second)
|
|
|
|
|
logger := zap.NewNop()
|
|
|
|
|
b := NewBitrixClient(BitrixDeps{
|
|
|
|
|
Logger: logger,
|
|
|
|
|
RedirectionURL: "https://squiz.pena.digital/integrations",
|
|
|
|
|
IntegrationID: "app.670bd825e44c52.61826940",
|
|
|
|
|
IntegrationSecret: "Ki0MElZXS6dE6tRsGxixri2jmxbxF2Xa4qQpBPziGdAvvLAHJx",
|
|
|
|
|
RateLimiter: lim,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
tokens, err := b.CreateWebHook(&models.CreateWebHookReq{
|
|
|
|
|
GrantType: "authorization_code",
|
|
|
|
|
Code: "50cb1067007232200072541200000001000007aab0e419e6de4ebff7dd4b238c144bae",
|
|
|
|
|
}, true)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
fmt.Println(tokens)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_GetListUsers(t *testing.T) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
lim := limiter.NewRateLimiter(ctx, 50, 2*time.Second)
|
|
|
|
|
logger := zap.NewNop()
|
|
|
|
|
b := NewBitrixClient(BitrixDeps{
|
|
|
|
|
Logger: logger,
|
|
|
|
|
RedirectionURL: "https://squiz.pena.digital/integrations",
|
|
|
|
|
IntegrationID: "app.670bd825e44c52.61826940",
|
|
|
|
|
IntegrationSecret: "Ki0MElZXS6dE6tRsGxixri2jmxbxF2Xa4qQpBPziGdAvvLAHJx",
|
|
|
|
|
RateLimiter: lim,
|
|
|
|
|
})
|
|
|
|
|
|
2024-10-18 14:11:28 +00:00
|
|
|
|
r, err := b.GetUserList("664e12670000071b00725412000000010000071da5594e25e0731541e2bd2ea0d78a7b", "b24-s5jg6c.bitrix24.ru")
|
2024-10-17 22:00:41 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
fmt.Println(r)
|
|
|
|
|
}
|
2024-10-20 12:42:00 +00:00
|
|
|
|
|
|
|
|
|
func Test_Add_Fields(t *testing.T) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
lim := limiter.NewRateLimiter(ctx, 50, 2*time.Second)
|
|
|
|
|
logger := zap.NewNop()
|
|
|
|
|
b := NewBitrixClient(BitrixDeps{
|
|
|
|
|
Logger: logger,
|
|
|
|
|
RedirectionURL: "https://squiz.pena.digital/integrations",
|
|
|
|
|
IntegrationID: "app.670bd825e44c52.61826940",
|
|
|
|
|
IntegrationSecret: "Ki0MElZXS6dE6tRsGxixri2jmxbxF2Xa4qQpBPziGdAvvLAHJx",
|
|
|
|
|
RateLimiter: lim,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
req := models.AddFields{
|
|
|
|
|
FieldName: "Test_Add_Fields_Deal",
|
|
|
|
|
EditFormLabel: "Test_Add_Fields_Deal",
|
|
|
|
|
ListColumnLabel: "Test_Add_Fields_Deal",
|
|
|
|
|
UserTypeID: model.StringCustomFieldsType,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
req.GenFieldName()
|
|
|
|
|
|
|
|
|
|
resp, err := b.AddFields(req, model.FieldTypeDeal, "9afc14670072322000725412000000010000074c130dd22fbea5321c68aebd7e4e6b98", "b24-s5jg6c.bitrix24.ru")
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
fmt.Println(resp)
|
|
|
|
|
}
|
2024-10-21 11:44:41 +00:00
|
|
|
|
|
|
|
|
|
func Test_Update_Contact(t *testing.T) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
lim := limiter.NewRateLimiter(ctx, 50, 2*time.Second)
|
|
|
|
|
logger := zap.NewNop()
|
|
|
|
|
b := NewBitrixClient(BitrixDeps{
|
|
|
|
|
Logger: logger,
|
|
|
|
|
RedirectionURL: "https://squiz.pena.digital/integrations",
|
|
|
|
|
IntegrationID: "app.670bd825e44c52.61826940",
|
|
|
|
|
IntegrationSecret: "Ki0MElZXS6dE6tRsGxixri2jmxbxF2Xa4qQpBPziGdAvvLAHJx",
|
|
|
|
|
RateLimiter: lim,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
contactFields := make(map[string]string)
|
|
|
|
|
contactFields["UF_CRM_1729426581"] = "phoneTESTUPDATE"
|
|
|
|
|
contactFields["UF_CRM_1729425300"] = "emailTESTUPDATE"
|
|
|
|
|
contactFields["UF_CRM_1729425184"] = "nameTESTUPDATE"
|
|
|
|
|
|
|
|
|
|
reqContact := models.CreateContactReq{
|
|
|
|
|
Fields: models.ContactFields{
|
|
|
|
|
Name: "TEST UPDATE CONTACT",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reqMapContact := models.FormattingToMap(&reqContact, contactFields)
|
|
|
|
|
|
|
|
|
|
err := b.UpdateContact(reqMapContact, "6b2c16670000071b0072541200000001000007b21dd57044f7de29fde6a9566e6932f1", "b24-s5jg6c.bitrix24.ru", 53)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
fmt.Println("GOOD")
|
|
|
|
|
}
|
2024-10-24 13:34:07 +00:00
|
|
|
|
|
|
|
|
|
func Test_AddedTagCustomField(t *testing.T) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
lim := limiter.NewRateLimiter(ctx, 50, 2*time.Second)
|
|
|
|
|
logger := zap.NewNop()
|
|
|
|
|
b := NewBitrixClient(BitrixDeps{
|
|
|
|
|
Logger: logger,
|
|
|
|
|
RedirectionURL: "https://squiz.pena.digital/integrations",
|
|
|
|
|
IntegrationID: "app.670bd825e44c52.61826940",
|
|
|
|
|
IntegrationSecret: "Ki0MElZXS6dE6tRsGxixri2jmxbxF2Xa4qQpBPziGdAvvLAHJx",
|
|
|
|
|
RateLimiter: lim,
|
|
|
|
|
})
|
|
|
|
|
|
2024-10-24 15:17:57 +00:00
|
|
|
|
err := b.AddedTagCustomField("e16b1a670000071b007254120000000100000759485bd49a2206c79f84e8a150522f43", "b24-s5jg6c.bitrix24.ru")
|
2024-10-24 13:34:07 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
}
|
|
|
|
|
fmt.Println("GOOD")
|
|
|
|
|
}
|