Private
Public Access
añadidos tests y hecho workflow de testing
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
1e74e4363e
commit
37f1741a77
12 files changed
+391
No files matched your search
@@ -0,0 +1,66 @@
|
||||
package stock
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"repuestera_back/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var dbAvailable bool
|
||||
|
||||
func newStockContext(t *testing.T, method, path string, body any, params gin.Params) (*gin.Context, *httptest.ResponseRecorder) {
|
||||
t.Helper()
|
||||
gin.SetMode(gin.TestMode)
|
||||
recorder := httptest.NewRecorder()
|
||||
context, _ := gin.CreateTestContext(recorder)
|
||||
var payload []byte
|
||||
if body != nil {
|
||||
payload, _ = json.Marshal(body)
|
||||
}
|
||||
request, err := http.NewRequest(method, path, bytes.NewReader(payload))
|
||||
if err != nil {
|
||||
t.Fatalf("no se pudo crear la request: %v", err)
|
||||
}
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
context.Request = request
|
||||
context.Params = params
|
||||
context.Set("userID", uint(1))
|
||||
context.Set(utils.ContextEmpresaIDKey, uint(0))
|
||||
return context, recorder
|
||||
}
|
||||
|
||||
func newIntegrationContext(t *testing.T, method, path string, body any, params gin.Params) (*gin.Context, *httptest.ResponseRecorder) {
|
||||
t.Helper()
|
||||
if !dbAvailable {
|
||||
t.Skip("base de datos no disponible")
|
||||
}
|
||||
gin.SetMode(gin.TestMode)
|
||||
recorder := httptest.NewRecorder()
|
||||
context, _ := gin.CreateTestContext(recorder)
|
||||
var payload []byte
|
||||
if body != nil {
|
||||
payload, _ = json.Marshal(body)
|
||||
}
|
||||
request, err := http.NewRequest(method, path, bytes.NewReader(payload))
|
||||
if err != nil {
|
||||
t.Fatalf("no se pudo crear la request: %v", err)
|
||||
}
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
context.Request = request
|
||||
context.Params = params
|
||||
context.Set("userID", uint(1))
|
||||
context.Set(utils.ContextEmpresaIDKey, uint(1))
|
||||
return context, recorder
|
||||
}
|
||||
|
||||
func requireDB(t *testing.T) {
|
||||
if !dbAvailable {
|
||||
t.Skip("base de datos no disponible")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user