@@ -681,13 +681,15 @@ describe("WorkspaceService", async () => {
681
681
const svc = container . get ( WorkspaceService ) ;
682
682
const db = container . get < WorkspaceDB > ( WorkspaceDB ) ;
683
683
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 ) ;
685
685
686
686
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 ( {
688
689
id : v4 ( ) ,
689
690
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 ( ) ,
691
693
status : {
692
694
conditions : { } ,
693
695
phase : "stopped" ,
@@ -705,17 +707,19 @@ describe("WorkspaceService", async () => {
705
707
const workspace = await svc . getWorkspace ( owner . id , ws . id ) ;
706
708
expect ( workspace ) . to . not . be . undefined ;
707
709
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
+ ) ;
709
713
} ) ;
710
714
711
715
it ( "should update the deletion eligibility time of a workspace with git changes" , async ( ) => {
712
716
const svc = container . get ( WorkspaceService ) ;
713
717
const db = container . get < WorkspaceDB > ( WorkspaceDB ) ;
714
718
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 ) ;
716
720
717
721
const ws = await createTestWorkspace ( svc , org , owner , project ) ;
718
- await db . storeInstance ( {
722
+ const instance = await db . storeInstance ( {
719
723
id : v4 ( ) ,
720
724
workspaceId : ws . id ,
721
725
creationTime : daysAgo ( 7 ) . toISOString ( ) ,
@@ -739,7 +743,9 @@ describe("WorkspaceService", async () => {
739
743
const workspace = await svc . getWorkspace ( owner . id , ws . id ) ;
740
744
expect ( workspace ) . to . not . be . undefined ;
741
745
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
+ ) ;
743
749
} ) ;
744
750
745
751
it ( "should update the deletion eligibility time of a prebuild" , async ( ) => {
0 commit comments