@@ -39,6 +39,13 @@ describe('createAppointment', () => {
39
39
27 * 60 * 60 * 1000 ,
40
40
) ;
41
41
} ) ;
42
+
43
+ test ( 'rolls over days, months, and years' , ( ) => {
44
+ const currentTime = Date . UTC ( 1991 , 16 , 6 , 2 , 12 , 0 , 0 ) ;
45
+ const result = createAppointment ( 720 , currentTime ) ;
46
+
47
+ expect ( result . getTime ( ) ) . toStrictEqual ( 767326320000 ) ;
48
+ } ) ;
42
49
} ) ;
43
50
44
51
describe ( 'getAppointmentTimestamp' , ( ) => {
@@ -52,7 +59,7 @@ describe('getAppointmentTimestamp', () => {
52
59
} ) ;
53
60
54
61
describe ( 'getAppointment' , ( ) => {
55
- test ( 'get appointment detail ' , ( ) => {
62
+ test ( 'extracts appointment details ' , ( ) => {
56
63
expect ( getAppointmentDetails ( '2022-04-24T08:15:00.000' ) ) . toStrictEqual ( {
57
64
year : 2022 ,
58
65
month : 3 ,
@@ -64,13 +71,13 @@ describe('getAppointment', () => {
64
71
} ) ;
65
72
66
73
describe ( 'updateAppointment' , ( ) => {
67
- test ( 'should update with one option ' , ( ) => {
74
+ test ( 'updates a field ' , ( ) => {
68
75
expect (
69
76
updateAppointment ( '2022-02-09T09:20:00.000' , { month : 6 } ) ,
70
77
) . toStrictEqual ( { year : 2022 , month : 6 , date : 9 , hour : 9 , minute : 20 } ) ;
71
78
} ) ;
72
79
73
- test ( 'should update with multiple options ' , ( ) => {
80
+ test ( 'update multiple fields ' , ( ) => {
74
81
expect (
75
82
updateAppointment ( '2022-11-21T21:20:00.000' , {
76
83
year : 2023 ,
@@ -82,39 +89,51 @@ describe('updateAppointment', () => {
82
89
) . toStrictEqual ( { year : 2023 , month : 1 , date : 12 , hour : 1 , minute : 29 } ) ;
83
90
} ) ;
84
91
85
- test ( 'should update with option with zero as value ' , ( ) => {
92
+ test ( 'updates even if option is 0 ' , ( ) => {
86
93
expect (
87
94
updateAppointment ( '2022-12-17T07:10:00.000' , { minute : 0 } ) ,
88
95
) . toStrictEqual ( { year : 2022 , month : 11 , date : 17 , hour : 7 , minute : 0 } ) ;
89
96
} ) ;
97
+
98
+ test ( 'rolls over values' , ( ) => {
99
+ expect (
100
+ updateAppointment ( '2029-02-28T23:59:00.000' , { hour : 24 , minute : 60 } ) ,
101
+ ) . toStrictEqual ( { year : 2029 , month : 2 , date : 1 , hour : 1 , minute : 0 } ) ;
102
+ } ) ;
90
103
} ) ;
91
104
92
105
describe ( 'availableTimes' , ( ) => {
93
- test ( 'get available times between two appointments' , ( ) => {
106
+ test ( 'retrieves number of seconds between two appointments' , ( ) => {
94
107
expect (
95
108
timeBetween ( '2022-12-12T09:20:00.000' , '2022-12-18T08:30:00.000' ) ,
96
109
) . toBe ( 515400 ) ;
97
110
} ) ;
111
+
112
+ test ( 'rounds to seconds' , ( ) => {
113
+ expect (
114
+ timeBetween ( '2024-03-06T09:12:15.180' , '2024-03-06T18:15:12.090' ) ,
115
+ ) . toBe ( 32577 ) ;
116
+ } ) ;
98
117
} ) ;
99
118
100
119
describe ( 'isValid' , ( ) => {
101
- test ( 'true when appointment datetime is in the future' , ( ) => {
120
+ test ( 'is true when appointment datetime is in the future' , ( ) => {
102
121
expect ( isValid ( '2022-02-11T23:00:00.000' , '2022-02-08T23:00:00.000' ) ) . toBe (
103
122
true ,
104
123
) ;
105
124
} ) ;
106
125
107
- test ( 'true when appointment date is in the future' , ( ) => {
126
+ test ( 'is true when appointment date is in the future' , ( ) => {
108
127
expect ( isValid ( '2022-02-11' , '2022-02-08' ) ) . toBe ( true ) ;
109
128
} ) ;
110
129
111
- test ( 'false when appointment datetime is in the past' , ( ) => {
130
+ test ( 'is false when appointment datetime is in the past' , ( ) => {
112
131
expect ( isValid ( '2022-05-20T23:00:00.000' , '2023-02-08T23:00:00.000' ) ) . toBe (
113
132
false ,
114
133
) ;
115
134
} ) ;
116
135
117
- test ( 'false when appointment date is in the past' , ( ) => {
136
+ test ( 'is false when appointment date is in the past' , ( ) => {
118
137
expect ( isValid ( '2022-05-21' , '2022-05-22' ) ) . toBe ( false ) ;
119
138
} ) ;
120
139
} ) ;
0 commit comments