amocrm/tests/json/json_test.go
skeris b554d9f475
All checks were successful
Deploy / CreateImage (push) Successful in 2m7s
Deploy / DeployService (push) Successful in 19s
ci gitea
2025-02-08 01:06:18 +03:00

80 lines
2.0 KiB
Go

package json
import (
"amocrm/internal/models"
"amocrm/internal/tools"
"context"
"encoding/json"
"fmt"
"github.com/stretchr/testify/assert"
"gitea.pena/SQuiz/common/dal"
"gitea.pena/SQuiz/common/model"
"testing"
)
func TestUnmarshalJSON(t *testing.T) {
jsonData := []byte(`[
{
"field_id": 1,
"values": [
{"value": "Value1"},
{"value": {"file_uuid": "123e4567file_uuid", "version_uuid": "123e4567version_uuid", "file_name": "file.pdf", "file_size": 1}}
]
},
{
"field_id": 2,
"values": [
{"value": "Value2"},
{"value": {"file_uuid": "98765432file_uuid", "version_uuid": "98765432version_uuid", "file_name": "file.wc", "file_size": 2}}
]
},
{
"field_id": 3,
"values": [
{"value": "Value3"},
{"value": {"file_uuid": "abcdeffile_uuid", "version_uuid": "abcdefversion_uuid", "file_name": "file.txt", "file_size": 3}}
]
}
]
`)
var fv []models.FieldsValues
err := json.Unmarshal(jsonData, &fv)
if err != nil {
t.Errorf("UnmarshalJSON failed: %v", err)
}
for _, f := range fv {
fmt.Println(f)
}
assert.Equal(t, 3, len(fv))
jsonAgain, err := json.Marshal(fv)
assert.NoError(t, err)
fmt.Println(string(jsonAgain))
}
func Test_ContactRule(t *testing.T) {
ctx := context.Background()
repo, err := dal.NewAmoDal(ctx, "host=localhost port=35432 user=squiz password=Redalert2 dbname=squiz sslmode=disable")
assert.NoError(t, err)
accountID := "64f2cd7a7047f28fdabf6d9e"
quiz, err := repo.QuizRepo.GetQuizById(ctx, accountID, 26166)
assert.NoError(t, err)
var quizConfig model.QuizContact
err = json.Unmarshal([]byte(quiz.Config), &quizConfig)
assert.NoError(t, err)
currentFields, err := repo.AmoRepo.GetUserFieldsByID(ctx, 30228997)
assert.NoError(t, err)
contactFieldsToCreate, forAdding := tools.ForContactRules(quizConfig, currentFields)
fmt.Println("contactFieldsToCreate", contactFieldsToCreate)
fmt.Println("forAdding", forAdding)
}