Private
Public Access
50 lines
1.5 KiB
Go
50 lines
1.5 KiB
Go
package stock
|
|
|
|
import (
|
|
"testing"
|
|
|
|
ctrl "repuestera_back/controllers/stock"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func TestActualizarObservacion_Validacion(t *testing.T) {
|
|
texto := ""
|
|
for i := 0; i < 61; i++ {
|
|
texto += "a"
|
|
}
|
|
context, recorder := newStockContext(t, "PATCH", "/stock/1/observacion", map[string]any{
|
|
"observacion": texto,
|
|
}, gin.Params{{Key: "id", Value: "1"}})
|
|
ctrl.ActualizarObservacion(context)
|
|
if recorder.Code != 400 {
|
|
t.Fatalf("observación larga: esperado 400, obtenido %d", recorder.Code)
|
|
}
|
|
|
|
context, recorder = newStockContext(t, "PATCH", "/stock/abc/observacion", map[string]any{
|
|
"observacion": "ok",
|
|
}, gin.Params{{Key: "id", Value: "abc"}})
|
|
ctrl.ActualizarObservacion(context)
|
|
if recorder.Code != 400 {
|
|
t.Fatalf("id inválido: esperado 400, obtenido %d", recorder.Code)
|
|
}
|
|
}
|
|
|
|
func TestActualizarObservacion_Integracion(t *testing.T) {
|
|
context, recorder := newIntegrationContext(t, "PATCH", "/stock/1/observacion", map[string]any{
|
|
"observacion": "test integracion",
|
|
}, gin.Params{{Key: "id", Value: "1"}})
|
|
ctrl.ActualizarObservacion(context)
|
|
if recorder.Code != 200 {
|
|
t.Fatalf("actualizar observación: esperado 200, obtenido %d: %s", recorder.Code, recorder.Body.String())
|
|
}
|
|
|
|
context, recorder = newIntegrationContext(t, "PATCH", "/stock/1/observacion", map[string]any{
|
|
"observacion": "",
|
|
}, gin.Params{{Key: "id", Value: "1"}})
|
|
ctrl.ActualizarObservacion(context)
|
|
if recorder.Code != 200 {
|
|
t.Fatalf("vaciar observación: esperado 200, obtenido %d: %s", recorder.Code, recorder.Body.String())
|
|
}
|
|
}
|