199 lines
6.3 KiB
Go
199 lines
6.3 KiB
Go
package bitrixClient
|
||
|
||
import (
|
||
"context"
|
||
"fmt"
|
||
"go.uber.org/zap"
|
||
"penahub.gitlab.yandexcloud.net/backend/quiz/bitrix/internal/models"
|
||
"penahub.gitlab.yandexcloud.net/backend/quiz/bitrix/internal/workers/limiter"
|
||
"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,
|
||
})
|
||
|
||
//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}
|
||
//
|
||
//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)
|
||
//}
|
||
//
|
||
//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)
|
||
//
|
||
//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)
|
||
//}
|
||
//
|
||
//createDealReq := models.CreatingDealReq{
|
||
// Fields: models.CreateDealFields{
|
||
// Title: "ТЕСТ ОТ ГОУ АПИ 10/10",
|
||
// TypeID: "SALE",
|
||
// StageID: "NEW",
|
||
// CompanyID: companyResult,
|
||
// ContactIDs: []int32{contactResult},
|
||
// Opened: "Y",
|
||
// AssignedByID: 1,
|
||
// CategoryID: 1,
|
||
// SourceID: "CALL",
|
||
// UtmSource: "UtmSource",
|
||
// UtmMedium: "UtmMedium",
|
||
// UtmCampaign: "UtmCampaign",
|
||
// UtmContent: "UtmContent",
|
||
// UtmTerm: "UtmTerm",
|
||
// },
|
||
//}
|
||
//
|
||
//reqMap = models.FormattingToMap(&createDealReq, fieldAnswer)
|
||
//result, err := b.CreatingDeal(reqMap, "ad5df5660000071b00717f920000000100000783b6e19c671e64c3655e5c7aff197e14", "b24-ld76ub.bitrix24.ru")
|
||
//if err != nil {
|
||
// fmt.Println(err)
|
||
//}
|
||
//
|
||
//for _, tipe := range model.CategoryArr {
|
||
// result, err := b.GetListPipelines(tipe, "9d5bf9660000071b00717f9200000001000007b8da5b64a2142c5a0abcfb3e65f89b0c", "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, "07cff6660000071b00717f92000000010000079e5af88b052dbcfe9e9d98cac38710ad", "b24-ld76ub.bitrix24.ru")
|
||
// if err != nil {
|
||
// fmt.Println(err)
|
||
// }
|
||
//
|
||
// r, _ := json.Marshal(result)
|
||
// fmt.Println(string(r))
|
||
// fmt.Println(tipe)
|
||
//}
|
||
//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 {
|
||
result, err := b.GetListSteps("9d5bf9660000071b00717f9200000001000007b8da5b64a2142c5a0abcfb3e65f89b0c", "b24-ld76ub.bitrix24.ru")
|
||
if err != nil {
|
||
fmt.Println(err)
|
||
}
|
||
for _, i := range result.Result {
|
||
fmt.Println(i.ID)
|
||
}
|
||
//}
|
||
//
|
||
//"CATEGORY_ID":"1"
|
||
}
|
||
|
||
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,
|
||
})
|
||
|
||
r, err := b.GetUserList("6a901167007232200072541200000001000007701b6ceba9a960508e993456e9b48a5a", "b24-s5jg6c.bitrix24.ru")
|
||
if err != nil {
|
||
fmt.Println(err)
|
||
return
|
||
}
|
||
fmt.Println(r)
|
||
}
|