github.com/mundipagg/boleto-api@v0.0.0-20230620145841-3f9ec742599f/models/interest_test.go (about) 1 package models 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 type testInterestParameter struct { 11 Line interface{} 12 Input interface{} 13 Expected interface{} 14 } 15 16 var hasInterestParameters = []testInterestParameter{ 17 {Line: 4, Input: Interest{DaysAfterExpirationDate: 1, AmountPerDayInCents: 1, PercentagePerMonth: 0}, Expected: true}, 18 {Line: 5, Input: Interest{DaysAfterExpirationDate: 1, AmountPerDayInCents: 0, PercentagePerMonth: 1.20}, Expected: true}, 19 {Line: 6, Input: Interest{DaysAfterExpirationDate: 1, AmountPerDayInCents: 200, PercentagePerMonth: 3}, Expected: true}, 20 } 21 22 var hasAmountPerDayInCentsParameters = []testInterestParameter{ 23 {Line: 1, Input: Interest{AmountPerDayInCents: 0}, Expected: false}, 24 {Line: 2, Input: Interest{AmountPerDayInCents: 1}, Expected: true}, 25 {Line: 3, Input: Interest{AmountPerDayInCents: 20034}, Expected: true}, 26 } 27 28 var validateParameters = []testFineParameter{ 29 {Line: 1, Input: Interest{DaysAfterExpirationDate: 1, AmountPerDayInCents: 0, PercentagePerMonth: 0}, Expected: false}, 30 {Line: 2, Input: Interest{DaysAfterExpirationDate: 1, AmountPerDayInCents: 1, PercentagePerMonth: 0}, Expected: true}, 31 {Line: 3, Input: Interest{DaysAfterExpirationDate: 1, AmountPerDayInCents: 0, PercentagePerMonth: 1}, Expected: true}, 32 {Line: 4, Input: Interest{DaysAfterExpirationDate: 1, AmountPerDayInCents: 1, PercentagePerMonth: 1}, Expected: false}, 33 {Line: 5, Input: Interest{DaysAfterExpirationDate: 1, PercentagePerMonth: -1}, Expected: false}, 34 {Line: 6, Input: Interest{DaysAfterExpirationDate: 1, PercentagePerMonth: -2.34}, Expected: false}, 35 {Line: 7, Input: Interest{DaysAfterExpirationDate: 1, PercentagePerMonth: 0}, Expected: false}, 36 {Line: 8, Input: Interest{DaysAfterExpirationDate: 1, PercentagePerMonth: 0.0}, Expected: false}, 37 {Line: 9, Input: Interest{DaysAfterExpirationDate: 1, PercentagePerMonth: 1}, Expected: true}, 38 {Line: 10, Input: Interest{DaysAfterExpirationDate: 1, PercentagePerMonth: 2.23}, Expected: true}, 39 {Line: 11, Input: Interest{DaysAfterExpirationDate: 0, AmountPerDayInCents: 0, PercentagePerMonth: 0}, Expected: false}, 40 {Line: 12, Input: Interest{DaysAfterExpirationDate: 0, AmountPerDayInCents: 1, PercentagePerMonth: 0}, Expected: false}, 41 {Line: 13, Input: Interest{DaysAfterExpirationDate: 0, AmountPerDayInCents: 0, PercentagePerMonth: 1.2}, Expected: false}, 42 {Line: 14, Input: Interest{DaysAfterExpirationDate: 1, AmountPerDayInCents: 1, PercentagePerMonth: 0.0}, Expected: true}, 43 {Line: 15, Input: Interest{DaysAfterExpirationDate: 1, AmountPerDayInCents: 0, PercentagePerMonth: 1.2}, Expected: true}, 44 {Line: 16, Input: Interest{DaysAfterExpirationDate: 2, AmountPerDayInCents: 0, PercentagePerMonth: 1.2}, Expected: true}, 45 } 46 47 var hasExclusiveRateValuesParameters = []testInterestParameter{ 48 {Line: 1, Input: Interest{AmountPerDayInCents: 0, PercentagePerMonth: 0}, Expected: false}, 49 {Line: 2, Input: Interest{AmountPerDayInCents: 1, PercentagePerMonth: 0}, Expected: true}, 50 {Line: 3, Input: Interest{AmountPerDayInCents: 0, PercentagePerMonth: 1}, Expected: true}, 51 {Line: 4, Input: Interest{AmountPerDayInCents: 1, PercentagePerMonth: 1}, Expected: false}, 52 } 53 54 var hasPercentagePerMonthParameters = []testInterestParameter{ 55 {Line: 1, Input: Interest{PercentagePerMonth: -1}, Expected: false}, 56 {Line: 2, Input: Interest{PercentagePerMonth: -2.34}, Expected: false}, 57 {Line: 3, Input: Interest{PercentagePerMonth: 0}, Expected: false}, 58 {Line: 4, Input: Interest{PercentagePerMonth: 0.0}, Expected: false}, 59 {Line: 5, Input: Interest{PercentagePerMonth: 1}, Expected: true}, 60 {Line: 6, Input: Interest{PercentagePerMonth: 2.23}, Expected: true}, 61 } 62 63 var hasDaysAfterExpirationDateParameters = []testInterestParameter{ 64 {Line: 1, Input: Interest{DaysAfterExpirationDate: 0, AmountPerDayInCents: 0, PercentagePerMonth: 0}, Expected: false}, 65 {Line: 2, Input: Interest{DaysAfterExpirationDate: 0, AmountPerDayInCents: 1, PercentagePerMonth: 0}, Expected: false}, 66 {Line: 3, Input: Interest{DaysAfterExpirationDate: 0, AmountPerDayInCents: 0, PercentagePerMonth: 1.2}, Expected: false}, 67 {Line: 4, Input: Interest{DaysAfterExpirationDate: 1, AmountPerDayInCents: 1, PercentagePerMonth: 0.0}, Expected: true}, 68 {Line: 5, Input: Interest{DaysAfterExpirationDate: 1, AmountPerDayInCents: 0, PercentagePerMonth: 1.2}, Expected: true}, 69 {Line: 6, Input: Interest{DaysAfterExpirationDate: 2, AmountPerDayInCents: 0, PercentagePerMonth: 1.2}, Expected: true}, 70 } 71 72 func TestHasInterest(t *testing.T) { 73 for _, fact := range hasInterestParameters { 74 input := fact.Input.(Interest) 75 76 result := input.HasInterest() 77 78 assert.Equal(t, fact.Expected, result, fmt.Sprintf("HasInterest - Linha %d: Os juros não foram validados corretamente", fact.Line.(int))) 79 } 80 } 81 82 func TestHasAmountPerDayInCents(t *testing.T) { 83 for _, fact := range hasAmountPerDayInCentsParameters { 84 input := fact.Input.(Interest) 85 86 result := input.HasAmountPerDayInCents() 87 88 assert.Equal(t, fact.Expected, result, fmt.Sprintf("HasAmountPerDayInCents - Linha %d: Os juros não foram validados corretamente", fact.Line.(int))) 89 } 90 } 91 92 func TestValidate(t *testing.T) { 93 for _, fact := range validateParameters { 94 input := fact.Input.(Interest) 95 96 result := input.Validate() == nil 97 98 assert.Equal(t, fact.Expected, result, fmt.Sprintf("Validate - Linha %d: Deve validar a struct de juros", fact.Line.(int))) 99 } 100 } 101 102 func TestHasExclusiveRateValues(t *testing.T) { 103 for _, fact := range hasExclusiveRateValuesParameters { 104 input := fact.Input.(Interest) 105 106 result := input.HasExclusiveRateValues() 107 108 assert.Equal(t, fact.Expected, result, fmt.Sprintf("HasExclusiveRateValues - Linha %d: Deve validar corretamente as regras de valores", fact.Line.(int))) 109 } 110 } 111 112 func TestHasPercentagePerMonth(t *testing.T) { 113 for _, fact := range hasPercentagePerMonthParameters { 114 input := fact.Input.(Interest) 115 116 result := input.HasPercentagePerMonth() 117 118 assert.Equal(t, fact.Expected, result, fmt.Sprintf("HasPercentagePerMonth - Linha %d: Deve validar corretamente o campo Percentage", fact.Line.(int))) 119 } 120 } 121 122 func TestHasDaysAfterExpirationDate(t *testing.T) { 123 for _, fact := range hasDaysAfterExpirationDateParameters { 124 input := fact.Input.(Interest) 125 126 result := input.HasDaysAfterExpirationDate() 127 128 assert.Equal(t, fact.Expected, result, fmt.Sprintf("HasDaysAfterExpirationDate - Linha %d: Deve validar corretamente o campo Days", fact.Line.(int))) 129 } 130 }