@@ -216,3 +216,85 @@ describe('ApprovalProcess.create', () => {
216216 expect ( result ) . toEqual ( config ) ;
217217 } ) ;
218218} ) ;
219+
220+ // ============================================================================
221+ // Protocol Improvement Tests: Approval escalation
222+ // ============================================================================
223+
224+ describe ( 'ApprovalProcessSchema - escalation' , ( ) => {
225+ it ( 'should accept approval process with escalation config' , ( ) => {
226+ const result = ApprovalProcessSchema . parse ( {
227+ name : 'escalated_approval' ,
228+ label : 'Escalated Approval' ,
229+ object : 'purchase_order' ,
230+ steps : [ {
231+ name : 'manager_review' ,
232+ label : 'Manager Review' ,
233+ approvers : [ { type : 'manager' , value : 'direct_manager' } ] ,
234+ } ] ,
235+ escalation : {
236+ enabled : true ,
237+ timeoutHours : 48 ,
238+ action : 'reassign' ,
239+ escalateTo : 'vp_operations' ,
240+ notifySubmitter : true ,
241+ } ,
242+ } ) ;
243+ expect ( result . escalation ?. enabled ) . toBe ( true ) ;
244+ expect ( result . escalation ?. timeoutHours ) . toBe ( 48 ) ;
245+ expect ( result . escalation ?. action ) . toBe ( 'reassign' ) ;
246+ expect ( result . escalation ?. escalateTo ) . toBe ( 'vp_operations' ) ;
247+ } ) ;
248+
249+ it ( 'should accept escalation with auto_approve action' , ( ) => {
250+ const result = ApprovalProcessSchema . parse ( {
251+ name : 'auto_escalate' ,
252+ label : 'Auto Escalate' ,
253+ object : 'expense_report' ,
254+ steps : [ {
255+ name : 'review' ,
256+ label : 'Review' ,
257+ approvers : [ { type : 'user' , value : 'finance_team' } ] ,
258+ } ] ,
259+ escalation : {
260+ enabled : true ,
261+ timeoutHours : 72 ,
262+ action : 'auto_approve' ,
263+ } ,
264+ } ) ;
265+ expect ( result . escalation ?. action ) . toBe ( 'auto_approve' ) ;
266+ } ) ;
267+
268+ it ( 'should default escalation action to notify' , ( ) => {
269+ const result = ApprovalProcessSchema . parse ( {
270+ name : 'default_escalation' ,
271+ label : 'Default' ,
272+ object : 'request' ,
273+ steps : [ {
274+ name : 'step_one' ,
275+ label : 'Step 1' ,
276+ approvers : [ { type : 'role' , value : 'approver' } ] ,
277+ } ] ,
278+ escalation : {
279+ enabled : true ,
280+ timeoutHours : 24 ,
281+ } ,
282+ } ) ;
283+ expect ( result . escalation ?. action ) . toBe ( 'notify' ) ;
284+ expect ( result . escalation ?. notifySubmitter ) . toBe ( true ) ;
285+ } ) ;
286+
287+ it ( 'should accept approval process without escalation (optional)' , ( ) => {
288+ const result = ApprovalProcessSchema . parse ( {
289+ name : 'no_escalation' ,
290+ label : 'No Escalation' ,
291+ object : 'task' ,
292+ steps : [ {
293+ name : 'approve' ,
294+ label : 'Approve' ,
295+ approvers : [ { type : 'user' , value : 'admin' } ] ,
296+ } ] ,
297+ } ) ;
298+ expect ( result . escalation ) . toBeUndefined ( ) ;
299+ } ) ;
300+ } ) ;
0 commit comments