github.com/enbility/spine-go@v0.7.0/model/tariffinformation_additions_test.go (about)

     1  package model
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/enbility/spine-go/util"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestTariffListDataType_Update(t *testing.T) {
    11  	sut := TariffListDataType{
    12  		TariffData: []TariffDataType{
    13  			{
    14  				TariffId:     util.Ptr(TariffIdType(0)),
    15  				ActiveTierId: []TierIdType{0},
    16  			},
    17  			{
    18  				TariffId:     util.Ptr(TariffIdType(1)),
    19  				ActiveTierId: []TierIdType{0},
    20  			},
    21  		},
    22  	}
    23  
    24  	newData := TariffListDataType{
    25  		TariffData: []TariffDataType{
    26  			{
    27  				TariffId:     util.Ptr(TariffIdType(1)),
    28  				ActiveTierId: []TierIdType{1},
    29  			},
    30  		},
    31  	}
    32  
    33  	// Act
    34  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
    35  	assert.True(t, success)
    36  
    37  	data := sut.TariffData
    38  	// check the non changing items
    39  	assert.Equal(t, 2, len(data))
    40  	item1 := data[0]
    41  	assert.Equal(t, 0, int(*item1.TariffId))
    42  	assert.Equal(t, 0, int(item1.ActiveTierId[0]))
    43  	// check properties of updated item
    44  	item2 := data[1]
    45  	assert.Equal(t, 1, int(*item2.TariffId))
    46  	assert.Equal(t, 1, int(item2.ActiveTierId[0]))
    47  }
    48  
    49  func TestTariffTierRelationListDataType_Update(t *testing.T) {
    50  	sut := TariffTierRelationListDataType{
    51  		TariffTierRelationData: []TariffTierRelationDataType{
    52  			{
    53  				TariffId: util.Ptr(TariffIdType(0)),
    54  				TierId:   []TierIdType{0},
    55  			},
    56  			{
    57  				TariffId: util.Ptr(TariffIdType(1)),
    58  				TierId:   []TierIdType{0},
    59  			},
    60  		},
    61  	}
    62  
    63  	newData := TariffTierRelationListDataType{
    64  		TariffTierRelationData: []TariffTierRelationDataType{
    65  			{
    66  				TariffId: util.Ptr(TariffIdType(1)),
    67  				TierId:   []TierIdType{1},
    68  			},
    69  		},
    70  	}
    71  
    72  	// Act
    73  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
    74  	assert.True(t, success)
    75  
    76  	data := sut.TariffTierRelationData
    77  	// check the non changing items
    78  	assert.Equal(t, 2, len(data))
    79  	item1 := data[0]
    80  	assert.Equal(t, 0, int(*item1.TariffId))
    81  	assert.Equal(t, 0, int(item1.TierId[0]))
    82  	// check properties of updated item
    83  	item2 := data[1]
    84  	assert.Equal(t, 1, int(*item2.TariffId))
    85  	assert.Equal(t, 1, int(item2.TierId[0]))
    86  }
    87  
    88  func TestTariffBoundaryRelationListDataType_Update(t *testing.T) {
    89  	sut := TariffBoundaryRelationListDataType{
    90  		TariffBoundaryRelationData: []TariffBoundaryRelationDataType{
    91  			{
    92  				TariffId:   util.Ptr(TariffIdType(0)),
    93  				BoundaryId: []TierBoundaryIdType{0},
    94  			},
    95  			{
    96  				TariffId:   util.Ptr(TariffIdType(1)),
    97  				BoundaryId: []TierBoundaryIdType{0},
    98  			},
    99  		},
   100  	}
   101  
   102  	newData := TariffBoundaryRelationListDataType{
   103  		TariffBoundaryRelationData: []TariffBoundaryRelationDataType{
   104  			{
   105  				TariffId:   util.Ptr(TariffIdType(1)),
   106  				BoundaryId: []TierBoundaryIdType{1},
   107  			},
   108  		},
   109  	}
   110  
   111  	// Act
   112  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
   113  	assert.True(t, success)
   114  
   115  	data := sut.TariffBoundaryRelationData
   116  	// check the non changing items
   117  	assert.Equal(t, 2, len(data))
   118  	item1 := data[0]
   119  	assert.Equal(t, 0, int(*item1.TariffId))
   120  	assert.Equal(t, 0, int(item1.BoundaryId[0]))
   121  	// check properties of updated item
   122  	item2 := data[1]
   123  	assert.Equal(t, 1, int(*item2.TariffId))
   124  	assert.Equal(t, 1, int(item2.BoundaryId[0]))
   125  }
   126  
   127  func TestTariffDescriptionListDataType_Update(t *testing.T) {
   128  	sut := TariffDescriptionListDataType{
   129  		TariffDescriptionData: []TariffDescriptionDataType{
   130  			{
   131  				TariffId:    util.Ptr(TariffIdType(0)),
   132  				Description: util.Ptr(DescriptionType("old")),
   133  			},
   134  			{
   135  				TariffId:    util.Ptr(TariffIdType(1)),
   136  				Description: util.Ptr(DescriptionType("old")),
   137  			},
   138  		},
   139  	}
   140  
   141  	newData := TariffDescriptionListDataType{
   142  		TariffDescriptionData: []TariffDescriptionDataType{
   143  			{
   144  				TariffId:    util.Ptr(TariffIdType(1)),
   145  				Description: util.Ptr(DescriptionType("new")),
   146  			},
   147  		},
   148  	}
   149  
   150  	// Act
   151  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
   152  	assert.True(t, success)
   153  
   154  	data := sut.TariffDescriptionData
   155  	// check the non changing items
   156  	assert.Equal(t, 2, len(data))
   157  	item1 := data[0]
   158  	assert.Equal(t, 0, int(*item1.TariffId))
   159  	assert.Equal(t, "old", string(*item1.Description))
   160  	// check properties of updated item
   161  	item2 := data[1]
   162  	assert.Equal(t, 1, int(*item2.TariffId))
   163  	assert.Equal(t, "new", string(*item2.Description))
   164  }
   165  
   166  func TestTierBoundaryListDataType_Update(t *testing.T) {
   167  	sut := TierBoundaryListDataType{
   168  		TierBoundaryData: []TierBoundaryDataType{
   169  			{
   170  				BoundaryId:         util.Ptr(TierBoundaryIdType(0)),
   171  				LowerBoundaryValue: NewScaledNumberType(1),
   172  			},
   173  			{
   174  				BoundaryId:         util.Ptr(TierBoundaryIdType(1)),
   175  				LowerBoundaryValue: NewScaledNumberType(1),
   176  			},
   177  		},
   178  	}
   179  
   180  	newData := TierBoundaryListDataType{
   181  		TierBoundaryData: []TierBoundaryDataType{
   182  			{
   183  				BoundaryId:         util.Ptr(TierBoundaryIdType(1)),
   184  				LowerBoundaryValue: NewScaledNumberType(10),
   185  			},
   186  		},
   187  	}
   188  
   189  	// Act
   190  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
   191  	assert.True(t, success)
   192  
   193  	data := sut.TierBoundaryData
   194  	// check the non changing items
   195  	assert.Equal(t, 2, len(data))
   196  	item1 := data[0]
   197  	assert.Equal(t, 0, int(*item1.BoundaryId))
   198  	assert.Equal(t, 1.0, item1.LowerBoundaryValue.GetValue())
   199  	// check properties of updated item
   200  	item2 := data[1]
   201  	assert.Equal(t, 1, int(*item2.BoundaryId))
   202  	assert.Equal(t, 10.0, item2.LowerBoundaryValue.GetValue())
   203  }
   204  
   205  func TestTierBoundaryDescriptionListDataType_Update(t *testing.T) {
   206  	sut := TierBoundaryDescriptionListDataType{
   207  		TierBoundaryDescriptionData: []TierBoundaryDescriptionDataType{
   208  			{
   209  				BoundaryId:  util.Ptr(TierBoundaryIdType(0)),
   210  				Description: util.Ptr(DescriptionType("old")),
   211  			},
   212  			{
   213  				BoundaryId:  util.Ptr(TierBoundaryIdType(1)),
   214  				Description: util.Ptr(DescriptionType("old")),
   215  			},
   216  		},
   217  	}
   218  
   219  	newData := TierBoundaryDescriptionListDataType{
   220  		TierBoundaryDescriptionData: []TierBoundaryDescriptionDataType{
   221  			{
   222  				BoundaryId:  util.Ptr(TierBoundaryIdType(1)),
   223  				Description: util.Ptr(DescriptionType("new")),
   224  			},
   225  		},
   226  	}
   227  
   228  	// Act
   229  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
   230  	assert.True(t, success)
   231  
   232  	data := sut.TierBoundaryDescriptionData
   233  	// check the non changing items
   234  	assert.Equal(t, 2, len(data))
   235  	item1 := data[0]
   236  	assert.Equal(t, 0, int(*item1.BoundaryId))
   237  	assert.Equal(t, "old", string(*item1.Description))
   238  	// check properties of updated item
   239  	item2 := data[1]
   240  	assert.Equal(t, 1, int(*item2.BoundaryId))
   241  	assert.Equal(t, "new", string(*item2.Description))
   242  }
   243  
   244  func TestCommodityListDataType_Update(t *testing.T) {
   245  	sut := CommodityListDataType{
   246  		CommodityData: []CommodityDataType{
   247  			{
   248  				CommodityId: util.Ptr(CommodityIdType(0)),
   249  				Description: util.Ptr(DescriptionType("old")),
   250  			},
   251  			{
   252  				CommodityId: util.Ptr(CommodityIdType(1)),
   253  				Description: util.Ptr(DescriptionType("old")),
   254  			},
   255  		},
   256  	}
   257  
   258  	newData := CommodityListDataType{
   259  		CommodityData: []CommodityDataType{
   260  			{
   261  				CommodityId: util.Ptr(CommodityIdType(1)),
   262  				Description: util.Ptr(DescriptionType("new")),
   263  			},
   264  		},
   265  	}
   266  
   267  	// Act
   268  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
   269  	assert.True(t, success)
   270  
   271  	data := sut.CommodityData
   272  	// check the non changing items
   273  	assert.Equal(t, 2, len(data))
   274  	item1 := data[0]
   275  	assert.Equal(t, 0, int(*item1.CommodityId))
   276  	assert.Equal(t, "old", string(*item1.Description))
   277  	// check properties of updated item
   278  	item2 := data[1]
   279  	assert.Equal(t, 1, int(*item2.CommodityId))
   280  	assert.Equal(t, "new", string(*item2.Description))
   281  }
   282  
   283  func TestTierListDataType_Update(t *testing.T) {
   284  	sut := TierListDataType{
   285  		TierData: []TierDataType{
   286  			{
   287  				TierId:            util.Ptr(TierIdType(0)),
   288  				ActiveIncentiveId: []IncentiveIdType{0},
   289  			},
   290  			{
   291  				TierId:            util.Ptr(TierIdType(1)),
   292  				ActiveIncentiveId: []IncentiveIdType{0},
   293  			},
   294  		},
   295  	}
   296  
   297  	newData := TierListDataType{
   298  		TierData: []TierDataType{
   299  			{
   300  				TierId:            util.Ptr(TierIdType(1)),
   301  				ActiveIncentiveId: []IncentiveIdType{1},
   302  			},
   303  		},
   304  	}
   305  
   306  	// Act
   307  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
   308  	assert.True(t, success)
   309  
   310  	data := sut.TierData
   311  	// check the non changing items
   312  	assert.Equal(t, 2, len(data))
   313  	item1 := data[0]
   314  	assert.Equal(t, 0, int(*item1.TierId))
   315  	assert.Equal(t, 0, int(item1.ActiveIncentiveId[0]))
   316  	// check properties of updated item
   317  	item2 := data[1]
   318  	assert.Equal(t, 1, int(*item2.TierId))
   319  	assert.Equal(t, 1, int(item2.ActiveIncentiveId[0]))
   320  }
   321  
   322  func TestTierIncentiveRelationListDataType_Update(t *testing.T) {
   323  	sut := TierIncentiveRelationListDataType{
   324  		TierIncentiveRelationData: []TierIncentiveRelationDataType{
   325  			{
   326  				TierId:      util.Ptr(TierIdType(0)),
   327  				IncentiveId: []IncentiveIdType{0},
   328  			},
   329  			{
   330  				TierId:      util.Ptr(TierIdType(1)),
   331  				IncentiveId: []IncentiveIdType{0},
   332  			},
   333  		},
   334  	}
   335  
   336  	newData := TierIncentiveRelationListDataType{
   337  		TierIncentiveRelationData: []TierIncentiveRelationDataType{
   338  			{
   339  				TierId:      util.Ptr(TierIdType(1)),
   340  				IncentiveId: []IncentiveIdType{1},
   341  			},
   342  		},
   343  	}
   344  
   345  	// Act
   346  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
   347  	assert.True(t, success)
   348  
   349  	data := sut.TierIncentiveRelationData
   350  	// check the non changing items
   351  	assert.Equal(t, 2, len(data))
   352  	item1 := data[0]
   353  	assert.Equal(t, 0, int(*item1.TierId))
   354  	assert.Equal(t, 0, int(item1.IncentiveId[0]))
   355  	// check properties of updated item
   356  	item2 := data[1]
   357  	assert.Equal(t, 1, int(*item2.TierId))
   358  	assert.Equal(t, 1, int(item2.IncentiveId[0]))
   359  }
   360  
   361  func TestTierDescriptionListDataType_Update(t *testing.T) {
   362  	sut := TierDescriptionListDataType{
   363  		TierDescriptionData: []TierDescriptionDataType{
   364  			{
   365  				TierId:      util.Ptr(TierIdType(0)),
   366  				Description: util.Ptr(DescriptionType("old")),
   367  			},
   368  			{
   369  				TierId:      util.Ptr(TierIdType(1)),
   370  				Description: util.Ptr(DescriptionType("old")),
   371  			},
   372  		},
   373  	}
   374  
   375  	newData := TierDescriptionListDataType{
   376  		TierDescriptionData: []TierDescriptionDataType{
   377  			{
   378  				TierId:      util.Ptr(TierIdType(1)),
   379  				Description: util.Ptr(DescriptionType("new")),
   380  			},
   381  		},
   382  	}
   383  
   384  	// Act
   385  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
   386  	assert.True(t, success)
   387  
   388  	data := sut.TierDescriptionData
   389  	// check the non changing items
   390  	assert.Equal(t, 2, len(data))
   391  	item1 := data[0]
   392  	assert.Equal(t, 0, int(*item1.TierId))
   393  	assert.Equal(t, "old", string(*item1.Description))
   394  	// check properties of updated item
   395  	item2 := data[1]
   396  	assert.Equal(t, 1, int(*item2.TierId))
   397  	assert.Equal(t, "new", string(*item2.Description))
   398  }
   399  
   400  func TestIncentiveListDataType_Update(t *testing.T) {
   401  	sut := IncentiveListDataType{
   402  		IncentiveData: []IncentiveDataType{
   403  			{
   404  				IncentiveId: util.Ptr(IncentiveIdType(0)),
   405  				Value:       NewScaledNumberType(1),
   406  			},
   407  			{
   408  				IncentiveId: util.Ptr(IncentiveIdType(1)),
   409  				Value:       NewScaledNumberType(1),
   410  			},
   411  		},
   412  	}
   413  
   414  	newData := IncentiveListDataType{
   415  		IncentiveData: []IncentiveDataType{
   416  			{
   417  				IncentiveId: util.Ptr(IncentiveIdType(1)),
   418  				Value:       NewScaledNumberType(10),
   419  			},
   420  		},
   421  	}
   422  
   423  	// Act
   424  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
   425  	assert.True(t, success)
   426  
   427  	data := sut.IncentiveData
   428  	// check the non changing items
   429  	assert.Equal(t, 2, len(data))
   430  	item1 := data[0]
   431  	assert.Equal(t, 0, int(*item1.IncentiveId))
   432  	assert.Equal(t, 1.0, item1.Value.GetValue())
   433  	// check properties of updated item
   434  	item2 := data[1]
   435  	assert.Equal(t, 1, int(*item2.IncentiveId))
   436  	assert.Equal(t, 10.0, item2.Value.GetValue())
   437  }
   438  
   439  func TestIncentiveDescriptionListDataType_Update(t *testing.T) {
   440  	sut := IncentiveDescriptionListDataType{
   441  		IncentiveDescriptionData: []IncentiveDescriptionDataType{
   442  			{
   443  				IncentiveId: util.Ptr(IncentiveIdType(0)),
   444  				Description: util.Ptr(DescriptionType("old")),
   445  			},
   446  			{
   447  				IncentiveId: util.Ptr(IncentiveIdType(1)),
   448  				Description: util.Ptr(DescriptionType("old")),
   449  			},
   450  		},
   451  	}
   452  
   453  	newData := IncentiveDescriptionListDataType{
   454  		IncentiveDescriptionData: []IncentiveDescriptionDataType{
   455  			{
   456  				IncentiveId: util.Ptr(IncentiveIdType(1)),
   457  				Description: util.Ptr(DescriptionType("new")),
   458  			},
   459  		},
   460  	}
   461  
   462  	// Act
   463  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
   464  	assert.True(t, success)
   465  
   466  	data := sut.IncentiveDescriptionData
   467  	// check the non changing items
   468  	assert.Equal(t, 2, len(data))
   469  	item1 := data[0]
   470  	assert.Equal(t, 0, int(*item1.IncentiveId))
   471  	assert.Equal(t, "old", string(*item1.Description))
   472  	// check properties of updated item
   473  	item2 := data[1]
   474  	assert.Equal(t, 1, int(*item2.IncentiveId))
   475  	assert.Equal(t, "new", string(*item2.Description))
   476  }