@@ -476,6 +476,59 @@ describe('V2 Methodology API - Basic CRUD Tests', function () {
476476 expect ( response . body . references [ 0 ] . count ) . to . equal ( 1 ) ;
477477 } ) ;
478478
479+ it ( 'should allow delete when committed references are already staged for deletion' , async function ( ) {
480+ const methodology = await MethodologyV2 . create ( {
481+ cadTrustMethodologyId : uuidv4 ( ) ,
482+ methodologyCode : 'STAGED-DELETE-METHOD-001' ,
483+ methodologyName : 'Methodology With Deleted Reference' ,
484+ } ) ;
485+
486+ const program = await ProgramV2 . create ( {
487+ programName : 'Staged Delete Program' ,
488+ programRegistry : 'Test Registry' ,
489+ programRegistryActivityId : 'STAGED-DELETE-001' ,
490+ } ) ;
491+
492+ const project = await ProjectV2 . create ( {
493+ cadTrustProjectId : uuidv4 ( ) ,
494+ orgUid : 'test-home-org-v2' ,
495+ projectRegistryName : 'Test Registry' ,
496+ projectId : 'STAGED-DELETE-PROJ-001' ,
497+ projectName : 'Staged Delete Project' ,
498+ cadTrustProgramId : program . cadTrustProgramId ,
499+ } ) ;
500+
501+ const projectMethodology = await ProjectMethodologyV2 . create ( {
502+ cadTrustProjectMethodologyId : uuidv4 ( ) ,
503+ cadTrustProjectId : project . cadTrustProjectId ,
504+ cadTrustMethodologyId : methodology . cadTrustMethodologyId ,
505+ } ) ;
506+
507+ await StagingV2 . create ( {
508+ uuid : uuidv4 ( ) ,
509+ table : 'project_methodology' ,
510+ action : 'DELETE' ,
511+ data : JSON . stringify ( [ {
512+ cad_trust_project_methodology_id : projectMethodology . cadTrustProjectMethodologyId ,
513+ } ] ) ,
514+ committed : false ,
515+ failed_commit : false ,
516+ is_transfer : false ,
517+ } ) ;
518+
519+ const response = await supertest ( app )
520+ . delete ( `/v2/methodology/${ methodology . cadTrustMethodologyId } ` )
521+ . expect ( 200 ) ;
522+
523+ expect ( response . body . success ) . to . be . true ;
524+ expect ( response . body . message ) . to . equal ( 'Methodology delete staged successfully' ) ;
525+
526+ const stagingRecord = await StagingV2 . findOne ( {
527+ where : { table : 'methodology' , action : 'DELETE' } ,
528+ } ) ;
529+ expect ( stagingRecord ) . to . exist ;
530+ } ) ;
531+
479532 it ( 'should return 409 with ?force=true when references still exist' , async function ( ) {
480533 const methodology = await MethodologyV2 . create ( {
481534 cadTrustMethodologyId : uuidv4 ( ) ,
0 commit comments