@@ -3015,30 +3015,39 @@ func (s *ServiceTestSuite) TestCancel() {
30153015
30163016func (s * ServiceTestSuite ) TestAddApprover () {
30173017 s .Run ("should return appeal on success" , func () {
3018- h := newServiceTestHelper ()
3019- defer h .assertExpectations (s .T ())
30203018 appealID := uuid .New ().String ()
30213019 approvalID := uuid .New ().String ()
30223020 approvalName := "test-approval-name"
30233021 newApprover := "[email protected] " 30243022
3025- tc := struct {
3023+ testCases := [] struct {
30263024 name , appealID , approvalID , newApprover string
3027- expectedAppeal * domain.Appeal
3028- expectedApproval * domain.Approval
30293025 }{
3030- name : "with approval ID" ,
3031- appealID : appealID , approvalID : approvalID , newApprover : newApprover ,
3032- expectedAppeal : & domain.Appeal {
3033- ID : appealID ,
3034- Status : domain .AppealStatusPending ,
3035- Approvals : []* domain.Approval {
3036- {
3037- ID : approvalID ,
3038- Name : approvalName ,
3039- Status : domain .ApprovalStatusPending ,
3040- Approvers : []string {
3041- 3026+ {
3027+ name : "with approval ID" ,
3028+ appealID : appealID , approvalID : approvalID , newApprover : newApprover ,
3029+ },
3030+ {
3031+ name : "with approval name" ,
3032+ appealID : appealID , approvalID : approvalName , newApprover : newApprover ,
3033+ },
3034+ }
3035+
3036+ for _ , tc := range testCases {
3037+ s .Run (tc .name , func () {
3038+ h := newServiceTestHelper ()
3039+ defer h .assertExpectations (s .T ())
3040+ expectedAppeal := & domain.Appeal {
3041+ ID : appealID ,
3042+ Status : domain .AppealStatusPending ,
3043+ Approvals : []* domain.Approval {
3044+ {
3045+ ID : approvalID ,
3046+ Name : approvalName ,
3047+ Status : domain .ApprovalStatusPending ,
3048+ Approvers : []string {
3049+ 3050+ },
30423051 },
30433052 },
30443053 Resource : & domain.Resource {},
@@ -3063,112 +3072,20 @@ func (s *ServiceTestSuite) TestAddApprover() {
30633072 h .mockNotifier .EXPECT ().
30643073 Notify (h .ctxMatcher , mock .Anything ).
30653074 Run (func (ctx context.Context , notifications []domain.Notification ) {
3066- s . Len ( notifications , 1 )
3075+ assert . Equal ( s . T (), len ( notifications ) , 1 )
30673076 n := notifications [0 ]
3068- s .Equal (tc .newApprover , n .User )
3069- s .Equal (domain .NotificationTypeApproverNotification , n .Message .Type )
3077+ assert .Equal (s . T (), tc .newApprover , n .User )
3078+ assert .Equal (s . T (), domain .NotificationTypeApproverNotification , n .Message .Type )
30703079 }).
30713080 Return (nil ).Once ()
30723081
30733082 actualAppeal , actualError := h .service .AddApprover (context .Background (), appealID , approvalID , newApprover )
30743083
3075- time.Sleep (time .Second )
30763084 s .NoError (actualError )
30773085 s .Equal (expectedApproval , actualAppeal .Approvals [0 ])
3078- },
3079- }
3080-
3081- s .mockRepository .EXPECT ().
3082- GetByID (mock .MatchedBy (func (ctx context.Context ) bool { return true }), appealID ).
3083- Return (tc .expectedAppeal , nil ).Once ()
3084- s .mockApprovalService .EXPECT ().
3085- AddApprover (mock .MatchedBy (func (ctx context.Context ) bool { return true }), approvalID , newApprover ).
3086- Return (nil ).Once ()
3087- s .mockAuditLogger .EXPECT ().
3088- Log (mock .MatchedBy (func (ctx context.Context ) bool { return true }), appeal .AuditKeyAddApprover , tc .expectedApproval ).Return (nil ).Once ()
3089- s .mockNotifier .EXPECT ().
3090- Notify (mock .MatchedBy (func (ctx context.Context ) bool { return true }), mock .Anything ).
3091- Run (func (ctx context.Context , notifications []domain.Notification ) {
3092- assert .Equal (s .T (), len (notifications ), 1 )
3093- n := notifications [0 ]
3094- ng := n
3095- assert .Equal (s .T (), tc .newApprover , ng .User )
3096- assert .Equal (s .T (), domain .NotificationTypeApproverNotification , ng .Message .Type )
3097- }).
3098- Return (nil ).Once ()
3099-
3100- actualAppeal , actualError := s .service .AddApprover (context .Background (), appealID , approvalID , newApprover )
3101-
3102- s .NoError (actualError )
3103- s .Equal (tc .expectedApproval , actualAppeal .Approvals [0 ])
3104- s .mockRepository .AssertExpectations (s .T ())
3105- s .mockApprovalService .AssertExpectations (s .T ())
3106- })
3107-
3108- s .Run ("should return appeal on success with approval name" , func () {
3109- appealID := uuid .New ().String ()
3110- approvalID := uuid .New ().String ()
3111- approvalName := "test-approval-name"
3112- newApprover := "[email protected] " 31133086
3114- tc := struct {
3115- name , appealID , approvalID , newApprover string
3116- expectedAppeal * domain.Appeal
3117- expectedApproval * domain.Approval
3118- }{
3119- name : "with approval name" ,
3120- appealID : appealID , approvalID : approvalName , newApprover : newApprover ,
3121- expectedAppeal : & domain.Appeal {
3122- ID : appealID ,
3123- Status : domain .AppealStatusPending ,
3124- Approvals : []* domain.Approval {
3125- {
3126- ID : approvalID ,
3127- Name : approvalName ,
3128- Status : domain .ApprovalStatusPending ,
3129- Approvers : []string {
3130- 3131- },
3132- },
3133- },
3134- Resource : & domain.Resource {},
3135- },
3136- expectedApproval : & domain.Approval {
3137- ID : approvalID ,
3138- Name : approvalName ,
3139- Status : domain .ApprovalStatusPending ,
3140- Approvers : []string {
3141- 3142- newApprover ,
3143- },
3144- },
3087+ })
31453088 }
3146-
3147- s .mockRepository .EXPECT ().
3148- GetByID (mock .MatchedBy (func (ctx context.Context ) bool { return true }), appealID ).
3149- Return (tc .expectedAppeal , nil ).Once ()
3150- s .mockApprovalService .EXPECT ().
3151- AddApprover (mock .MatchedBy (func (ctx context.Context ) bool { return true }), approvalID , newApprover ).
3152- Return (nil ).Once ()
3153- s .mockAuditLogger .EXPECT ().
3154- Log (mock .MatchedBy (func (ctx context.Context ) bool { return true }), appeal .AuditKeyAddApprover , tc .expectedApproval ).Return (nil ).Once ()
3155- s .mockNotifier .EXPECT ().
3156- Notify (mock .MatchedBy (func (ctx context.Context ) bool { return true }), mock .Anything ).
3157- Run (func (ctx context.Context , notifications []domain.Notification ) {
3158- assert .Equal (s .T (), len (notifications ), 1 )
3159- n := notifications [0 ]
3160- ng := n
3161- assert .Equal (s .T (), tc .newApprover , ng .User )
3162- assert .Equal (s .T (), domain .NotificationTypeApproverNotification , ng .Message .Type )
3163- }).
3164- Return (nil ).Once ()
3165-
3166- actualAppeal , actualError := s .service .AddApprover (context .Background (), appealID , approvalID , newApprover )
3167-
3168- s .NoError (actualError )
3169- s .Equal (tc .expectedApproval , actualAppeal .Approvals [0 ])
3170- s .mockRepository .AssertExpectations (s .T ())
3171- s .mockApprovalService .AssertExpectations (s .T ())
31723089 })
31733090
31743091 s .Run ("params validation" , func () {
0 commit comments