* H-16: align takeover with channel AI workflow (#2) * feat(conversations): complete manual AI takeover * fix(conversations): align AI takeover flow with channel AI * fix(conversations): close takeover review gaps --------- Co-authored-by: Rogee <rogee@ipao.vip> * feat(shangwutong): sync customer names back to channel (#3) Co-authored-by: Rogee <rogee@ipao.vip> * fix(shangwutong): close contact sync review gaps (#4) Co-authored-by: Rogee <rogee@ipao.vip> * H-28: harden Shangwutong CID sync (#5) * fix(shangwutong): close contact sync review gaps * fix(shangwutong): harden CID sync boundaries --------- Co-authored-by: Rogee <rogee@ipao.vip> * fix(conversations): sync AI takeover exit in realtime (#6) Co-authored-by: Rogee <rogee@ipao.vip> * test(shangwutong): cover CID rename reliability (#7) Co-authored-by: Rogee <rogee@ipao.vip> * H-43: fix WEB Captain takeover E2E flow (#8) * test(shangwutong): cover CID rename reliability * H-43: fix WEB Captain takeover flow * H-48: preserve compatible provider model * H-49: make Captain takeover atomic * H-50: prevent duplicate widget initialization --------- Co-authored-by: Rogee <rogee@ipao.vip> * H-55: make Captain bindings atomic (#9) Co-authored-by: Rogee <rogee@ipao.vip> * H-60: harden Captain migration rollback and concurrency * chore(agent): baseline — uncommitted work from the local directory * H-335: add safe Captain skills and user deactivation * H-338: close auth and Captain review blockers * H-338: close assignment and session races * H-338: close assignment and websocket invalidation gaps * H-338: enforce assignment write invariants --------- Co-authored-by: Rogee <rogee@ipao.vip>
34 lines
1.5 KiB
Go
34 lines
1.5 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/gochat/gochat/internal/model"
|
|
"github.com/gochat/gochat/internal/repository"
|
|
"github.com/stretchr/testify/require"
|
|
"gorm.io/driver/sqlite"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func TestAssignableAgentsExcludeInactiveUsers(t *testing.T) {
|
|
db, err := gorm.Open(sqlite.Open("file:assignable-active?mode=memory&cache=shared"), &gorm.Config{})
|
|
require.NoError(t, err)
|
|
require.NoError(t, db.AutoMigrate(&model.Account{}, &model.User{}, &model.AccountUser{}))
|
|
account := model.Account{Name: "account"}
|
|
require.NoError(t, db.Create(&account).Error)
|
|
active := model.User{Name: "Active", Email: "active@example.com", Active: true}
|
|
inactive := model.User{Name: "Inactive", Email: "inactive@example.com", Active: true}
|
|
require.NoError(t, db.Create(&active).Error)
|
|
require.NoError(t, db.Create(&inactive).Error)
|
|
require.NoError(t, db.Model(&inactive).Update("active", false).Error)
|
|
require.NoError(t, db.Create(&model.AccountUser{AccountID: account.ID, UserID: active.ID, Role: "administrator"}).Error)
|
|
require.NoError(t, db.Create(&model.AccountUser{AccountID: account.ID, UserID: inactive.ID, Role: "administrator"}).Error)
|
|
|
|
svc := NewAssignableAgentService(repository.NewInboxMemberRepo(db), repository.NewUserRepo(db), repository.NewAccountRepo(db), repository.NewConversationRepo(db))
|
|
agents, err := svc.FindAssignableAgents(context.Background(), account.ID, nil)
|
|
require.NoError(t, err)
|
|
require.Len(t, agents, 1)
|
|
require.Equal(t, active.ID, agents[0].ID)
|
|
}
|