2024-09-20 14:41:33 +00:00
|
|
|
|
package bitrixClient
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2024-09-23 14:46:46 +00:00
|
|
|
|
"encoding/json"
|
2024-09-20 14:41:33 +00:00
|
|
|
|
"fmt"
|
|
|
|
|
"go.uber.org/zap"
|
2024-09-23 09:31:38 +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-09-26 08:19:51 +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-26 08:19:51 +00:00
|
|
|
|
arr := []model.FieldsType{model.FieldTypeLead, model.FieldTypeCompany, model.FieldTypeContact, model.FieldTypeDeal}
|
|
|
|
|
|
|
|
|
|
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-09-24 14:36:29 +00:00
|
|
|
|
|
|
|
|
|
fieldAnswer := make(map[string]string)
|
|
|
|
|
fieldAnswer["UF_CRM_1727099993"] = "field1"
|
|
|
|
|
fieldAnswer["UF_CRM_1727099994"] = "field2"
|
|
|
|
|
fieldAnswer["UF_CRM_1727099994"] = "field3"
|
|
|
|
|
fieldAnswer["UF_CRM_1726835607006"] = "field4"
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2024-09-26 07:32:41 +00:00
|
|
|
|
contactResult, err := b.CreateContact(reqMap, "eb19f5660000071b00717f9200000001000007f6c1795b0c3c995cf4cbbae1a9d0394c", "b24-ld76ub.bitrix24.ru")
|
2024-09-24 14:36:29 +00:00
|
|
|
|
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)
|
2024-09-26 07:32:41 +00:00
|
|
|
|
companyResult, err := b.CreateCompany(reqMap, "eb19f5660000071b00717f9200000001000007f6c1795b0c3c995cf4cbbae1a9d0394c", "b24-ld76ub.bitrix24.ru")
|
2024-09-24 14:36:29 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createDealReq := models.CreatingDealReq{
|
|
|
|
|
Fields: models.CreateDealFields{
|
|
|
|
|
Title: "ТЕСТ ОТ ГОУ АПИ 10/10",
|
|
|
|
|
TypeID: "SALE",
|
|
|
|
|
StageID: "NEW",
|
|
|
|
|
CompanyID: companyResult,
|
|
|
|
|
ContactIDs: []int32{contactResult},
|
|
|
|
|
Opened: "Y",
|
|
|
|
|
AssignedByID: 1,
|
|
|
|
|
CategoryID: 5,
|
|
|
|
|
SourceID: "CALL",
|
|
|
|
|
UtmSource: "UtmSource",
|
|
|
|
|
UtmMedium: "UtmMedium",
|
|
|
|
|
UtmCampaign: "UtmCampaign",
|
|
|
|
|
UtmContent: "UtmContent",
|
|
|
|
|
UtmTerm: "UtmTerm",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reqMap = models.FormattingToMap(&createDealReq, fieldAnswer)
|
2024-09-26 07:32:41 +00:00
|
|
|
|
result, err := b.CreatingDeal(reqMap, "eb19f5660000071b00717f9200000001000007f6c1795b0c3c995cf4cbbae1a9d0394c", "b24-ld76ub.bitrix24.ru")
|
2024-09-24 14:36:29 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
}
|
2024-09-23 14:46:46 +00:00
|
|
|
|
|
2024-09-26 08:19:51 +00:00
|
|
|
|
for _, tipe := range model.CategoryArr {
|
|
|
|
|
result, err := b.GetListPipelines(tipe, "eb19f5660000071b00717f9200000001000007f6c1795b0c3c995cf4cbbae1a9d0394c", "b24-ld76ub.bitrix24.ru")
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r, _ := json.Marshal(result)
|
|
|
|
|
fmt.Println(string(r))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tipe := range arr {
|
|
|
|
|
result, err := b.GetListFields(tipe, "eb19f5660000071b00717f9200000001000007f6c1795b0c3c995cf4cbbae1a9d0394c", "b24-ld76ub.bitrix24.ru")
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r, _ := json.Marshal(result)
|
|
|
|
|
fmt.Println(string(r))
|
|
|
|
|
fmt.Println(tipe)
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-23 16:01:13 +00:00
|
|
|
|
r, _ := json.Marshal(result)
|
|
|
|
|
fmt.Println(string(r))
|
2024-09-24 14:36:29 +00:00
|
|
|
|
|
2024-09-20 14:41:33 +00:00
|
|
|
|
}
|