Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

56 righe
2.7 KiB

  1. package service
  2. import (
  3. "testing"
  4. "github.com/QuantumNous/new-api/common"
  5. "github.com/QuantumNous/new-api/constant"
  6. "github.com/QuantumNous/new-api/model"
  7. "github.com/stretchr/testify/assert"
  8. "github.com/stretchr/testify/require"
  9. )
  10. func TestGetUserConcreteTokenGroups(t *testing.T) {
  11. db := setupDoubaoAssetChannelDB(t)
  12. for i, group := range []string{"vip", "default", "default", "auto", ""} {
  13. require.NoError(t, db.Create(&model.Token{Id: i + 1, UserId: 10, Key: "key-" + string(rune('0'+i)), Group: group}).Error)
  14. }
  15. groups, err := model.GetUserConcreteTokenGroups(10)
  16. require.NoError(t, err)
  17. assert.Equal(t, []string{"default", "vip"}, groups)
  18. }
  19. func TestGetVideoAssetChannelCandidatesFiltersGroupAndStatus(t *testing.T) {
  20. db := setupDoubaoAssetChannelDB(t)
  21. createDoubaoAssetChannelForTest(t, db, 7, constant.ChannelTypeDoubaoVideoCompatibleAiping, "default", "key", common.ChannelStatusEnabled)
  22. createDoubaoAssetChannelForTest(t, db, 16, constant.ChannelTypeDoubaoVideoCompatibleTianyiYun, "default", "key", common.ChannelStatusEnabled)
  23. createDoubaoAssetChannelForTest(t, db, 17, constant.ChannelTypeDoubaoVideoCompatibleTianyiYun, "default", "key", common.ChannelStatusAutoDisabled)
  24. createDoubaoAssetChannelForTest(t, db, 18, constant.ChannelTypeDoubaoVideoCompatibleTianyiYun, "vip", "key", common.ChannelStatusEnabled)
  25. createDoubaoAssetChannelForTest(t, db, 19, constant.ChannelTypeChinaMobileSeedance, "default", "\n", common.ChannelStatusEnabled)
  26. candidates, err := GetVideoAssetChannelCandidates("default", VideoAssetFamilySeedance)
  27. require.NoError(t, err)
  28. require.Len(t, candidates, 2)
  29. assert.Equal(t, []int{7, 16}, []int{candidates[0].Id, candidates[1].Id})
  30. }
  31. func TestClearVideoAssetChannelBindingClearsOnlyFamily(t *testing.T) {
  32. db := setupDoubaoAssetChannelDB(t)
  33. createDoubaoAssetChannelForTest(t, db, 7, constant.ChannelTypeDoubaoVideoCompatibleAiping, "default", "key", common.ChannelStatusEnabled)
  34. createDoubaoAssetChannelForTest(t, db, 59, constant.ChannelTypeKlingAiping, "default", "key", common.ChannelStatusEnabled)
  35. require.NoError(t, model.BindUserAssetChannel(10, constant.ChannelTypeDoubaoVideoCompatibleAiping, "default", 7))
  36. require.NoError(t, model.BindUserAssetChannel(10, constant.ChannelTypeKlingAiping, "default", 59))
  37. require.NoError(t, ClearVideoAssetChannelBinding(10, "default", VideoAssetFamilySeedance))
  38. seedanceBindings, err := model.GetUserAssetChannelsByTypes(10, VideoAssetChannelTypesForFamily(VideoAssetFamilySeedance), "default")
  39. require.NoError(t, err)
  40. assert.Empty(t, seedanceBindings)
  41. klingBinding, err := model.GetUserAssetChannel(10, constant.ChannelTypeKlingAiping, "default")
  42. require.NoError(t, err)
  43. assert.NotNil(t, klingBinding)
  44. }