@@ -22,6 +22,8 @@ await jest.unstable_mockModule('../videoService/opentokVideoService.ts', () => {
22
22
return {
23
23
startArchive : jest . fn < ( ) => Promise < string > > ( ) . mockResolvedValue ( 'archiveId' ) ,
24
24
stopArchive : jest . fn < ( ) => Promise < string > > ( ) . mockRejectedValue ( 'invalid archive' ) ,
25
+ enableCaptions : jest . fn < ( ) => Promise < string > > ( ) . mockResolvedValue ( 'captionId' ) ,
26
+ disableCaptions : jest . fn < ( ) => Promise < string > > ( ) . mockResolvedValue ( 'invalid caption' ) ,
25
27
generateToken : jest
26
28
. fn < ( ) => Promise < { token : string ; apiKey : string } > > ( )
27
29
. mockResolvedValue ( {
@@ -70,28 +72,66 @@ describe.each([
70
72
} ) ;
71
73
72
74
describe ( 'POST requests' , ( ) => {
73
- it ( 'returns a 200 when starting an archive in a room' , async ( ) => {
74
- const res = await request ( server )
75
- . post ( `/session/${ roomName } /startArchive` )
76
- . set ( 'Content-Type' , 'application/json' ) ;
77
- expect ( res . statusCode ) . toEqual ( 200 ) ;
78
- } ) ;
75
+ describe ( 'archiving' , ( ) => {
76
+ it ( 'returns a 200 when starting an archive in a room' , async ( ) => {
77
+ const res = await request ( server )
78
+ . post ( `/session/${ roomName } /startArchive` )
79
+ . set ( 'Content-Type' , 'application/json' ) ;
80
+ expect ( res . statusCode ) . toEqual ( 200 ) ;
81
+ } ) ;
79
82
80
- it ( 'returns a 404 when starting an archive in a non-existent room' , async ( ) => {
81
- const invalidRoomName = 'nonExistingRoomName' ;
82
- const res = await request ( server )
83
- . post ( `/session/${ invalidRoomName } /startArchive` )
84
- . set ( 'Content-Type' , 'application/json' ) ;
85
- expect ( res . statusCode ) . toEqual ( 404 ) ;
83
+ it ( 'returns a 404 when starting an archive in a non-existent room' , async ( ) => {
84
+ const invalidRoomName = 'nonExistingRoomName' ;
85
+ const res = await request ( server )
86
+ . post ( `/session/${ invalidRoomName } /startArchive` )
87
+ . set ( 'Content-Type' , 'application/json' ) ;
88
+ expect ( res . statusCode ) . toEqual ( 404 ) ;
89
+ } ) ;
90
+
91
+ it ( 'returns a 500 when stopping an invalid archive in a room' , async ( ) => {
92
+ const archiveId = 'b8-c9-d10' ;
93
+ const res = await request ( server )
94
+ . post ( `/session/${ roomName } /${ archiveId } /stopArchive` )
95
+ . set ( 'Content-Type' , 'application/json' )
96
+ . set ( 'Accept' , 'application/json' ) ;
97
+ expect ( res . statusCode ) . toEqual ( 500 ) ;
98
+ } ) ;
86
99
} ) ;
87
100
88
- it ( 'returns a 500 when stopping an invalid archive in a room' , async ( ) => {
89
- const archiveId = 'b8-c9-d10' ;
90
- const res = await request ( server )
91
- . post ( `/session/${ roomName } /${ archiveId } /stopArchive` )
92
- . set ( 'Content-Type' , 'application/json' )
93
- . set ( 'Accept' , 'application/json' ) ;
94
- expect ( res . statusCode ) . toEqual ( 500 ) ;
101
+ describe ( 'captions' , ( ) => {
102
+ it ( 'returns a 200 when enabling captions in a room' , async ( ) => {
103
+ const res = await request ( server )
104
+ . post ( `/session/${ roomName } /enableCaptions` )
105
+ . set ( 'Content-Type' , 'application/json' ) ;
106
+ expect ( res . statusCode ) . toEqual ( 200 ) ;
107
+ } ) ;
108
+
109
+ it ( 'returns a 200 when disabling captions in a room' , async ( ) => {
110
+ const captionId = 'someCaptionId' ;
111
+ const res = await request ( server )
112
+ . post ( `/session/${ roomName } /${ captionId } /disableCaptions` )
113
+ . set ( 'Content-Type' , 'application/json' ) ;
114
+ expect ( res . statusCode ) . toEqual ( 200 ) ;
115
+ } ) ;
116
+
117
+ it ( 'returns a 404 when starting captions in a non-existent room' , async ( ) => {
118
+ const invalidRoomName = 'randomRoomName' ;
119
+ const res = await request ( server )
120
+ . post ( `/session/${ invalidRoomName } /enableCaptions` )
121
+ . set ( 'Content-Type' , 'application/json' ) ;
122
+ expect ( res . statusCode ) . toEqual ( 404 ) ;
123
+ } ) ;
124
+
125
+ it ( 'returns an invalid caption message when stopping an invalid captions in a room' , async ( ) => {
126
+ const invalidCaptionId = 'wrongCaptionId' ;
127
+ const res = await request ( server )
128
+ . post ( `/session/${ roomName } /${ invalidCaptionId } /disableCaptions` )
129
+ . set ( 'Content-Type' , 'application/json' )
130
+ . set ( 'Accept' , 'application/json' ) ;
131
+
132
+ const responseBody = JSON . parse ( res . text ) ;
133
+ expect ( responseBody . captionId ) . toEqual ( 'invalid caption' ) ;
134
+ } ) ;
95
135
} ) ;
96
136
} ) ;
97
137
} ) ;
0 commit comments