@@ -5,3 +5,77 @@ import {
5
5
updateAppointment ,
6
6
availableTimes ,
7
7
} from './appointment-time' ;
8
+
9
+ describe ( 'createAppointment' , ( ) => {
10
+ test ( 'creates appointment of 4 days later' , ( ) => {
11
+ expect ( createAppointment ( 4 ) ) . toBe (
12
+ new Date ( Date . now ( ) + 4 * 24 * 3600 * 1000 )
13
+ ) ;
14
+ } ) ;
15
+
16
+ test ( 'creates appointment of 124 days later' , ( ) => {
17
+ expect ( createAppointment ( 124 ) ) . toBe (
18
+ new Date ( Date . now ( ) + 124 * 24 * 3600 * 1000 )
19
+ ) ;
20
+ } ) ;
21
+ } ) ;
22
+
23
+ describe ( 'getAppointment' , ( ) => {
24
+ test ( 'get appointment detail' , ( ) => {
25
+ expect ( getAppointment ( '24 April 2022 10:15 AM' ) ) . toEqual ( {
26
+ year : 2022 ,
27
+ month : 3 ,
28
+ date : 24 ,
29
+ hour : 10 ,
30
+ minute : 15 ,
31
+ } ) ;
32
+ } ) ;
33
+ } ) ;
34
+
35
+ describe ( 'updateAppointment' , ( ) => {
36
+ test ( 'should update with one option' , ( ) => {
37
+ expect (
38
+ updateAppointment ( '09 February 2022 10:20 am' , { month : 6 } )
39
+ ) . toEqual ( { year : 2022 , month : 6 , date : 9 , hour : 10 , minute : 20 } ) ;
40
+ } ) ;
41
+
42
+ test ( 'should update with multiple options' , ( ) => {
43
+ expect (
44
+ updateAppointment ( '21 November 2022 10:20 pm' , {
45
+ year : 2023 ,
46
+ month : 1 ,
47
+ date : 12 ,
48
+ hour : 1 ,
49
+ minute : 29 ,
50
+ } )
51
+ ) . toEqual ( { year : 2023 , month : 1 , date : 12 , hour : 1 , minute : 29 } ) ;
52
+ } ) ;
53
+
54
+ test ( 'should update with option with zero as value' , ( ) => {
55
+ expect (
56
+ updateAppointment ( '17 December 2022 8:10 am' , { minute : 0 } )
57
+ ) . toEqual ( { year : 2022 , month : 11 , date : 17 , hour : 8 , minute : 0 } ) ;
58
+ } ) ;
59
+ } ) ;
60
+
61
+ describe ( 'availableTimes' , ( ) => {
62
+ test ( 'get available times between two appointments' , ( ) => {
63
+ expect (
64
+ availableTimes ( '12 December 2022 10:20 am' , '18 December 2022 9:30 am' )
65
+ ) . toBe ( 515400000 ) ;
66
+ } ) ;
67
+ } ) ;
68
+
69
+ describe ( 'isValid' , ( ) => {
70
+ test ( 'appointmentTime is greater than currentTime' , ( ) => {
71
+ expect ( isValid ( '12 February 2022' , '9 February 2022' ) ) . toEqual (
72
+ 'The appointment is valid.'
73
+ ) ;
74
+ } ) ;
75
+
76
+ test ( 'appointmentTime is less than currentTime' , ( ) => {
77
+ expect ( isValid ( '20 May 2022' , '21 May 2022' ) ) . toEqual (
78
+ 'The appointment is not valid anymore.'
79
+ ) ;
80
+ } ) ;
81
+ } ) ;
0 commit comments