<commit_before>package bradescoNetEmpresa

import (
	"testing"
	"time"

	"github.com/mundipagg/boleto-api/env"
	"github.com/mundipagg/boleto-api/mock"
	"github.com/mundipagg/boleto-api/models"
	"github.com/mundipagg/boleto-api/util"
	. "github.com/smartystreets/goconvey/convey"
)

const baseMockJSON = `
{
    "bankNumber": 237,
   "authentication": {
            "Username": "",
            "Password": ""
        },
        "agreement": {
            "agreementNumber": 5822351,
            "wallet": 9,
            "agency": "1111",
            "account": "0062145"
        },
        "title": {
           
            "expireDate": "2050-12-30",
            "amountInCents": 200,
            "ourNumber": 12345678901,
            "instructions": "Não receber após a data de vencimento.",
            "documentNumber": "1234567890"
        },
        "recipient": {
            "name": "Empresa - Boletos",
            "document": {
                "type": "CNPJ",
                "number": "29799428000128"
            },
            "address": {
                "street": "Avenida Miguel Estefno, 2394",
                "complement": "Água Funda",
                "zipCode": "04301-002",
                "city": "São Paulo",
                "stateCode": "SP"
            }
        },
        "buyer": {
            "name": "<NAME>",
            "email": "<EMAIL>",
            "document": {
                "type": "CNPJ",
                "number": "29.799.428/0001-28"
            },
            "address": {
                "street": "Rua Teste",
                "number": "2",
                "complement": "SALA 1",
                "zipCode": "20931-001",
                "district": "Centro",
                "city": "Rio de Janeiro",
                "stateCode": "RJ"
            }
        }
}
`

func TestRegisterBoleto(t *testing.T) {
	env.Config(true, true, true)
	input := new(models.BoletoRequest)
	if err := util.FromJSON(baseMockJSON, input); err != nil {
		t.Fail()
	}
	bank := New()
	go mock.Run("9098")
	time.Sleep(2 * time.Second)

	Convey("Deve-se processar um boleto BradescoNetEmpresa com sucesso", t, func() {
		output, err := bank.ProcessBoleto(input)
		So(err, ShouldBeNil)
		So(output.BarCodeNumber, ShouldNotBeEmpty)
		So(output.DigitableLine, ShouldNotBeEmpty)
		So(output.Errors, ShouldBeEmpty)
	})

	Convey("Deve-se exibir uma mensagem de erro, caso o registro não aconteça com sucesso", t, func() {
		input.Title.AmountInCents = 100
		output, err := bank.ProcessBoleto(input)
		So(err, ShouldBeNil)
		So(output.BarCodeNumber, ShouldBeEmpty)
		So(output.DigitableLine, ShouldBeEmpty)
		So(output.Errors, ShouldNotBeEmpty)
	})
}
<commit_msg>add test<commit_after>package bradescoNetEmpresa

import (
	"testing"
	"time"

	"github.com/mundipagg/boleto-api/env"
	"github.com/mundipagg/boleto-api/mock"
	"github.com/mundipagg/boleto-api/models"
	"github.com/mundipagg/boleto-api/util"
	. "github.com/smartystreets/goconvey/convey"
)

const baseMockJSON = `
{
    "bankNumber": 237,
   "authentication": {
            "Username": "",
            "Password": ""
        },
        "agreement": {
            "agreementNumber": 5822351,
            "wallet": 9,
            "agency": "1111",
            "account": "0062145"
        },
        "title": {
           
            "expireDate": "2050-12-30",
            "amountInCents": 200,
            "ourNumber": 12345678901,
            "instructions": "Não receber após a data de vencimento.",
            "documentNumber": "1234567890"
        },
        "recipient": {
            "name": "<NAME>",
            "document": {
                "type": "CNPJ",
                "number": "29799428000128"
            },
            "address": {
                "street": "Avenida Miguel Estefno, 2394",
                "complement": "Água Funda",
                "zipCode": "04301-002",
                "city": "São Paulo",
                "stateCode": "SP"
            }
        },
        "buyer": {
            "name": "<NAME>",
            "email": "<EMAIL>",
            "document": {
                "type": "CNPJ",
                "number": "29.799.428/0001-28"
            },
            "address": {
                "street": "Rua Teste",
                "number": "2",
                "complement": "SALA 1",
                "zipCode": "20931-001",
                "district": "Centro",
                "city": "Rio de Janeiro",
                "stateCode": "RJ"
            }
        }
}
`

func TestRegisterBoleto(t *testing.T) {
	env.Config(true, true, true)
	input := new(models.BoletoRequest)
	if err := util.FromJSON(baseMockJSON, input); err != nil {
		t.Fail()
	}
	bank := New()
	go mock.Run("9098")
	time.Sleep(2 * time.Second)

	Convey("Deve-se processar um boleto BradescoNetEmpresa com sucesso", t, func() {
		output, err := bank.ProcessBoleto(input)
		So(err, ShouldBeNil)
		So(output.BarCodeNumber, ShouldNotBeEmpty)
		So(output.DigitableLine, ShouldNotBeEmpty)
		So(output.Errors, ShouldBeEmpty)
	})

	Convey("Deve-se exibir uma mensagem de erro, caso o registro não aconteça com sucesso", t, func() {
		input.Title.AmountInCents = 201
		output, err := bank.ProcessBoleto(input)
		So(err, ShouldBeNil)
		So(output.BarCodeNumber, ShouldBeEmpty)
		So(output.DigitableLine, ShouldBeEmpty)
		So(output.Errors, ShouldNotBeEmpty)
	})

	Convey("Deve-se exibir uma mensagem de erro, caso o status code for 500", t, func() {
		input.Title.AmountInCents = 202
		output, err := bank.ProcessBoleto(input)
		So(err, ShouldBeNil)
		So(output.BarCodeNumber, ShouldBeEmpty)
		So(output.DigitableLine, ShouldBeEmpty)
		So(output.Errors, ShouldNotBeEmpty)
	})
}

{'fraction_non_alphanumeric': 0.14677762039660056, 'fraction_numerical': 0.04072237960339943, 'mean_word_length': 1.9700315457413249, 'pattern_counts': {'":': 80, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4323397', 'n_tokens_mistral': 2118, 'n_tokens_neox': 1878, 'n_words': 359}