@@ -144,6 +144,42 @@ describe('PostHandler', () => {
144
144
req . headers = { 'upload-length' : 1000 , host : 'localhost:3000' } ;
145
145
handler . send ( req , res ) ;
146
146
} )
147
+
148
+ it ( `must fire the ${ EVENTS . EVENT_UPLOAD_COMPLETE } event when upload is complete with single request` , ( done ) => {
149
+ const fake_store = sinon . createStubInstance ( DataStore ) ;
150
+
151
+ const upload_length = 1000 ;
152
+
153
+ fake_store . create . resolvesArg ( 0 ) ;
154
+ fake_store . write . resolves ( upload_length ) ;
155
+
156
+ const handler = new PostHandler ( fake_store , { path : '/test/output' } ) ;
157
+ handler . on ( EVENTS . EVENT_UPLOAD_COMPLETE , ( obj ) => {
158
+ done ( ) ;
159
+ } ) ;
160
+
161
+ req . headers = { 'upload-length' : `${ upload_length } ` , host : 'localhost:3000' , 'content-type' : 'application/offset+octet-stream' } ;
162
+ handler . send ( req , res ) ;
163
+ } )
164
+
165
+ it ( `must not fire the ${ EVENTS . EVENT_UPLOAD_COMPLETE } event when upload-length is defered` , ( done ) => {
166
+ const fake_store = sinon . createStubInstance ( DataStore ) ;
167
+
168
+ const upload_length = 1000 ;
169
+
170
+ fake_store . create . resolvesArg ( 0 ) ;
171
+ fake_store . write . resolves ( upload_length ) ;
172
+
173
+ const handler = new PostHandler ( fake_store , { path : '/test/output' } ) ;
174
+ handler . on ( EVENTS . EVENT_UPLOAD_COMPLETE , ( obj ) => {
175
+ done ( new Error ( ) ) ;
176
+ } ) ;
177
+
178
+ req . headers = { 'upload-defer-length' : '1' , host : 'localhost:3000' , 'content-type' : 'application/offset+octet-stream' } ;
179
+ handler . send ( req , res )
180
+ . then ( ( ) => done ( ) )
181
+ . catch ( done ) ;
182
+ } )
147
183
} ) ;
148
184
} ) ;
149
185
} ) ;
0 commit comments