Skip to content
Snippets Groups Projects
Select Git revision
  • 932eb6c518ca6ec1268a84aecb47f958e644fd7d
  • master default protected
  • feature/PRXS-3383-CollectionsSort
  • refactor/PRXS-3053-Files
  • feature/PRXS-3143-3235-ReferenceOptions
  • feature/PRXS-3421-ImplementNewRefAPI
  • feature/PRXS-3143-LimitReferenceFields
  • feature/PRXS-3234-FeaturePruneIdents
  • feature/3149-LocaleCodeAsID-Feature
  • PRXS-3421-RecursiveReferences
  • feature/3109-SerializeFeature
  • release/0.33
  • feature/3109-RecoverySchema
  • feature/3109-feature
  • fix/PRXS-3369-ValidateFields
  • refactor/PRXS-3306-MovePkgGroup1
  • refactor/6-pkg-refactor-expr
  • fix/PRXS-3360-TemplateBuilderPatch
  • feature/3293-MongoV2
  • feature/3272-GoVersionUp
  • feature/PRXS-3218-HideTemplateActions
  • v0.33.1
  • v0.32.0
  • v0.31.1
  • v0.31.0
  • v0.30.0
  • v0.29.0
  • v0.28.0
  • v0.27.0-alpha.1+16
  • v0.27.0-alpha.1+15
  • v0.27.0-alpha.1+14
  • v0.27.0-alpha.1+13
  • v0.27.0-alpha.1+12
  • v0.27.0-alpha.1+11
  • v0.27.0-alpha.1+10
  • v0.27.0-alpha.1+9
  • v0.27.0-alpha.1+8
  • v0.27.0-alpha.1+7
  • v0.27.0-alpha.1+6
  • v0.27.0-alpha.1+5
  • v0.27.0-alpha.1+4
41 results

assets_test.go

Blame
  • field_test.go 7.87 KiB
    package references
    
    import (
    	"context"
    	"encoding/json"
    	"fmt"
    	"testing"
    
    	"git.perx.ru/perxis/perxis-go/pkg/items"
    	"git.perx.ru/perxis/perxis-go/pkg/items/mocks"
    	"git.perx.ru/perxis/perxis-go/pkg/schema"
    	"git.perx.ru/perxis/perxis-go/pkg/schema/field"
    	"git.perx.ru/perxis/perxis-go/pkg/schema/validate"
    	"github.com/stretchr/testify/assert"
    	"github.com/stretchr/testify/require"
    )
    
    func TestReferenceField_Decode(t *testing.T) {
    
    	tests := []struct {
    		name    string
    		field   *field.Field
    		data    interface{}
    		want    interface{}
    		wantErr bool
    	}{
    		{
    			"Correct",
    			Field(nil),
    			map[string]interface{}{"collection_id": "media", "id": "11111111"},
    			&Reference{ID: "11111111", CollectionID: "media"},
    			false,
    		},
    		{
    			"Invalid CollectionID",
    			Field(nil),
    			map[string]interface{}{"collection_id": "media", "id": 11111111},
    			"decode error: ReferenceField decode error: field \"id\" required",
    			true,
    		},
    		{
    			"Extra Field",
    			Field(nil),
    			map[string]interface{}{"collection_id": "media", "id": "11111111", "extra": true},
    			&Reference{ID: "11111111", CollectionID: "media"},
    			false,
    		},
    		{
    			"Enabled",
    			Field(nil),
    			map[string]interface{}{"collection_id": "media", "id": "11111111", "disabled": true},
    			&Reference{ID: "11111111", CollectionID: "media", Disabled: true},
    			false,
    		},
    		{
    			"Disabled",
    			Field(nil),
    			map[string]interface{}{"collection_id": "media", "id": "11111111", "disabled": false},
    			&Reference{ID: "11111111", CollectionID: "media", Disabled: false},
    			false,
    		},
    		{
    			"Disabled wrong type",
    			Field(nil),
    			map[string]interface{}{"collection_id": "media", "id": "11111111", "disabled": 3},
    			&Reference{ID: "11111111", CollectionID: "media", Disabled: false},
    			false,
    		},
    		{
    			"Missing Field",