forked from ebhomengo/niki
parent
73af8d30f9
commit
a43e973b01
|
@ -13,6 +13,25 @@ import (
|
||||||
"net/http/httptest"
|
"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
|
// LoginBenefactor is a utility function to login a benefactor and return the access token
|
||||||
func LoginBenefactor(phoneNumber string) string {
|
func LoginBenefactor(phoneNumber string) string {
|
||||||
sendOTPRes, err := services.BenefactorSvc.SendOtp(context.Background(), param.SendOtpRequest{
|
sendOTPRes, err := services.BenefactorSvc.SendOtp(context.Background(), param.SendOtpRequest{
|
||||||
|
@ -32,22 +51,3 @@ func LoginBenefactor(phoneNumber string) string {
|
||||||
|
|
||||||
return registerRes.Tokens.AccessToken
|
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
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue