forked from ebhomengo/niki
1
0
Fork 0
Signed-off-by: Reza Mobaraki <rezam578@gmail.com>
This commit is contained in:
Reza Mobaraki 2024-08-28 01:57:16 +03:30
parent 73af8d30f9
commit a43e973b01
No known key found for this signature in database
GPG Key ID: 922CBCF25B541A6F
1 changed files with 19 additions and 19 deletions

View File

@ -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
}