Files
new-api-custom/model/ability_group_test.go
T

32 lines
1.3 KiB
Go

package model
import (
"testing"
"github.com/QuantumNous/new-api/common"
"github.com/QuantumNous/new-api/constant"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetEnabledGroupSetRequiresEnabledAbilityAndChannel(t *testing.T) {
resetPricingEndpointTestTables(t)
require.NoError(t, DB.Create(&[]Channel{
{Id: 1, Type: constant.ChannelTypeOpenAI, Key: "active-key", Name: "active", Status: common.ChannelStatusEnabled},
{Id: 2, Type: constant.ChannelTypeOpenAI, Key: "manual-key", Name: "manual", Status: common.ChannelStatusManuallyDisabled},
{Id: 3, Type: constant.ChannelTypeOpenAI, Key: "auto-key", Name: "auto", Status: common.ChannelStatusAutoDisabled},
{Id: 4, Type: constant.ChannelTypeOpenAI, Key: "ability-key", Name: "ability", Status: common.ChannelStatusEnabled},
}).Error)
require.NoError(t, DB.Create(&[]Ability{
{Group: "active", Model: "gpt-active", ChannelId: 1, Enabled: true},
{Group: "manual-disabled", Model: "gpt-manual", ChannelId: 2, Enabled: true},
{Group: "auto-disabled", Model: "gpt-auto", ChannelId: 3, Enabled: true},
{Group: "ability-disabled", Model: "gpt-ability", ChannelId: 4, Enabled: false},
}).Error)
groups, err := GetEnabledGroupSet()
require.NoError(t, err)
assert.Equal(t, map[string]struct{}{"active": {}}, groups)
}