github.com/mundipagg/boleto-api@v0.0.0-20230620145841-3f9ec742599f/tmpl/funcmaps_test.go (about)

     1  package tmpl
     2  
     3  import (
     4  	"fmt"
     5  	"html/template"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/mundipagg/boleto-api/models"
    10  	"github.com/mundipagg/boleto-api/test"
    11  	"github.com/stretchr/testify/assert"
    12  )
    13  
    14  type TestFee struct {
    15  	line          uint8
    16  	AmountFee     uint64
    17  	PercentageFee float64
    18  	TitleAmount   uint64
    19  }
    20  
    21  var formatDigitableLineParameters = []test.Parameter{
    22  	{Input: "34191123456789010111213141516171812345678901112", Expected: "34191.12345 67890.101112 13141.516171 8 12345678901112"},
    23  }
    24  
    25  var truncateParameters = []test.Parameter{
    26  	{Input: "00000000000000000000", Length: 5, Expected: "00000"},
    27  	{Input: "00000000000000000000", Length: 50, Expected: "00000000000000000000"},
    28  	{Input: "Rua de teste para o truncate", Length: 20, Expected: "Rua de teste para o "},
    29  	{Input: "", Length: 50, Expected: ""},
    30  }
    31  
    32  var clearStringParameters = []test.Parameter{
    33  	{Input: "óláçñê", Expected: "olacne"},
    34  	{Input: "ola", Expected: "ola"},
    35  	{Input: "", Expected: ""},
    36  	{Input: "Jardim Novo Cambuí ", Expected: "Jardim Novo Cambui"},
    37  	{Input: "Jardim Novo Cambuí�", Expected: "Jardim Novo Cambui"},
    38  }
    39  
    40  var formatNumberParameters = []test.UInt64TestParameter{
    41  	{Input: 50332, Expected: "503,32"},
    42  	{Input: 55, Expected: "0,55"},
    43  	{Input: 0, Expected: "0,00"},
    44  }
    45  
    46  var toFloatStrParameters = []test.UInt64TestParameter{
    47  	{Input: 50332, Expected: "503.32"},
    48  	{Input: 55, Expected: "0.55"},
    49  	{Input: 0, Expected: "0.00"},
    50  	{Input: 200, Expected: "2.00"},
    51  }
    52  
    53  var StrtoFloatParameters = []test.Parameter{
    54  	{Input: "2.00", Expected: 2.00},
    55  	{Input: "2.01", Expected: 2.01},
    56  }
    57  
    58  var formatDocParameters = []test.Parameter{
    59  	{Input: models.Document{Type: "CPF", Number: "12312100100"}, Expected: "123.121.001-00"},
    60  	{Input: models.Document{Type: "CNPJ", Number: "12123123000112"}, Expected: "12.123.123/0001-12"},
    61  }
    62  
    63  var docTypeParameters = []test.Parameter{
    64  	{Input: models.Document{Type: "CPF", Number: "12312100100"}, Expected: 1},
    65  	{Input: models.Document{Type: "CNPJ", Number: "12123123000112"}, Expected: 2},
    66  }
    67  
    68  var sanitizeCepParameters = []test.Parameter{
    69  	{Input: "25368-100", Expected: "25368100"},
    70  	{Input: "25368100", Expected: "25368100"},
    71  }
    72  
    73  var mod11BradescoShopFacilDvParameters = []test.Parameter{
    74  	{Input: "00000000006", Expected: "0"},
    75  	{Input: "00000000001", Expected: "P"},
    76  	{Input: "00000000002", Expected: "8"},
    77  }
    78  
    79  var sanitizeCitibankSpecialCharacteresParameters = []test.Parameter{
    80  	{Input: "", Expected: ""},       //Default string value
    81  	{Input: "   ", Expected: "   "}, //Whitespaces
    82  	{Input: "a b", Expected: "a b"},
    83  	{Input: "/-;@", Expected: "/-;@"}, //Caracteres especiais aceitos pelo Citibank
    84  	{Input: "???????????????????????????a-zA-Z0-9ÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõç.", Expected: "a-zA-Z0-9AEIOUAEIOUAEIOUAOaeiouaeiouaeiouaoc."},
    85  	{Input: "Ol@ Mundo. você pode ver uma barra /, mas não uma exclamação!?; Nem Isso", Expected: "Ol@ Mundo. voce pode ver uma barra / mas nao uma exclamacao; Nem Isso"},
    86  	{Input: "Avenida Andr? Rodrigues de Freitas", Expected: "Avenida Andr Rodrigues de Freitas"},
    87  }
    88  
    89  var clearStringCaixaParameters = []test.Parameter{
    90  	{Input: "CaixaAccepted:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789,/()*=-+!:?.;_'", Expected: "CaixaAccepted:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789,/()*=-+!:?.;_'"},
    91  	{Input: "CaixaAccepted:,/()*=-+!:?.;_'", Expected: "CaixaAccepted:,/()*=-+!:?.;_'"},
    92  	{Input: "XMLNotAccepted:&<>", Expected: "XMLNotAccepted:   "},
    93  	{Input: "CaixaClearCharacter:ÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõç", Expected: "CaixaClearCharacter:AEIOUAEIOUAEIOUAOaeiouaeiouaeiouaoc"},
    94  	{Input: "@#$%¨{}[]^~|ºª§°¹²³£¢¬\\�\"", Expected: "                         "},
    95  }
    96  
    97  var truncateOnlyParameters = []test.Parameter{
    98  	{Input: "0000000000000000000", Length: 5, Expected: "00000"},
    99  	{Input: "0000000000000000000", Length: 50, Expected: "0000000000000000000"},
   100  	{Input: "Rua de teste para o truncate", Length: 20, Expected: "Rua de teste para o "},
   101  	{Input: "", Length: 50, Expected: ""},
   102  	{Input: "ÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõç,/()*&=-+!:?<>.;_'@#$%¨{}[]^~|ºª§°¹²³£¢¬\\\"", Length: 80, Expected: "ÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõç,/()*&=-+!:?<>.;_'@#$%¨{}[]^~|ºª§°¹²³£¢¬\\\""},
   103  	{Input: "ÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõç,/()*&=-+!:?<>.;_'@#$%¨{}[]^~|ºª§°¹²³£¢¬\\\"", Length: 75, Expected: "ÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõç,/()*&=-+!:?<>.;_'@#$%¨{}[]^~|ºª§°¹²³£¢¬"},
   104  }
   105  
   106  var joinStringsParameters = []test.Parameter{
   107  	{Input: []string{"a", "b", "c"}, Expected: "a b c"},
   108  	{Input: []string{"abc", "d", "efgh"}, Expected: "abc d efgh"},
   109  	{Input: []string{" ", " ", " "}, Expected: "     "},
   110  	{Input: []string{"", "", "", "", ""}, Expected: "    "},
   111  	{Input: []string{"ÁÉÍÓÚÀ", "()*&=-+!:?<", "^~|ºª§°¹²³£¢¬\\\"", "@#$%"}, Expected: "ÁÉÍÓÚÀ ()*&=-+!:?< ^~|ºª§°¹²³£¢¬\\\" @#$%"},
   112  }
   113  
   114  var float64ToStringParameters = []test.Parameter{
   115  	{Input: -2.0, Expected: "-2.00"},
   116  	{Input: -2.4, Expected: "-2.40"},
   117  	{Input: 0.0, Expected: "0.00"},
   118  	{Input: 0.02, Expected: "0.02"},
   119  	{Input: 1.0, Expected: "1.00"},
   120  	{Input: 1.23, Expected: "1.23"},
   121  	{Input: 1.2379, Expected: "1.24"},
   122  }
   123  
   124  var calculateFeesParameters = []test.Parameter{
   125  	{Input: TestFee{line: 1, AmountFee: 0, PercentageFee: 0, TitleAmount: 1}, Expected: 0.0},
   126  	{Input: TestFee{line: 2, AmountFee: 200, PercentageFee: 0, TitleAmount: 2000}, Expected: 2.0},
   127  	{Input: TestFee{line: 3, AmountFee: 346, PercentageFee: 0, TitleAmount: 2000}, Expected: 3.46},
   128  	{Input: TestFee{line: 4, AmountFee: 122211, PercentageFee: 0, TitleAmount: 2000}, Expected: 1222.1100000000001},
   129  	{Input: TestFee{line: 5, AmountFee: 0, PercentageFee: 1.00, TitleAmount: 2000}, Expected: 0.2},
   130  	{Input: TestFee{line: 6, AmountFee: 0, PercentageFee: 1.26, TitleAmount: 2248}, Expected: 0.283248},
   131  }
   132  
   133  var getFineInstructionParameters = []test.Parameter{
   134  	{Input: models.Title{AmountInCents: 2000, Fees: &models.Fees{Fine: &models.Fine{DaysAfterExpirationDate: 1, AmountInCents: 200}}}, Expected: "A PARTIR DE 10/03/2022: MULTA..........R$ 2.00"},
   135  	{Input: models.Title{AmountInCents: 2000, Fees: &models.Fees{Fine: &models.Fine{DaysAfterExpirationDate: 2, AmountInCents: 346}}}, Expected: "A PARTIR DE 11/03/2022: MULTA..........R$ 3.46"},
   136  	{Input: models.Title{AmountInCents: 2000, Fees: &models.Fees{Fine: &models.Fine{DaysAfterExpirationDate: 2, AmountInCents: 122211}}}, Expected: "A PARTIR DE 11/03/2022: MULTA..........R$ 1222.11"},
   137  	{Input: models.Title{AmountInCents: 2000, Fees: &models.Fees{Fine: &models.Fine{DaysAfterExpirationDate: 2, PercentageOnTotal: 1.00}}}, Expected: "A PARTIR DE 11/03/2022: MULTA..........R$ 0.20"},
   138  	{Input: models.Title{AmountInCents: 2248, Fees: &models.Fees{Fine: &models.Fine{DaysAfterExpirationDate: 2, PercentageOnTotal: 1.26}}}, Expected: "A PARTIR DE 11/03/2022: MULTA..........R$ 0.28"},
   139  	{Input: models.Title{AmountInCents: 10, Fees: &models.Fees{Fine: &models.Fine{DaysAfterExpirationDate: 1, PercentageOnTotal: 0.5}}}, Expected: "A PARTIR DE 10/03/2022: MULTA..........R$ 0.00"},
   140  }
   141  
   142  var calculateInterestByDayParameters = []test.Parameter{
   143  	{Input: TestFee{line: 1, AmountFee: 0, PercentageFee: 0, TitleAmount: 1}, Expected: 0.0},
   144  	{Input: TestFee{line: 2, AmountFee: 200, PercentageFee: 0, TitleAmount: 2000}, Expected: 2.0},
   145  	{Input: TestFee{line: 3, AmountFee: 346, PercentageFee: 0, TitleAmount: 2000}, Expected: 3.46},
   146  	{Input: TestFee{line: 4, AmountFee: 122211, PercentageFee: 0, TitleAmount: 2000}, Expected: 1222.1100000000001},
   147  	{Input: TestFee{line: 5, AmountFee: 0, PercentageFee: 1.00, TitleAmount: 6000}, Expected: 0.02},
   148  	{Input: TestFee{line: 6, AmountFee: 0, PercentageFee: 1.26, TitleAmount: 83448}, Expected: 0.3504816},
   149  }
   150  
   151  var getInterestInstructionParameters = []test.Parameter{
   152  	{Input: models.Title{AmountInCents: 2000, Fees: &models.Fees{Interest: &models.Interest{DaysAfterExpirationDate: 1, AmountPerDayInCents: 20}}}, Expected: "A PARTIR DE 10/03/2022: JUROS POR DIA DE ATRASO.........R$ 0.200"},
   153  	{Input: models.Title{AmountInCents: 2000, Fees: &models.Fees{Interest: &models.Interest{DaysAfterExpirationDate: 1, AmountPerDayInCents: 346}}}, Expected: "A PARTIR DE 10/03/2022: JUROS POR DIA DE ATRASO.........R$ 3.460"},
   154  	{Input: models.Title{AmountInCents: 2000, Fees: &models.Fees{Interest: &models.Interest{DaysAfterExpirationDate: 2, AmountPerDayInCents: 122211}}}, Expected: "A PARTIR DE 11/03/2022: JUROS POR DIA DE ATRASO.........R$ 1222.110"},
   155  	{Input: models.Title{AmountInCents: 6000, Fees: &models.Fees{Interest: &models.Interest{DaysAfterExpirationDate: 2, PercentagePerMonth: 1.00}}}, Expected: "A PARTIR DE 11/03/2022: JUROS POR DIA DE ATRASO.........R$ 0.020"},
   156  	{Input: models.Title{AmountInCents: 83448, Fees: &models.Fees{Interest: &models.Interest{DaysAfterExpirationDate: 2, PercentagePerMonth: 1.26}}}, Expected: "A PARTIR DE 11/03/2022: JUROS POR DIA DE ATRASO.........R$ 0.350"},
   157  	{Input: models.Title{AmountInCents: 10, Fees: &models.Fees{Interest: &models.Interest{DaysAfterExpirationDate: 1, PercentagePerMonth: 0.5}}}, Expected: "A PARTIR DE 10/03/2022: JUROS POR DIA DE ATRASO.........R$ 0.000"},
   158  	{Input: models.Title{AmountInCents: 2000, Fees: &models.Fees{Interest: &models.Interest{DaysAfterExpirationDate: 1, PercentagePerMonth: 1.0}}}, Expected: "A PARTIR DE 10/03/2022: JUROS POR DIA DE ATRASO.........R$ 0.006"},
   159  }
   160  
   161  var alphanumericsStringsParameters = []test.Parameter{
   162  	{Input: "zÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõç", Expected: "zÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõç"},
   163  	{Input: "1234567890zÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõç", Expected: "1234567890zÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõç"},
   164  	{Input: "1234567890zÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõçabcdefABCDEFzZ", Expected: "1234567890zÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõçabcdefABCDEFzZ"},
   165  	{Input: "1@234#567890zÁÉÍÓÚÀÈ%ÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõçabcdefABCDEFzZ", Expected: "1234567890zÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõçabcdefABCDEFzZ"},
   166  }
   167  
   168  var alphabeticsStringsParameters = []test.Parameter{
   169  	{Input: "zÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõç", Expected: "zÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõç"},
   170  	{Input: "zÁÉÍ1234ÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóú1234àèìòùâêîôûãõç", Expected: "zÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõç"},
   171  	{Input: "abcdefgzÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõçABCDEFGZ", Expected: "abcdefgzÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõçABCDEFGZ"},
   172  	{Input: "abcdef$gzÁÉÍÓÚÀ%ÈÌÒÙÂÊÎÔÛÃ1()ÕáéíóúàèìòùâêîôûãõçABCDEFGZ", Expected: "abcdefgzÁÉÍÓÚÀÈÌÒÙÂÊÎÔÛÃÕáéíóúàèìòùâêîôûãõçABCDEFGZ"},
   173  }
   174  
   175  var onlyOneSpaceStringsParameters = []test.Parameter{
   176  	{Input: "campo1 campo2", Expected: "campo1 campo2"},
   177  	{Input: "campo1 \tcampo2", Expected: "campo1 campo2"},
   178  	{Input: "campo1 \t	campo2", Expected: "campo1 campo2"},
   179  	{Input: "campo1 \t	campo2 campo3", Expected: "campo1 campo2 campo3"},
   180  }
   181  
   182  var removeAllSpacesStringsParameters = []test.Parameter{
   183  	{Input: "campo1 campo2", Expected: "campo1campo2"},
   184  	{Input: "S P", Expected: "SP"},
   185  	{Input: "S P ", Expected: "SP"},
   186  	{Input: "S 	\tP \t", Expected: "SP"},
   187  }
   188  
   189  var roundDownParameters = []test.Parameter{
   190  	{Input: 0.12346, Expected: 0.1234},
   191  	{Input: 0.12349, Expected: 0.1234},
   192  	{Input: 0.12340, Expected: 0.1234},
   193  	{Input: 1.0, Expected: 1.0},
   194  	{Input: 0.0, Expected: 0.0},
   195  }
   196  
   197  var float64ToStringTruncateParameters = []test.Parameter{
   198  	{Input: 0.12346, Expected: "0.1234"},
   199  	{Input: 0.12349, Expected: "0.1234"},
   200  	{Input: 0.12340, Expected: "0.1234"},
   201  	{Input: 1.0, Expected: "1.0000"},
   202  	{Input: 0.0, Expected: "0.0000"},
   203  }
   204  
   205  func TestShouldPadLeft(t *testing.T) {
   206  	expected := "00005"
   207  
   208  	result := padLeft("5", "0", 5)
   209  
   210  	assert.Equal(t, expected, result, "O texto deve ter zeros a esqueda e até 5 caracteres")
   211  }
   212  
   213  func TestShouldReturnString(t *testing.T) {
   214  	expected := "5"
   215  
   216  	result := toString(5)
   217  
   218  	assert.Equal(t, expected, result, "O número deve ser uma string")
   219  }
   220  
   221  func TestFormatDigitableLine(t *testing.T) {
   222  	for _, fact := range formatDigitableLineParameters {
   223  		result := fmtDigitableLine(fact.Input.(string))
   224  		assert.Equal(t, fact.Expected, result, "A linha digitável deve ser formatada corretamente")
   225  	}
   226  }
   227  
   228  func TestTruncate(t *testing.T) {
   229  	for _, fact := range truncateParameters {
   230  		result := truncateString(fact.Input.(string), fact.Length)
   231  		assert.Equal(t, fact.Expected, result, "Deve-se truncar uma string corretamente")
   232  	}
   233  }
   234  
   235  func TestClearString(t *testing.T) {
   236  	for _, fact := range clearStringParameters {
   237  		result := clearString(fact.Input.(string))
   238  		assert.Equal(t, fact.Expected, result, "Deve-se limpar uma string corretamente")
   239  	}
   240  }
   241  
   242  func TestJoinSpace(t *testing.T) {
   243  	for _, fact := range joinStringsParameters {
   244  		params := fact.Input.([]string)
   245  		result := joinSpace(params...)
   246  		assert.Equal(t, fact.Expected, result, "Deve-se limpar uma string corretamente")
   247  	}
   248  }
   249  
   250  func TestFormatCNPJ(t *testing.T) {
   251  	expected := "01.000.000/0001-00"
   252  
   253  	result := fmtCNPJ("01000000000100")
   254  
   255  	assert.Equal(t, expected, result, "O CNPJ deve ser formatado corretamente")
   256  }
   257  
   258  func TestFormatCPF(t *testing.T) {
   259  	expected := "123.121.001-00"
   260  
   261  	result := fmtCPF("12312100100")
   262  
   263  	assert.Equal(t, expected, result, "O CPF deve ser formatado corretamente")
   264  }
   265  
   266  func TestFormatNumber(t *testing.T) {
   267  	for _, fact := range formatNumberParameters {
   268  		result := fmtNumber(fact.Input)
   269  		assert.Equal(t, fact.Expected, result, "O valor em inteiro deve ser convertido para uma string com duas casas decimais separado por vírgula (0,00)")
   270  	}
   271  }
   272  
   273  func TestMod11OurNumber(t *testing.T) {
   274  	var expected, onlyDigitExpected uint
   275  	expected = 120000001148
   276  	onlyDigitExpected = 8
   277  
   278  	result := calculateOurNumberMod11(12000000114, false)
   279  	onlyDigitResult := calculateOurNumberMod11(12000000114, true)
   280  
   281  	assert.Equal(t, expected, result, "Deve-se calcular o mod11 do nosso número e retornar o digito à esquerda")
   282  	assert.Equal(t, onlyDigitExpected, onlyDigitResult, "Deve-se calcular o mod11 do nosso número e retornar o digito à esquerda")
   283  }
   284  
   285  func TestToFloatStr(t *testing.T) {
   286  	for _, fact := range toFloatStrParameters {
   287  		result := toFloatStr(fact.Input)
   288  		assert.Equal(t, fact.Expected, result, "O valor em inteiro deve ser convertido para uma string com duas casas decimais separado por ponto (0.00)")
   289  	}
   290  }
   291  
   292  func TestStrToFloat(t *testing.T) {
   293  	for _, fact := range StrtoFloatParameters {
   294  		result := strToFloat(fact.Input.(string))
   295  		assert.Equal(t, fact.Expected, result, "O valor em inteiro deve ser convertido para uma string com duas casas decimais separado por ponto (0.00)")
   296  	}
   297  }
   298  
   299  func TestFormatDoc(t *testing.T) {
   300  	for _, fact := range formatDocParameters {
   301  		result := fmtDoc(fact.Input.(models.Document))
   302  		assert.Equal(t, fact.Expected, result, "O documento deve ser formatado corretamente")
   303  	}
   304  }
   305  
   306  func TestDocType(t *testing.T) {
   307  	for _, fact := range docTypeParameters {
   308  		result := docType(fact.Input.(models.Document))
   309  		assert.Equal(t, fact.Expected, result, "O documento deve ser do tipo correto")
   310  	}
   311  }
   312  
   313  func TestTrim(t *testing.T) {
   314  	expected := "hue br festa"
   315  
   316  	result := trim(" hue br festa ")
   317  
   318  	assert.Equal(t, expected, result, "O texto não deve ter espaços no início e no final")
   319  }
   320  
   321  func TestSanitizeHtml(t *testing.T) {
   322  	expected := "hu3 br festa"
   323  
   324  	result := sanitizeHtmlString("<b>hu3 br festa</b>")
   325  
   326  	assert.Equal(t, expected, result, "O texto não deve conter HTML tags")
   327  }
   328  
   329  func TestUnscapeHtml(t *testing.T) {
   330  	var expected template.HTML
   331  	expected = "ó"
   332  
   333  	result := unescapeHtmlString("&#243;")
   334  
   335  	assert.Equal(t, expected, result, "A string não deve ter caracteres Unicode")
   336  }
   337  
   338  func TestSanitizeCep(t *testing.T) {
   339  	for _, fact := range sanitizeCepParameters {
   340  		result := extractNumbers(fact.Input.(string))
   341  		assert.Equal(t, fact.Expected, result, "o zipcode deve conter apenas números")
   342  	}
   343  }
   344  
   345  func TestDVOurNumberMod11BradescoShopFacil(t *testing.T) {
   346  	wallet := "19"
   347  	for _, fact := range mod11BradescoShopFacilDvParameters {
   348  		result := mod11BradescoShopFacilDv(fact.Input.(string), wallet)
   349  		assert.Equal(t, fact.Expected, result, "o dígito verificador deve ser equivalente ao OurNumber")
   350  	}
   351  }
   352  
   353  func TestEscape(t *testing.T) {
   354  	expected := "KM 5,00    "
   355  
   356  	result := escapeStringOnJson("KM 5,00 \t \f \r \b")
   357  
   358  	assert.Equal(t, expected, result, "O texto deve ser escapado")
   359  }
   360  
   361  func TestRemoveCharacterSpecial(t *testing.T) {
   362  	expected := "Texto com carácter especial   -"
   363  
   364  	result := removeSpecialCharacter("Texto? com \"carácter\" especial * ' -")
   365  
   366  	assert.Equal(t, expected, result, "Os caracteres especiais devem ser removidos")
   367  }
   368  
   369  func TestCitiBankSanitizeString(t *testing.T) {
   370  	for _, fact := range sanitizeCitibankSpecialCharacteresParameters {
   371  		input := fact.Input.(string)
   372  		result := sanitizeCitibankSpecialCharacteres(input)
   373  		assert.Equal(t, fact.Expected, result, "Caracteres especiais e acentos devem ser removidos")
   374  	}
   375  }
   376  
   377  func TestClearStringCaixa(t *testing.T) {
   378  	for _, fact := range clearStringCaixaParameters {
   379  		result := clearStringCaixa(fact.Input.(string))
   380  		assert.Equal(t, fact.Expected, result, "Deve-se limpar uma string corretamente")
   381  	}
   382  }
   383  
   384  func TestTruncateOnly(t *testing.T) {
   385  	for _, fact := range truncateOnlyParameters {
   386  		result := truncateOnly(fact.Input.(string), fact.Length)
   387  		assert.Equal(t, fact.Expected, result, "Deve-se truncar uma string corretamente")
   388  	}
   389  }
   390  
   391  func TestDatePlusDays(t *testing.T) {
   392  	var daysToAdd uint = 2
   393  	dateNow := time.Now()
   394  	dateExpected := dateNow.UTC().Add(time.Hour * 24 * time.Duration(daysToAdd))
   395  
   396  	result := datePlusDays(dateNow, daysToAdd)
   397  
   398  	assert.Equal(t, dateExpected, result, "Deve incrementar na data, os dias passados no método")
   399  }
   400  
   401  func TestDatePlusDaysConsideringZeroAsStart(t *testing.T) {
   402  	var daysPassedForTheMethod uint = 3
   403  	var daysCountingFromZero uint = 2
   404  	dateNow := time.Now()
   405  	dateExpected := dateNow.UTC().Add(time.Hour * 24 * time.Duration(daysCountingFromZero))
   406  
   407  	result := datePlusDaysConsideringZeroAsStart(dateNow, daysPassedForTheMethod)
   408  
   409  	assert.Equal(t, dateExpected, result, "Deve incrementar na data, os dias passados no método, considerando o zero como start")
   410  }
   411  
   412  func TestFloat64ToStringWith2f(t *testing.T) {
   413  	format := "%.2f"
   414  	for _, fact := range float64ToStringParameters {
   415  		result := float64ToString(format, fact.Input.(float64))
   416  		assert.Equal(t, fact.Expected, result, "Deve formatar o float com duas casas decimais e retornar como string")
   417  	}
   418  }
   419  
   420  func TestDatePlusDaysLocalTime(t *testing.T) {
   421  	var daysToAdd uint = 2
   422  	dateNow := time.Now()
   423  	dateExpected := dateNow.Add(time.Hour * 24 * time.Duration(daysToAdd))
   424  
   425  	result := datePlusDaysLocalTime(dateNow, daysToAdd)
   426  
   427  	assert.Equal(t, dateExpected, result, "Deve incrementar na data, os dias passados no método, considerando o local time")
   428  }
   429  
   430  func TestCalculateFees(t *testing.T) {
   431  	for _, fact := range calculateFeesParameters {
   432  		testFee := fact.Input.(TestFee)
   433  		result := calculateFees(testFee.AmountFee, testFee.PercentageFee, testFee.TitleAmount)
   434  		assert.Equal(t, fact.Expected, result, fmt.Sprintf("CalculateFees - Linha %d: Deve calcular corretamente o Fees", testFee.line))
   435  	}
   436  }
   437  
   438  func TestCalculateInterestByDay(t *testing.T) {
   439  	for _, fact := range calculateInterestByDayParameters {
   440  		testFee := fact.Input.(TestFee)
   441  		result := calculateInterestByDay(testFee.AmountFee, testFee.PercentageFee, testFee.TitleAmount)
   442  		assert.Equal(t, fact.Expected, result, fmt.Sprintf("CalculateInterestByDay - Linha %d: Deve calcular corretamente o juros", testFee.line))
   443  	}
   444  }
   445  
   446  func TestGetFineInstruction(t *testing.T) {
   447  	expireDateTime, _ := time.Parse("2006-01-02", "2022-03-09")
   448  
   449  	for _, fact := range getFineInstructionParameters {
   450  		title := fact.Input.(models.Title)
   451  		title.ExpireDateTime = expireDateTime
   452  		result := getFineInstruction(title)
   453  		assert.Equal(t, fact.Expected, result, "Deve trazer a instrução de multa corretamente")
   454  	}
   455  }
   456  
   457  func TestGetInterestInstruction(t *testing.T) {
   458  	expireDateTime, _ := time.Parse("2006-01-02", "2022-03-09")
   459  
   460  	for _, fact := range getInterestInstructionParameters {
   461  		title := fact.Input.(models.Title)
   462  		title.ExpireDateTime = expireDateTime
   463  		result := getInterestInstruction(title)
   464  		assert.Equal(t, fact.Expected, result, "Deve trazer a instrução de juros corretamente")
   465  	}
   466  }
   467  
   468  func TestOnlyAlphanumerics(t *testing.T) {
   469  	for _, fact := range alphanumericsStringsParameters {
   470  		result := onlyAlphanumerics(fact.Input.(string))
   471  		assert.Equal(t, fact.Expected, result, "Deve manter todos os caracteres alfanuméricos")
   472  	}
   473  }
   474  
   475  func TestOnlyAlphabetics(t *testing.T) {
   476  	for _, fact := range alphabeticsStringsParameters {
   477  		result := onlyAlphabetics(fact.Input.(string))
   478  		assert.Equal(t, fact.Expected, result, "Deve manter todos os caracteres alfabéticos")
   479  	}
   480  }
   481  
   482  func TestOnlyOneSpace(t *testing.T) {
   483  	for _, fact := range onlyOneSpaceStringsParameters {
   484  		result := onlyOneSpace(fact.Input.(string))
   485  		assert.Equal(t, fact.Expected, result, "Deve manter apenas um espaço entre strings, quando existir")
   486  	}
   487  }
   488  
   489  func TestRemoveAllSpaces(t *testing.T) {
   490  	for _, fact := range removeAllSpacesStringsParameters {
   491  		result := removeAllSpaces(fact.Input.(string))
   492  		assert.Equal(t, fact.Expected, result, "Deve remover qualquer espaço entre strings")
   493  	}
   494  }
   495  
   496  func TestRoundDown(t *testing.T) {
   497  	decimalPlaces := 4
   498  	for _, fact := range roundDownParameters {
   499  		result := roundDown(fact.Input.(float64), decimalPlaces)
   500  		assert.Equal(t, fact.Expected, result, "Deve truncar o número float na quarta casa decimal")
   501  	}
   502  }
   503  
   504  func TestFloat64ToStringTruncate(t *testing.T) {
   505  	decimalPlaces := 4
   506  	numberFormat := "%.4f"
   507  	for _, fact := range float64ToStringTruncateParameters {
   508  		result := float64ToStringTruncate(numberFormat, decimalPlaces, fact.Input.(float64))
   509  		assert.Equal(t, fact.Expected, result, "Converte um número float com 4 decimais")
   510  	}
   511  }
   512  
   513  func TestConvertAmountInCentsToPercent(t *testing.T) {
   514  	var totalAmount uint64 = 2000
   515  	var amount uint64 = 1
   516  	percentageExpected := 0.05
   517  	result := convertAmountInCentsToPercent(totalAmount, amount)
   518  	assert.Equal(t, percentageExpected, result, "Deve retornar a quantidade em porcento de amount dado um totalAmount")
   519  }
   520  
   521  func TestConvertAmountInCentsToPercentPerDay(t *testing.T) {
   522  	var totalAmount uint64 = 3000
   523  	var amount uint64 = 1
   524  	percentageExpected := 1.0
   525  	result := convertAmountInCentsToPercentPerDay(totalAmount, amount)
   526  	assert.Equal(t, percentageExpected, result, "Deve retornar a quantidade em porcento de amount dado um totalAmount por dia")
   527  }