@@ -3,6 +3,8 @@ import duration from "dayjs/plugin/duration"
33import { Template , Workspace } from "../api/typesGenerated"
44import * as Mocks from "../testHelpers/entities"
55import {
6+ canExtendDeadline ,
7+ canReduceDeadline ,
68 deadlineExtensionMax ,
79 deadlineExtensionMin ,
810 extractTimezone ,
@@ -78,3 +80,37 @@ describe("minDeadline", () => {
7880 expect ( delta ) . toBeGreaterThanOrEqual ( deadlineExtensionMin . asMilliseconds ( ) )
7981 } )
8082} )
83+
84+ describe ( "canExtendDeadline" , ( ) => {
85+ it ( "should be falsy if the deadline is more than 24 hours in the future" , ( ) => {
86+ expect (
87+ canExtendDeadline ( dayjs ( ) . add ( 25 , "hours" ) , Mocks . MockWorkspace , Mocks . MockTemplate ) ,
88+ ) . toBeFalsy ( )
89+ } )
90+
91+ it ( "should be falsy if the deadline is more than the template max_ttl" , ( ) => {
92+ const tooFarAhead = dayjs ( ) . add ( dayjs . duration ( Mocks . MockTemplate . max_ttl_ms , "milliseconds" ) )
93+ expect ( canExtendDeadline ( tooFarAhead , Mocks . MockWorkspace , Mocks . MockTemplate ) ) . toBeFalsy ( )
94+ } )
95+
96+ it ( "should be truth if the deadline is within the template max_ttl" , ( ) => {
97+ const okDeadline = dayjs ( ) . add (
98+ dayjs . duration ( Mocks . MockTemplate . max_ttl_ms / 2 , "milliseconds" ) ,
99+ )
100+ expect ( canExtendDeadline ( okDeadline , Mocks . MockWorkspace , Mocks . MockTemplate ) ) . toBeFalsy ( )
101+ } )
102+ } )
103+
104+ describe ( "canReduceDeadline" , ( ) => {
105+ it ( "should be falsy if the deadline is 30 minutes or less in the future" , ( ) => {
106+ expect ( canReduceDeadline ( dayjs ( ) ) ) . toBeFalsy ( )
107+ expect ( canReduceDeadline ( dayjs ( ) . add ( 1 , "minutes" ) ) ) . toBeFalsy ( )
108+ expect ( canReduceDeadline ( dayjs ( ) . add ( 29 , "minutes" ) ) ) . toBeFalsy ( )
109+ expect ( canReduceDeadline ( dayjs ( ) . add ( 30 , "minutes" ) ) ) . toBeFalsy ( )
110+ } )
111+
112+ it ( "should be truthy if the deadline is 30 minutes or more in the future" , ( ) => {
113+ expect ( canReduceDeadline ( dayjs ( ) . add ( 31 , "minutes" ) ) ) . toBeTruthy ( )
114+ expect ( canReduceDeadline ( dayjs ( ) . add ( 100 , "years" ) ) ) . toBeTruthy ( )
115+ } )
116+ } )
0 commit comments