diff --git a/delivery/http_server/end2end/request_helper_test.go b/delivery/http_server/end2end/request_helper_test.go index c46c745..7b8c17c 100644 --- a/delivery/http_server/end2end/request_helper_test.go +++ b/delivery/http_server/end2end/request_helper_test.go @@ -13,6 +13,25 @@ import ( "net/http/httptest" ) +// CreateRequest is a utility function to create and send HTTP requests +func CreateRequest(method, url, token string, body interface{}) *httptest.ResponseRecorder { + var buf bytes.Buffer + if body != nil { + err := json.NewEncoder(&buf).Encode(body) + if err != nil { + log.Fatalf("could not encode body: %v", err) + } + } + + req := httptest.NewRequest(method, url, &buf) + req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON) + req.Header.Set(echo.HeaderAuthorization, fmt.Sprintf("Bearer %s", token)) + + rec := httptest.NewRecorder() + testServer.Serve(rec, req) + return rec +} + // LoginBenefactor is a utility function to login a benefactor and return the access token func LoginBenefactor(phoneNumber string) string { sendOTPRes, err := services.BenefactorSvc.SendOtp(context.Background(), param.SendOtpRequest{ @@ -32,22 +51,3 @@ func LoginBenefactor(phoneNumber string) string { return registerRes.Tokens.AccessToken } - -// CreateRequest is a utility function to create and send HTTP requests -func CreateRequest(method, url, token string, body interface{}) *httptest.ResponseRecorder { - var buf bytes.Buffer - if body != nil { - err := json.NewEncoder(&buf).Encode(body) - if err != nil { - log.Fatalf("could not encode body: %v", err) - } - } - - req := httptest.NewRequest(method, url, &buf) - req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON) - req.Header.Set(echo.HeaderAuthorization, fmt.Sprintf("Bearer %s", token)) - - rec := httptest.NewRecorder() - testServer.Serve(rec, req) - return rec -}