@@ -2,11 +2,9 @@ import dayjs from "dayjs"
2
2
import duration from "dayjs/plugin/duration"
3
3
import { emptySchedule } from "pages/WorkspaceSchedulePage/schedule"
4
4
import { emptyTTL } from "pages/WorkspaceSchedulePage/ttl"
5
- import { Template , Workspace } from "../api/typesGenerated"
5
+ import { Workspace } from "../api/typesGenerated"
6
6
import * as Mocks from "../testHelpers/entities"
7
7
import {
8
- canExtendDeadline ,
9
- canReduceDeadline ,
10
8
deadlineExtensionMax ,
11
9
deadlineExtensionMin ,
12
10
extractTimezone ,
@@ -19,6 +17,7 @@ import {
19
17
20
18
dayjs . extend ( duration )
21
19
const now = dayjs ( )
20
+ const startTime = dayjs ( Mocks . MockWorkspaceBuild . updated_at )
22
21
23
22
describe ( "util/schedule" , ( ) => {
24
23
describe ( "stripTimezone" , ( ) => {
@@ -43,38 +42,16 @@ describe("util/schedule", () => {
43
42
} )
44
43
45
44
describe ( "maxDeadline" , ( ) => {
46
- // Given: a workspace built from a template with a max deadline equal to 25 hours which isn't really possible
47
45
const workspace : Workspace = {
48
46
...Mocks . MockWorkspace ,
49
47
latest_build : {
50
48
...Mocks . MockWorkspaceBuild ,
51
- deadline : now . add ( 8 , "hours" ) . utc ( ) . format ( ) ,
49
+ deadline : startTime . add ( 8 , "hours" ) . utc ( ) . format ( ) ,
52
50
} ,
53
51
}
54
- describe ( "given a template with 25 hour max ttl" , ( ) => {
55
- it ( "should be never be greater than global max deadline" , ( ) => {
56
- const template : Template = {
57
- ...Mocks . MockTemplate ,
58
- default_ttl_ms : 25 * 60 * 60 * 1000 ,
59
- }
60
-
61
- // Then: deadlineMinusDisabled should be falsy
62
- const delta = getMaxDeadline ( workspace , template ) . diff ( now )
63
- expect ( delta ) . toBeLessThanOrEqual ( deadlineExtensionMax . asMilliseconds ( ) )
64
- } )
65
- } )
66
-
67
- describe ( "given a template with 4 hour max ttl" , ( ) => {
68
- it ( "should be never be greater than global max deadline" , ( ) => {
69
- const template : Template = {
70
- ...Mocks . MockTemplate ,
71
- default_ttl_ms : 4 * 60 * 60 * 1000 ,
72
- }
73
-
74
- // Then: deadlineMinusDisabled should be falsy
75
- const delta = getMaxDeadline ( workspace , template ) . diff ( now )
76
- expect ( delta ) . toBeLessThanOrEqual ( deadlineExtensionMax . asMilliseconds ( ) )
77
- } )
52
+ it ( "should be 24 hours from the workspace start time" , ( ) => {
53
+ const delta = getMaxDeadline ( workspace ) . diff ( startTime )
54
+ expect ( delta ) . toEqual ( deadlineExtensionMax . asMilliseconds ( ) )
78
55
} )
79
56
} )
80
57
@@ -85,50 +62,6 @@ describe("minDeadline", () => {
85
62
} )
86
63
} )
87
64
88
- describe ( "canExtendDeadline" , ( ) => {
89
- it ( "should be falsy if the deadline is more than 24 hours in the future" , ( ) => {
90
- expect (
91
- canExtendDeadline (
92
- dayjs ( ) . add ( 25 , "hours" ) ,
93
- Mocks . MockWorkspace ,
94
- Mocks . MockTemplate ,
95
- ) ,
96
- ) . toBeFalsy ( )
97
- } )
98
-
99
- it ( "should be falsy if the deadline is more than the template max_ttl" , ( ) => {
100
- const tooFarAhead = dayjs ( ) . add (
101
- dayjs . duration ( Mocks . MockTemplate . default_ttl_ms , "milliseconds" ) ,
102
- )
103
- expect (
104
- canExtendDeadline ( tooFarAhead , Mocks . MockWorkspace , Mocks . MockTemplate ) ,
105
- ) . toBeFalsy ( )
106
- } )
107
-
108
- it ( "should be truth if the deadline is within the template max_ttl" , ( ) => {
109
- const okDeadline = dayjs ( ) . add (
110
- dayjs . duration ( Mocks . MockTemplate . default_ttl_ms / 2 , "milliseconds" ) ,
111
- )
112
- expect (
113
- canExtendDeadline ( okDeadline , Mocks . MockWorkspace , Mocks . MockTemplate ) ,
114
- ) . toBeFalsy ( )
115
- } )
116
- } )
117
-
118
- describe ( "canReduceDeadline" , ( ) => {
119
- it ( "should be falsy if the deadline is 30 minutes or less in the future" , ( ) => {
120
- expect ( canReduceDeadline ( dayjs ( ) ) ) . toBeFalsy ( )
121
- expect ( canReduceDeadline ( dayjs ( ) . add ( 1 , "minutes" ) ) ) . toBeFalsy ( )
122
- expect ( canReduceDeadline ( dayjs ( ) . add ( 29 , "minutes" ) ) ) . toBeFalsy ( )
123
- expect ( canReduceDeadline ( dayjs ( ) . add ( 30 , "minutes" ) ) ) . toBeFalsy ( )
124
- } )
125
-
126
- it ( "should be truthy if the deadline is 30 minutes or more in the future" , ( ) => {
127
- expect ( canReduceDeadline ( dayjs ( ) . add ( 31 , "minutes" ) ) ) . toBeTruthy ( )
128
- expect ( canReduceDeadline ( dayjs ( ) . add ( 100 , "years" ) ) ) . toBeTruthy ( )
129
- } )
130
- } )
131
-
132
65
describe ( "getMaxDeadlineChange" , ( ) => {
133
66
it ( "should return the number of hours you can add before hitting the max deadline" , ( ) => {
134
67
const deadline = dayjs ( )
0 commit comments