@@ -16,6 +16,7 @@ import (
1616 "github.com/coze-dev/coze-loop/backend/kitex_gen/coze/loop/data/domain/dataset_job"
1717 domain_eval_set "github.com/coze-dev/coze-loop/backend/kitex_gen/coze/loop/evaluation/domain/eval_set"
1818 "github.com/coze-dev/coze-loop/backend/kitex_gen/coze/loop/evaluation/eval_set"
19+ "github.com/coze-dev/coze-loop/backend/modules/evaluation/consts"
1920 metricsmock "github.com/coze-dev/coze-loop/backend/modules/evaluation/domain/component/metrics/mocks"
2021 "github.com/coze-dev/coze-loop/backend/modules/evaluation/domain/component/rpc"
2122 rpcmocks "github.com/coze-dev/coze-loop/backend/modules/evaluation/domain/component/rpc/mocks"
@@ -331,6 +332,142 @@ func TestEvaluationSetApplicationImpl_EvaluationSetValidateMultiPartData(t *test
331332 }
332333}
333334
335+ func TestEvaluationSetApplicationImpl_UpdateEvaluationSet (t * testing.T ) {
336+ ctrl := gomock .NewController (t )
337+ defer ctrl .Finish ()
338+
339+ mockAuth := rpcmocks .NewMockIAuthProvider (ctrl )
340+ mockEvalSetSvc := servicemocks .NewMockIEvaluationSetService (ctrl )
341+
342+ app := & EvaluationSetApplicationImpl {
343+ auth : mockAuth ,
344+ evaluationSetService : mockEvalSetSvc ,
345+ }
346+
347+ workspaceID := int64 (3003 )
348+ evaluationSetID := int64 (4004 )
349+ validSet := & entity.EvaluationSet {ID : evaluationSetID , SpaceID : workspaceID + 1 , BaseInfo : & entity.BaseInfo {CreatedBy : & entity.UserInfo {UserID : gptr .Of ("owner" )}}}
350+
351+ baseReq := func () * eval_set.UpdateEvaluationSetRequest {
352+ return & eval_set.UpdateEvaluationSetRequest {
353+ WorkspaceID : workspaceID ,
354+ EvaluationSetID : evaluationSetID ,
355+ Name : gptr .Of ("new name" ),
356+ Description : gptr .Of ("new desc" ),
357+ }
358+ }
359+
360+ tests := []struct {
361+ name string
362+ req * eval_set.UpdateEvaluationSetRequest
363+ setup func ()
364+ wantErr int32
365+ check func (t * testing.T , resp * eval_set.UpdateEvaluationSetResponse )
366+ }{
367+ {
368+ name : "nil req" ,
369+ req : nil ,
370+ setup : func () {
371+ mockEvalSetSvc .EXPECT ().GetEvaluationSet (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).Times (0 )
372+ mockAuth .EXPECT ().AuthorizationWithoutSPI (gomock .Any (), gomock .Any ()).Times (0 )
373+ mockEvalSetSvc .EXPECT ().UpdateEvaluationSet (gomock .Any (), gomock .Any ()).Times (0 )
374+ },
375+ wantErr : errno .CommonInvalidParamCode ,
376+ },
377+ {
378+ name : "get evaluation set error" ,
379+ req : baseReq (),
380+ setup : func () {
381+ mockEvalSetSvc .EXPECT ().GetEvaluationSet (gomock .Any (), gptr .Of (workspaceID ), evaluationSetID , gomock .Nil ()).Return (nil , errors .New ("get err" ))
382+ mockAuth .EXPECT ().AuthorizationWithoutSPI (gomock .Any (), gomock .Any ()).Times (0 )
383+ mockEvalSetSvc .EXPECT ().UpdateEvaluationSet (gomock .Any (), gomock .Any ()).Times (0 )
384+ },
385+ wantErr : - 1 ,
386+ },
387+ {
388+ name : "evaluation set not found" ,
389+ req : baseReq (),
390+ setup : func () {
391+ mockEvalSetSvc .EXPECT ().GetEvaluationSet (gomock .Any (), gptr .Of (workspaceID ), evaluationSetID , gomock .Nil ()).Return (nil , nil )
392+ mockAuth .EXPECT ().AuthorizationWithoutSPI (gomock .Any (), gomock .Any ()).Times (0 )
393+ mockEvalSetSvc .EXPECT ().UpdateEvaluationSet (gomock .Any (), gomock .Any ()).Times (0 )
394+ },
395+ wantErr : errno .ResourceNotFoundCode ,
396+ },
397+ {
398+ name : "auth failed" ,
399+ req : baseReq (),
400+ setup : func () {
401+ mockEvalSetSvc .EXPECT ().GetEvaluationSet (gomock .Any (), gptr .Of (workspaceID ), evaluationSetID , gomock .Nil ()).Return (validSet , nil )
402+ mockAuth .EXPECT ().AuthorizationWithoutSPI (gomock .Any (), gomock .AssignableToTypeOf (& rpc.AuthorizationWithoutSPIParam {})).Return (errorx .NewByCode (errno .CommonNoPermissionCode ))
403+ mockEvalSetSvc .EXPECT ().UpdateEvaluationSet (gomock .Any (), gomock .Any ()).Times (0 )
404+ },
405+ wantErr : errno .CommonNoPermissionCode ,
406+ },
407+ {
408+ name : "update service error" ,
409+ req : baseReq (),
410+ setup : func () {
411+ mockEvalSetSvc .EXPECT ().GetEvaluationSet (gomock .Any (), gptr .Of (workspaceID ), evaluationSetID , gomock .Nil ()).Return (validSet , nil )
412+ mockAuth .EXPECT ().AuthorizationWithoutSPI (gomock .Any (), gomock .AssignableToTypeOf (& rpc.AuthorizationWithoutSPIParam {})).Return (nil )
413+ mockEvalSetSvc .EXPECT ().UpdateEvaluationSet (gomock .Any (), gomock .AssignableToTypeOf (& entity.UpdateEvaluationSetParam {})).Return (errors .New ("update err" ))
414+ },
415+ wantErr : - 1 ,
416+ },
417+ {
418+ name : "success" ,
419+ req : baseReq (),
420+ setup : func () {
421+ mockEvalSetSvc .EXPECT ().GetEvaluationSet (gomock .Any (), gptr .Of (workspaceID ), evaluationSetID , gomock .Nil ()).Return (validSet , nil )
422+ mockAuth .EXPECT ().AuthorizationWithoutSPI (gomock .Any (), gomock .AssignableToTypeOf (& rpc.AuthorizationWithoutSPIParam {})).DoAndReturn (func (_ context.Context , p * rpc.AuthorizationWithoutSPIParam ) error {
423+ assert .Equal (t , strconv .FormatInt (validSet .ID , 10 ), p .ObjectID )
424+ assert .Equal (t , workspaceID , p .SpaceID )
425+ assert .Equal (t , validSet .SpaceID , p .ResourceSpaceID )
426+ assert .Equal (t , validSet .BaseInfo .CreatedBy .UserID , p .OwnerID )
427+ if assert .Len (t , p .ActionObjects , 1 ) {
428+ assert .Equal (t , consts .Edit , gptr .Indirect (p .ActionObjects [0 ].Action ))
429+ assert .Equal (t , rpc .AuthEntityType_EvaluationSet , gptr .Indirect (p .ActionObjects [0 ].EntityType ))
430+ }
431+ return nil
432+ })
433+ mockEvalSetSvc .EXPECT ().UpdateEvaluationSet (gomock .Any (), gomock .AssignableToTypeOf (& entity.UpdateEvaluationSetParam {})).DoAndReturn (func (_ context.Context , p * entity.UpdateEvaluationSetParam ) error {
434+ assert .Equal (t , workspaceID , p .SpaceID )
435+ assert .Equal (t , evaluationSetID , p .EvaluationSetID )
436+ assert .Equal (t , gptr .Indirect (baseReq ().Name ), gptr .Indirect (p .Name ))
437+ assert .Equal (t , gptr .Indirect (baseReq ().Description ), gptr .Indirect (p .Description ))
438+ return nil
439+ })
440+ },
441+ check : func (t * testing.T , resp * eval_set.UpdateEvaluationSetResponse ) {
442+ assert .NotNil (t , resp )
443+ },
444+ },
445+ }
446+
447+ for _ , tc := range tests {
448+ t .Run (tc .name , func (t * testing.T ) {
449+ if tc .setup != nil {
450+ tc .setup ()
451+ }
452+ resp , err := app .UpdateEvaluationSet (context .Background (), tc .req )
453+ if tc .wantErr != 0 {
454+ assert .Error (t , err )
455+ if tc .wantErr > 0 {
456+ statusErr , ok := errorx .FromStatusError (err )
457+ assert .True (t , ok )
458+ assert .Equal (t , tc .wantErr , statusErr .Code ())
459+ }
460+ assert .Nil (t , resp )
461+ } else {
462+ assert .NoError (t , err )
463+ if tc .check != nil {
464+ tc .check (t , resp )
465+ }
466+ }
467+ })
468+ }
469+ }
470+
334471func TestEvaluationSetApplicationImpl_GetEvaluationSetItemField (t * testing.T ) {
335472 ctrl := gomock .NewController (t )
336473 defer ctrl .Finish ()
0 commit comments