amocrm/tests/json/json_test.go

53 lines
1.2 KiB
Go
Raw Normal View History

package json
import (
"amocrm/internal/models"
"encoding/json"
"fmt"
"github.com/stretchr/testify/assert"
"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))
}