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

     1  package pefisa
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/mundipagg/boleto-api/mock"
     7  	"github.com/mundipagg/boleto-api/models"
     8  	"github.com/mundipagg/boleto-api/test"
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  var boletoTypeParameters = []test.Parameter{
    13  	{Input: models.Title{BoletoType: ""}, Expected: "1"},
    14  	{Input: models.Title{BoletoType: "NSA"}, Expected: "1"},
    15  	{Input: models.Title{BoletoType: "DM"}, Expected: "1"},
    16  	{Input: models.Title{BoletoType: "DS"}, Expected: "2"},
    17  	{Input: models.Title{BoletoType: "NP"}, Expected: "3"},
    18  	{Input: models.Title{BoletoType: "SE"}, Expected: "4"},
    19  	{Input: models.Title{BoletoType: "CH"}, Expected: "10"},
    20  	{Input: models.Title{BoletoType: "OUT"}, Expected: "99"},
    21  }
    22  
    23  func TestProcessBoleto_WhenServiceRespondsSuccessfully_ShouldHasSuccessfulBoletoResponse(t *testing.T) {
    24  	mock.StartMockService("9044")
    25  
    26  	input := newStubBoletoRequestPefisa().Build()
    27  	bank := New()
    28  
    29  	output, _ := bank.ProcessBoleto(input)
    30  
    31  	test.AssertProcessBoletoWithSuccess(t, output)
    32  }
    33  
    34  func TestProcessBoleto_WhenServiceRespondsFailed_ShouldHasFailedBoletoResponse(t *testing.T) {
    35  	mock.StartMockService("9043")
    36  
    37  	input := newStubBoletoRequestPefisa().WithAmountInCents(201).Build()
    38  	bank := New()
    39  
    40  	output, _ := bank.ProcessBoleto(input)
    41  
    42  	test.AssertProcessBoletoFailed(t, output)
    43  }
    44  
    45  func TestGetBoletoType_WhenCalled_ShouldBeMapTypeSuccessful(t *testing.T) {
    46  	request := newStubBoletoRequestPefisa().Build()
    47  	for _, fact := range boletoTypeParameters {
    48  		request.Title = fact.Input.(models.Title)
    49  		_, result := getBoletoType(request)
    50  		assert.Equal(t, fact.Expected, result, "Deve mapear o boleto type corretamente")
    51  	}
    52  }
    53  
    54  func TestTemplateResponse_WhenRequestHasTabCharacter_ShouldBeParsedSuccessful(t *testing.T) {
    55  	mock.StartMockService("9045")
    56  	input := newStubBoletoRequestPefisa().WithBuyerName("Usuario \tTeste").Build()
    57  	bank := New()
    58  
    59  	output, _ := bank.ProcessBoleto(input)
    60  
    61  	test.AssertProcessBoletoWithSuccess(t, output)
    62  }