flamingo.me/flamingo-commerce/v3@v3.11.0/category/domain/category_test.go (about)

     1  package domain
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestCategoryData_Attribute(t *testing.T) {
     9  	var nilAtt *Attribute
    10  	type fields struct {
    11  		CategoryCode       string
    12  		CategoryName       string
    13  		CategoryPath       string
    14  		IsPromoted         bool
    15  		CategoryMedia      Medias
    16  		CategoryTypeCode   string
    17  		CategoryAttributes Attributes
    18  	}
    19  	type args struct {
    20  		code string
    21  	}
    22  	tests := []struct {
    23  		name   string
    24  		fields fields
    25  		args   args
    26  		want   interface{}
    27  	}{
    28  		{
    29  			name: "empty attributes",
    30  			args: args{
    31  				code: "test",
    32  			},
    33  			want: nilAtt,
    34  		},
    35  		{
    36  			name: "not found",
    37  			args: args{
    38  				code: "invalid",
    39  			},
    40  			fields: fields{
    41  				CategoryAttributes: Attributes{
    42  					"test": Attribute{Values: []AttributeValue{{RawValue: "ok"}}},
    43  				},
    44  			},
    45  			want: nilAtt,
    46  		},
    47  		{
    48  			args: args{
    49  				code: "test",
    50  			},
    51  			want: nilAtt,
    52  		},
    53  		{
    54  			name: "found",
    55  			args: args{
    56  				code: "test",
    57  			},
    58  			fields: fields{
    59  				CategoryAttributes: Attributes{
    60  					"test": Attribute{Values: []AttributeValue{{RawValue: "ok"}}},
    61  				},
    62  			},
    63  			want: &Attribute{Values: []AttributeValue{{RawValue: "ok"}}},
    64  		},
    65  	}
    66  	for _, tt := range tests {
    67  		t.Run(tt.name, func(t *testing.T) {
    68  			c := CategoryData{
    69  				CategoryCode:       tt.fields.CategoryCode,
    70  				CategoryName:       tt.fields.CategoryName,
    71  				CategoryPath:       tt.fields.CategoryPath,
    72  				IsPromoted:         tt.fields.IsPromoted,
    73  				CategoryMedia:      tt.fields.CategoryMedia,
    74  				CategoryTypeCode:   tt.fields.CategoryTypeCode,
    75  				CategoryAttributes: tt.fields.CategoryAttributes,
    76  			}
    77  			if got := c.Attributes().Get(tt.args.code); !reflect.DeepEqual(got, tt.want) {
    78  				t.Errorf("CategoryData.Attribute() = %v, want %v", got, tt.want)
    79  			}
    80  		})
    81  	}
    82  }