github.com/enbility/spine-go@v0.7.0/model/supplyconditions_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 TestSupplyConditionListDataType_Update(t *testing.T) { 11 sut := SupplyConditionListDataType{ 12 SupplyConditionData: []SupplyConditionDataType{ 13 { 14 ConditionId: util.Ptr(ConditionIdType(0)), 15 Description: util.Ptr(DescriptionType("old")), 16 }, 17 { 18 ConditionId: util.Ptr(ConditionIdType(1)), 19 Description: util.Ptr(DescriptionType("old")), 20 }, 21 }, 22 } 23 24 newData := SupplyConditionListDataType{ 25 SupplyConditionData: []SupplyConditionDataType{ 26 { 27 ConditionId: util.Ptr(ConditionIdType(1)), 28 Description: util.Ptr(DescriptionType("new")), 29 }, 30 }, 31 } 32 33 // Act 34 _, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil) 35 assert.True(t, success) 36 37 data := sut.SupplyConditionData 38 // check the non changing items 39 assert.Equal(t, 2, len(data)) 40 item1 := data[0] 41 assert.Equal(t, 0, int(*item1.ConditionId)) 42 assert.Equal(t, "old", string(*item1.Description)) 43 // check properties of updated item 44 item2 := data[1] 45 assert.Equal(t, 1, int(*item2.ConditionId)) 46 assert.Equal(t, "new", string(*item2.Description)) 47 } 48 49 func TestSupplyConditionDescriptionListDataType_Update(t *testing.T) { 50 sut := SupplyConditionDescriptionListDataType{ 51 SupplyConditionDescriptionData: []SupplyConditionDescriptionDataType{ 52 { 53 ConditionId: util.Ptr(ConditionIdType(0)), 54 Description: util.Ptr(DescriptionType("old")), 55 }, 56 { 57 ConditionId: util.Ptr(ConditionIdType(1)), 58 Description: util.Ptr(DescriptionType("old")), 59 }, 60 }, 61 } 62 63 newData := SupplyConditionDescriptionListDataType{ 64 SupplyConditionDescriptionData: []SupplyConditionDescriptionDataType{ 65 { 66 ConditionId: util.Ptr(ConditionIdType(1)), 67 Description: util.Ptr(DescriptionType("new")), 68 }, 69 }, 70 } 71 72 // Act 73 _, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil) 74 assert.True(t, success) 75 76 data := sut.SupplyConditionDescriptionData 77 // check the non changing items 78 assert.Equal(t, 2, len(data)) 79 item1 := data[0] 80 assert.Equal(t, 0, int(*item1.ConditionId)) 81 assert.Equal(t, "old", string(*item1.Description)) 82 // check properties of updated item 83 item2 := data[1] 84 assert.Equal(t, 1, int(*item2.ConditionId)) 85 assert.Equal(t, "new", string(*item2.Description)) 86 } 87 88 func TestSupplyConditionThresholdRelationListDataType_Update(t *testing.T) { 89 sut := SupplyConditionThresholdRelationListDataType{ 90 SupplyConditionThresholdRelationData: []SupplyConditionThresholdRelationDataType{ 91 { 92 ConditionId: util.Ptr(ConditionIdType(0)), 93 ThresholdId: []ThresholdIdType{0}, 94 }, 95 { 96 ConditionId: util.Ptr(ConditionIdType(1)), 97 ThresholdId: []ThresholdIdType{0}, 98 }, 99 }, 100 } 101 102 newData := SupplyConditionThresholdRelationListDataType{ 103 SupplyConditionThresholdRelationData: []SupplyConditionThresholdRelationDataType{ 104 { 105 ConditionId: util.Ptr(ConditionIdType(1)), 106 ThresholdId: []ThresholdIdType{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.SupplyConditionThresholdRelationData 116 // check the non changing items 117 assert.Equal(t, 2, len(data)) 118 item1 := data[0] 119 assert.Equal(t, 0, int(*item1.ConditionId)) 120 assert.Equal(t, 0, int(item1.ThresholdId[0])) 121 // check properties of updated item 122 item2 := data[1] 123 assert.Equal(t, 1, int(*item2.ConditionId)) 124 assert.Equal(t, 1, int(item2.ThresholdId[0])) 125 }