Add default-web promo code CRUD, user/channel concurrency controls, and domestic Alipay/Wxpay billing settings. Harden promo code validation and preserve explicit zero concurrency limits with backend regression coverage.
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package model
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestChannelUpdatePersistsExplicitZeroConcurrencyLimit(t *testing.T) {
|
|
truncateTables(t)
|
|
require.NoError(t, DB.AutoMigrate(&Ability{}))
|
|
t.Cleanup(func() {
|
|
DB.Exec("DELETE FROM abilities")
|
|
})
|
|
|
|
channel := &Channel{
|
|
Type: 1,
|
|
Key: "test-key",
|
|
Status: 1,
|
|
Name: "test-channel",
|
|
Models: "gpt-test",
|
|
Group: "default",
|
|
ConcurrencyLimit: 3,
|
|
}
|
|
require.NoError(t, DB.Create(channel).Error)
|
|
|
|
channel.ConcurrencyLimit = 0
|
|
require.NoError(t, channel.Update("concurrency_limit"))
|
|
|
|
var reloaded Channel
|
|
require.NoError(t, DB.First(&reloaded, channel.Id).Error)
|
|
require.Equal(t, 0, reloaded.ConcurrencyLimit)
|
|
}
|
|
|
|
func TestChannelUpdateKeepsZeroConcurrencyLimitImplicitByDefault(t *testing.T) {
|
|
truncateTables(t)
|
|
require.NoError(t, DB.AutoMigrate(&Ability{}))
|
|
t.Cleanup(func() {
|
|
DB.Exec("DELETE FROM abilities")
|
|
})
|
|
|
|
channel := &Channel{
|
|
Type: 1,
|
|
Key: "test-key",
|
|
Status: 1,
|
|
Name: "test-channel",
|
|
Models: "gpt-test",
|
|
Group: "default",
|
|
ConcurrencyLimit: 3,
|
|
}
|
|
require.NoError(t, DB.Create(channel).Error)
|
|
|
|
update := &Channel{
|
|
Id: channel.Id,
|
|
Name: "renamed-channel",
|
|
Models: channel.Models,
|
|
Group: channel.Group,
|
|
ConcurrencyLimit: 0,
|
|
}
|
|
require.NoError(t, update.Update())
|
|
|
|
var reloaded Channel
|
|
require.NoError(t, DB.First(&reloaded, channel.Id).Error)
|
|
require.Equal(t, "renamed-channel", reloaded.Name)
|
|
require.Equal(t, 3, reloaded.ConcurrencyLimit)
|
|
}
|