@@ -681,13 +681,15 @@ describe("WorkspaceService", async () => {
681681 const svc = container . get ( WorkspaceService ) ;
682682 const db = container . get < WorkspaceDB > ( WorkspaceDB ) ;
683683 const today = new Date ( ) ;
684- const daysAgo = ( days : number ) => new Date ( today . getTime ( ) - 1000 * 60 * 60 * 24 * days ) ;
684+ const daysAgo = ( days : number , from = today ) => new Date ( from . getTime ( ) - 1000 * 60 * 60 * 24 * days ) ;
685685
686686 const ws = await createTestWorkspace ( svc , org , owner , project ) ;
687- await db . storeInstance ( {
687+ await svc . updateDeletionEligibilityTime ( owner . id , ws . id , true ) ;
688+ const instance = await db . storeInstance ( {
688689 id : v4 ( ) ,
689690 workspaceId : ws . id ,
690- creationTime : daysAgo ( 7 ) . toISOString ( ) ,
691+ // tomorrow, because as of #20271 deletion eligibility times can't go backwards and those are set when creating a ws
692+ creationTime : daysAgo ( - 1 ) . toISOString ( ) ,
691693 status : {
692694 conditions : { } ,
693695 phase : "stopped" ,
@@ -705,17 +707,19 @@ describe("WorkspaceService", async () => {
705707 const workspace = await svc . getWorkspace ( owner . id , ws . id ) ;
706708 expect ( workspace ) . to . not . be . undefined ;
707709 expect ( workspace . workspace . deletionEligibilityTime ) . to . not . be . undefined ;
708- expect ( workspace . workspace . deletionEligibilityTime ) . to . eq ( daysAgo ( 7 - 14 ) . toISOString ( ) ) ;
710+ expect ( workspace . workspace . deletionEligibilityTime ) . to . eq (
711+ daysAgo ( - 14 , new Date ( instance . creationTime ) ) . toISOString ( ) ,
712+ ) ;
709713 } ) ;
710714
711715 it ( "should update the deletion eligibility time of a workspace with git changes" , async ( ) => {
712716 const svc = container . get ( WorkspaceService ) ;
713717 const db = container . get < WorkspaceDB > ( WorkspaceDB ) ;
714718 const today = new Date ( ) ;
715- const daysAgo = ( days : number ) => new Date ( today . getTime ( ) - 1000 * 60 * 60 * 24 * days ) ;
719+ const daysAgo = ( days : number , from = today ) => new Date ( from . getTime ( ) - 1000 * 60 * 60 * 24 * days ) ;
716720
717721 const ws = await createTestWorkspace ( svc , org , owner , project ) ;
718- await db . storeInstance ( {
722+ const instance = await db . storeInstance ( {
719723 id : v4 ( ) ,
720724 workspaceId : ws . id ,
721725 creationTime : daysAgo ( 7 ) . toISOString ( ) ,
@@ -739,7 +743,9 @@ describe("WorkspaceService", async () => {
739743 const workspace = await svc . getWorkspace ( owner . id , ws . id ) ;
740744 expect ( workspace ) . to . not . be . undefined ;
741745 expect ( workspace . workspace . deletionEligibilityTime ) . to . not . be . undefined ;
742- expect ( workspace . workspace . deletionEligibilityTime ) . to . eq ( daysAgo ( 7 - 14 * 2 ) . toISOString ( ) ) ;
746+ expect ( workspace . workspace . deletionEligibilityTime ) . to . eq (
747+ daysAgo ( - 14 * 2 , new Date ( instance . creationTime ) ) . toISOString ( ) ,
748+ ) ;
743749 } ) ;
744750
745751 it ( "should update the deletion eligibility time of a prebuild" , async ( ) => {
0 commit comments