github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/domain/formationconstraint/converter_test.go (about) 1 package formationconstraint_test 2 3 import ( 4 "testing" 5 6 "github.com/kyma-incubator/compass/components/director/internal/domain/formationconstraint" 7 "github.com/kyma-incubator/compass/components/director/internal/model" 8 "github.com/kyma-incubator/compass/components/director/pkg/graphql" 9 "github.com/stretchr/testify/require" 10 ) 11 12 var converter = formationconstraint.NewConverter() 13 14 func TestToGraphQL(t *testing.T) { 15 t.Run("Success", func(t *testing.T) { 16 // WHEN 17 actual := converter.ToGraphQL(formationConstraintModel) 18 19 // THEN 20 require.Equal(t, gqlFormationConstraint, actual) 21 }) 22 t.Run("Nil input", func(t *testing.T) { 23 // WHEN 24 actual := converter.ToGraphQL(nil) 25 26 // THEN 27 require.Nil(t, actual) 28 }) 29 } 30 31 func TestMultipleToGraphQL(t *testing.T) { 32 t.Run("Success", func(t *testing.T) { 33 // WHEN 34 actual := converter.MultipleToGraphQL([]*model.FormationConstraint{formationConstraintModel, formationConstraintModel2, nil}) 35 36 // THEN 37 require.Equal(t, []*graphql.FormationConstraint{gqlFormationConstraint, gqlFormationConstraint2}, actual) 38 }) 39 t.Run("Nil input", func(t *testing.T) { 40 // WHEN 41 actual := converter.MultipleToGraphQL(nil) 42 43 // THEN 44 require.Nil(t, actual) 45 }) 46 } 47 48 func TestToEntity(t *testing.T) { 49 t.Run("Success", func(t *testing.T) { 50 // WHEN 51 actual := converter.ToEntity(formationConstraintModel) 52 53 // THEN 54 require.Equal(t, &entity, actual) 55 }) 56 t.Run("Nil input", func(t *testing.T) { 57 // WHEN 58 actual := converter.ToEntity(nil) 59 60 // THEN 61 require.Nil(t, actual) 62 }) 63 } 64 65 func TestFromEntity(t *testing.T) { 66 t.Run("Success", func(t *testing.T) { 67 // WHEN 68 actual := converter.FromEntity(&entity) 69 70 // THEN 71 require.Equal(t, formationConstraintModel, actual) 72 }) 73 t.Run("Nil input", func(t *testing.T) { 74 // WHEN 75 actual := converter.FromEntity(nil) 76 77 // THEN 78 require.Nil(t, actual) 79 }) 80 } 81 82 func TestFromInputGraphQL(t *testing.T) { 83 t.Run("Success", func(t *testing.T) { 84 // WHEN 85 actual := converter.FromInputGraphQL(gqlInput) 86 87 // THEN 88 require.Equal(t, modelInput, actual) 89 }) 90 } 91 92 func TestFromModelInputToModel(t *testing.T) { 93 t.Run("Success", func(t *testing.T) { 94 // WHEN 95 actual := converter.FromModelInputToModel(modelInput, testID) 96 97 // THEN 98 require.Equal(t, modelFromInput, actual) 99 }) 100 }