Created
August 11, 2020 13:34
-
-
Save jeffotoni/78e6ff340d4881b2d6fbc9b5bc5f5ad2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package handler | |
import ( | |
"bytes" | |
"encoding/json" | |
"net/http" | |
"net/http/httptest" | |
"strings" | |
"testing" | |
"github.com/stretchr/testify/assert" | |
) | |
func TestScore_Handle(t *testing.T) { | |
requestBody := `[ | |
{ | |
"id": "5f20325488b6d415454025af", | |
"value": 768.29, | |
"paid_at": "2019-03-25 07:23:20", | |
"ip_location": "SC/BR", | |
"card_hold_name": "Ashlee Swanson", | |
"customer": { | |
"id": "5f203254077bb9e7bae8056f", | |
"name": "Ashlee Swanson", | |
"birth_date": "2005-04-18", | |
"state": "SC/BR", | |
"phone": "48 98466-8473" | |
} | |
}, | |
{ | |
"id": "5f20325459b82a71bb5e7aec", | |
"value": 639.06, | |
"paid_at": "2019-10-13 02:33:15", | |
"ip_location": "PR/BR", | |
"card_hold_name": "Warren Richards", | |
"customer": { | |
"id": "5f203254042fa643c98a3be6", | |
"name": "Warren Richards", | |
"birth_date": "1985-09-29", | |
"state": "PR/BR", | |
"phone": "71 98901-4859" | |
} | |
} | |
] | |
` | |
responseBody := ` | |
{ | |
"id":ID_REGEX, | |
"value": | |
} | |
` | |
rq := httptest.NewRequest(http.MethodPost, "/v1/score", strings.NewReader(requestBody)) | |
rw := httptest.NewRecorder() | |
Score(rw, rq) | |
assert.Equal(t, http.StatusOK, rw.Code) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment