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

     1  package integrationsystem_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/kyma-incubator/compass/components/director/internal/domain/integrationsystem"
     7  	"github.com/kyma-incubator/compass/components/director/internal/model"
     8  	"github.com/kyma-incubator/compass/components/director/pkg/graphql"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  )
    12  
    13  func TestConverter_ToGraphQL(t *testing.T) {
    14  	// GIVEN
    15  	converter := integrationsystem.NewConverter()
    16  
    17  	testCases := []struct {
    18  		Name     string
    19  		Input    *model.IntegrationSystem
    20  		Expected *graphql.IntegrationSystem
    21  	}{
    22  		{
    23  			Name:     "All properties given",
    24  			Input:    fixModelIntegrationSystem(testID, testName),
    25  			Expected: fixGQLIntegrationSystem(testID, testName),
    26  		},
    27  		{
    28  			Name:     "Empty",
    29  			Input:    &model.IntegrationSystem{},
    30  			Expected: &graphql.IntegrationSystem{},
    31  		},
    32  		{
    33  			Name:     "Nil",
    34  			Input:    nil,
    35  			Expected: nil,
    36  		},
    37  	}
    38  
    39  	for _, testCase := range testCases {
    40  		t.Run(testCase.Name, func(t *testing.T) {
    41  			// WHEN
    42  			res := converter.ToGraphQL(testCase.Input)
    43  
    44  			// THEN
    45  			assert.Equal(t, testCase.Expected, res)
    46  		})
    47  	}
    48  }
    49  
    50  func TestConverter_MultipleToGraphQL(t *testing.T) {
    51  	// GIVEN
    52  	input := []*model.IntegrationSystem{
    53  		fixModelIntegrationSystem("id1", "name1"),
    54  		fixModelIntegrationSystem("id2", "name2"),
    55  		{},
    56  		nil,
    57  	}
    58  	expected := []*graphql.IntegrationSystem{
    59  		fixGQLIntegrationSystem("id1", "name1"),
    60  		fixGQLIntegrationSystem("id2", "name2"),
    61  		{},
    62  	}
    63  	converter := integrationsystem.NewConverter()
    64  
    65  	// WHEN
    66  	res := converter.MultipleToGraphQL(input)
    67  
    68  	// THEN
    69  	assert.Equal(t, expected, res)
    70  }
    71  
    72  func TestConverter_InputFromGraphQL(t *testing.T) {
    73  	// GIVEN
    74  	converter := integrationsystem.NewConverter()
    75  
    76  	testCases := []struct {
    77  		Name     string
    78  		Input    graphql.IntegrationSystemInput
    79  		Expected model.IntegrationSystemInput
    80  	}{
    81  		{
    82  			Name:     "All properties given",
    83  			Input:    fixGQLIntegrationSystemInput(testName),
    84  			Expected: fixModelIntegrationSystemInput(testName),
    85  		},
    86  		{
    87  			Name:     "Empty",
    88  			Input:    graphql.IntegrationSystemInput{},
    89  			Expected: model.IntegrationSystemInput{},
    90  		},
    91  	}
    92  
    93  	for _, testCase := range testCases {
    94  		t.Run(testCase.Name, func(t *testing.T) {
    95  			// WHEN
    96  			res := converter.InputFromGraphQL(testCase.Input)
    97  
    98  			// THEN
    99  			assert.Equal(t, testCase.Expected, res)
   100  		})
   101  	}
   102  }
   103  
   104  func TestConverter_ToEntity(t *testing.T) {
   105  	// GIVEN
   106  	converter := integrationsystem.NewConverter()
   107  
   108  	testCases := []struct {
   109  		Name     string
   110  		Input    *model.IntegrationSystem
   111  		Expected *integrationsystem.Entity
   112  	}{
   113  		{
   114  			Name:     "All properties given",
   115  			Input:    fixModelIntegrationSystem(testID, testName),
   116  			Expected: fixEntityIntegrationSystem(testID, testName),
   117  		},
   118  		{
   119  			Name:     "Empty",
   120  			Input:    &model.IntegrationSystem{},
   121  			Expected: &integrationsystem.Entity{},
   122  		},
   123  		{
   124  			Name:     "Nil",
   125  			Input:    nil,
   126  			Expected: nil,
   127  		},
   128  	}
   129  
   130  	for _, testCase := range testCases {
   131  		t.Run(testCase.Name, func(t *testing.T) {
   132  			// WHEN
   133  			res := converter.ToEntity(testCase.Input)
   134  
   135  			// THEN
   136  			assert.Equal(t, testCase.Expected, res)
   137  		})
   138  	}
   139  }
   140  
   141  func TestConverter_FromEntity(t *testing.T) {
   142  	// GIVEN
   143  	converter := integrationsystem.NewConverter()
   144  
   145  	testCases := []struct {
   146  		Name     string
   147  		Input    *integrationsystem.Entity
   148  		Expected *model.IntegrationSystem
   149  	}{
   150  		{
   151  			Name:     "All properties given",
   152  			Input:    fixEntityIntegrationSystem(testID, testName),
   153  			Expected: fixModelIntegrationSystem(testID, testName),
   154  		},
   155  		{
   156  			Name:     "Empty",
   157  			Input:    &integrationsystem.Entity{},
   158  			Expected: &model.IntegrationSystem{},
   159  		},
   160  		{
   161  			Name:     "Nil",
   162  			Input:    nil,
   163  			Expected: nil,
   164  		},
   165  	}
   166  
   167  	for _, testCase := range testCases {
   168  		t.Run(testCase.Name, func(t *testing.T) {
   169  			// WHEN
   170  			res := converter.FromEntity(testCase.Input)
   171  
   172  			// THEN
   173  			assert.Equal(t, testCase.Expected, res)
   174  		})
   175  	}
   176  }