Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/shopify"
|
||||
"github.com/descrybe/descrybe-v2/apps/api/internal/woocommerce"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func TestHandleUpdateShopifyScheduleRejectsInvalidJSON(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := &Server{Shopify: &shopify.Service{}}
|
||||
ctx := context.WithValue(context.Background(), ctxCompanyID, uuid.MustParse("11111111-1111-1111-1111-111111111111"))
|
||||
ctx = context.WithValue(ctx, ctxRole, "admin")
|
||||
rec := httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodPut, "/api/shopify/schedule", strings.NewReader(`{bad`))
|
||||
req = req.WithContext(ctx)
|
||||
s.handleUpdateShopifySchedule(rec, req)
|
||||
if rec.Code != http.StatusBadRequest {
|
||||
t.Fatalf("status=%d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleUpdateShopifyScheduleRejectsInvalidInterval(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := &Server{Shopify: &shopify.Service{}} // Pool nil — interval check runs before DB
|
||||
ctx := context.WithValue(context.Background(), ctxCompanyID, uuid.MustParse("11111111-1111-1111-1111-111111111111"))
|
||||
ctx = context.WithValue(ctx, ctxRole, "admin")
|
||||
rec := httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodPut, "/api/shopify/schedule", strings.NewReader(`{"schedule_interval_hours":999,"schedule_paused":false}`))
|
||||
req = req.WithContext(ctx)
|
||||
s.handleUpdateShopifySchedule(rec, req)
|
||||
if rec.Code != http.StatusBadRequest {
|
||||
t.Fatalf("status=%d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleSyncShopifyRejectsInvalidJSON(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := &Server{} // Shopify unused — DecodeJSONOptional fails first
|
||||
rec := httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/shopify/sync", strings.NewReader(`{"status":`))
|
||||
s.handleSyncShopify(rec, req)
|
||||
if rec.Code != http.StatusBadRequest {
|
||||
t.Fatalf("status=%d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleUpdateWooScheduleRejectsInvalidInterval(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := &Server{Woo: &woocommerce.Service{}}
|
||||
ctx := context.WithValue(context.Background(), ctxCompanyID, uuid.MustParse("11111111-1111-1111-1111-111111111111"))
|
||||
ctx = context.WithValue(ctx, ctxRole, "admin")
|
||||
rec := httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodPut, "/api/woocommerce/schedule", strings.NewReader(`{"schedule_interval_hours":-2,"schedule_paused":true}`))
|
||||
req = req.WithContext(ctx)
|
||||
s.handleUpdateWooSchedule(rec, req)
|
||||
if rec.Code != http.StatusBadRequest {
|
||||
t.Fatalf("status=%d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleSyncWooRejectsInvalidJSON(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := &Server{}
|
||||
rec := httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/woocommerce/sync", strings.NewReader(`[`))
|
||||
s.handleSyncWoo(rec, req)
|
||||
if rec.Code != http.StatusBadRequest {
|
||||
t.Fatalf("status=%d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user