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

     1  package systemssync_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/kyma-incubator/compass/components/director/internal/domain/systemssync"
     7  	"github.com/kyma-incubator/compass/components/director/internal/model"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestConverter_ToEntity(t *testing.T) {
    12  	systemsSyncModel := fixSystemsSyncModel(syncID, syncTenantID, syncProductID, lastSyncTime)
    13  	systemsSyncEntity := fixSystemsSyncEntity(syncID, syncTenantID, syncProductID, lastSyncTime)
    14  	testCases := []struct {
    15  		Name     string
    16  		Input    *model.SystemSynchronizationTimestamp
    17  		Expected *systemssync.Entity
    18  	}{
    19  		{
    20  			Name:     "All properties given",
    21  			Input:    systemsSyncModel,
    22  			Expected: systemsSyncEntity,
    23  		},
    24  		{
    25  			Name:     "Empty",
    26  			Input:    &model.SystemSynchronizationTimestamp{},
    27  			Expected: &systemssync.Entity{},
    28  		},
    29  		{
    30  			Name:     "Nil",
    31  			Input:    nil,
    32  			Expected: nil,
    33  		},
    34  	}
    35  
    36  	for _, testCase := range testCases {
    37  		t.Run(testCase.Name, func(t *testing.T) {
    38  			conv := systemssync.NewConverter()
    39  
    40  			// WHEN
    41  			res := conv.ToEntity(testCase.Input)
    42  
    43  			assert.Equal(t, testCase.Expected, res)
    44  		})
    45  	}
    46  }
    47  
    48  func TestConverter_FromEntity(t *testing.T) {
    49  	systemsSyncModel := fixSystemsSyncModel(syncID, syncTenantID, syncProductID, lastSyncTime)
    50  	systemsSyncEntity := fixSystemsSyncEntity(syncID, syncTenantID, syncProductID, lastSyncTime)
    51  
    52  	testCases := []struct {
    53  		Name     string
    54  		Input    *systemssync.Entity
    55  		Expected *model.SystemSynchronizationTimestamp
    56  	}{
    57  		{
    58  			Name:     "All properties given",
    59  			Input:    systemsSyncEntity,
    60  			Expected: systemsSyncModel,
    61  		},
    62  		{
    63  			Name:     "Empty",
    64  			Input:    &systemssync.Entity{},
    65  			Expected: &model.SystemSynchronizationTimestamp{},
    66  		},
    67  		{
    68  			Name:     "Nil",
    69  			Input:    nil,
    70  			Expected: nil,
    71  		},
    72  	}
    73  
    74  	for _, testCase := range testCases {
    75  		t.Run(testCase.Name, func(t *testing.T) {
    76  			conv := systemssync.NewConverter()
    77  
    78  			// WHEN
    79  			res := conv.FromEntity(testCase.Input)
    80  
    81  			assert.Equal(t, testCase.Expected, res)
    82  		})
    83  	}
    84  }