github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/model/eventapi_test.go (about)

     1  package model_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/kyma-incubator/compass/components/director/pkg/resource"
     7  
     8  	"github.com/kyma-incubator/compass/components/director/internal/model"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestEventAPIDefinitionInput_ToEventAPIDefinition(t *testing.T) {
    13  	// GIVEN
    14  	id := "foo"
    15  	bndlID := "bar"
    16  	appID := "baz"
    17  	appTemplateVersionID := "naz"
    18  	desc := "Sample"
    19  	name := "sample"
    20  	group := "sampleGroup"
    21  
    22  	testCases := []struct {
    23  		Name         string
    24  		Input        *model.EventDefinitionInput
    25  		ResourceType resource.Type
    26  		ResourceID   string
    27  		Expected     *model.EventDefinition
    28  	}{
    29  		{
    30  			Name: "All properties given for App",
    31  			Input: &model.EventDefinitionInput{
    32  				Name:        name,
    33  				Description: &desc,
    34  				Group:       &group,
    35  			},
    36  			Expected: &model.EventDefinition{
    37  				ApplicationID: &appID,
    38  				Name:          name,
    39  				Description:   &desc,
    40  				Group:         &group,
    41  				PackageID:     &bndlID,
    42  				BaseEntity: &model.BaseEntity{
    43  					ID:    id,
    44  					Ready: true,
    45  				},
    46  			},
    47  			ResourceType: resource.Application,
    48  			ResourceID:   appID,
    49  		},
    50  		{
    51  			Name: "All properties given for App Template Version",
    52  			Input: &model.EventDefinitionInput{
    53  				Name:        name,
    54  				Description: &desc,
    55  				Group:       &group,
    56  			},
    57  			Expected: &model.EventDefinition{
    58  				ApplicationTemplateVersionID: &appTemplateVersionID,
    59  				Name:                         name,
    60  				Description:                  &desc,
    61  				Group:                        &group,
    62  				PackageID:                    &bndlID,
    63  				BaseEntity: &model.BaseEntity{
    64  					ID:    id,
    65  					Ready: true,
    66  				},
    67  			},
    68  			ResourceType: resource.ApplicationTemplateVersion,
    69  			ResourceID:   appTemplateVersionID,
    70  		},
    71  		{
    72  			Name:     "Nil",
    73  			Input:    nil,
    74  			Expected: nil,
    75  		},
    76  	}
    77  
    78  	for _, testCase := range testCases {
    79  		t.Run(testCase.Name, func(t *testing.T) {
    80  			// WHEN
    81  			result := testCase.Input.ToEventDefinition(id, testCase.ResourceType, testCase.ResourceID, &bndlID, 0)
    82  
    83  			// then
    84  			assert.Equal(t, testCase.Expected, result)
    85  		})
    86  	}
    87  }