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

     1  // +build integration !unit
     2  
     3  package api
     4  
     5  import (
     6  	"encoding/json"
     7  	"net/http"
     8  	"net/http/httptest"
     9  	"testing"
    10  
    11  	"github.com/mundipagg/boleto-api/models"
    12  	"github.com/stretchr/testify/assert"
    13  )
    14  
    15  func TestGetBoleto_WhenNotFoundKeys_ShouldReturnNotFound(t *testing.T) {
    16  	expected := models.ErrorResponse{Code: "MP404", Message: "Not Found"}
    17  
    18  	router := mockInstallApi()
    19  	w := httptest.NewRecorder()
    20  	req, _ := http.NewRequest("GET", "/boleto?fmt=html&id=1234567890&pk=1234567890", nil)
    21  	router.ServeHTTP(w, req)
    22  
    23  	var response models.BoletoResponse
    24  	err := json.Unmarshal(w.Body.Bytes(), &response)
    25  
    26  	assert.Nil(t, err)
    27  	assert.Equal(t, 404, w.Code)
    28  	assert.Equal(t, 1, len(response.Errors))
    29  	assert.Equal(t, expected.Code, response.Errors[0].Code, "O erro code deverá ser mapeado corretamente")
    30  	assert.Equal(t, expected.Message, response.Errors[0].Message, "O erro message deverá ser mapeado corretamente")
    31  
    32  }