fix platform workflow integrity and permissions
This commit is contained in:
@@ -2,9 +2,13 @@ package common
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func TestFilterFieldsKeepsOnlyAllowedKeys(t *testing.T) {
|
||||
@@ -14,6 +18,24 @@ func TestFilterFieldsKeepsOnlyAllowedKeys(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOperationalQueriesExcludeArchivedRecords(t *testing.T) {
|
||||
sqlDatabase, _, err := sqlmock.New()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer sqlDatabase.Close()
|
||||
database, err := gorm.Open(postgres.New(postgres.Config{Conn: sqlDatabase}), &gorm.Config{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
statement := database.ToSQL(func(tx *gorm.DB) *gorm.DB {
|
||||
return ActiveRecords(tx.Model(&models.EcProduct{})).Find(&[]models.EcProduct{})
|
||||
})
|
||||
if !strings.Contains(statement, `status <> 3`) {
|
||||
t.Fatalf("archive filter missing from operational query: %s", statement)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceResponseStripsInternalIDsRecursively(t *testing.T) {
|
||||
got := ResourceResponse(map[string]any{
|
||||
"id": uint64(1), "identity": "root",
|
||||
@@ -56,3 +78,33 @@ func TestCommonMethodModesRemainHTTPCompatible(t *testing.T) {
|
||||
t.Fatal("standard HTTP methods unavailable")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenericStatusRejectsDomainLifecycleValues(t *testing.T) {
|
||||
for _, status := range []int{StatusDraft, StatusEnable, StatusDisable, StatusArchived, StatusFrozen} {
|
||||
if !IsGenericRecordStatus(status) {
|
||||
t.Fatalf("generic status %d was rejected", status)
|
||||
}
|
||||
}
|
||||
if IsGenericRecordStatus(StatusCompleted) {
|
||||
t.Fatal("business lifecycle status was accepted as generic entity status")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommerceAndFinanceRejectInvalidAmounts(t *testing.T) {
|
||||
tests := []struct {
|
||||
model any
|
||||
values map[string]any
|
||||
}{
|
||||
{&models.EcProduct{}, map[string]any{"product_code": "p", "name": "P", "price_amount": -1.0}},
|
||||
{&models.EcCart{}, map[string]any{"quantity": 0.0}},
|
||||
{&models.EcOrder{}, map[string]any{"order_no": "o", "total_amount": -1.0}},
|
||||
{&models.EcOrderItem{}, map[string]any{"product_snapshot": "{}", "quantity": -1.0, "sale_amount": 1.0}},
|
||||
{&models.EcReview{}, map[string]any{"score": 6.0, "content": "bad"}},
|
||||
{&models.FinPayment{}, map[string]any{"channel": "wallet", "amount": -1.0}},
|
||||
}
|
||||
for _, test := range tests {
|
||||
if ValidateResourceValues(test.model, test.values, true) == nil {
|
||||
t.Fatalf("%T accepted invalid values %#v", test.model, test.values)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user