File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 35
35
"handlebars" : " ^4.7.6" ,
36
36
"pkg" : " ^4.4.3" ,
37
37
"tar" : " ^6.0.1"
38
+ },
39
+ "devDependencies" : {
40
+ "chai" : " ^4.2.0" ,
41
+ "mocha" : " ^6.2.1" ,
42
+ "sinon" : " ^7.5.0" ,
43
+ "sinon-chai" : " ^3.4.0"
38
44
}
39
45
}
Original file line number Diff line number Diff line change
1
+ import { expect } from 'chai' ;
2
+ import sinon from 'sinon' ;
3
+ import upload from './s3' ;
4
+
1
5
describe ( 's3 module' , ( ) => {
2
6
describe ( '.upload' , ( ) => {
7
+ const params = { ACL : 'public-read' } ;
8
+
3
9
context ( 'when the upload errors' , ( ) => {
10
+ const uploadMock = sinon . mock ( ) . withArgs ( params ) . yields ( 'error' , { } ) ;
11
+ const s3Stub = { upload : uploadMock } ;
4
12
13
+ it ( 'rejects the promise with the error' , ( done ) => {
14
+ upload ( params , s3Stub ) . catch ( ( error ) => {
15
+ expect ( error ) . to . equal ( 'error' ) ;
16
+ uploadMock . verify ( ) ;
17
+ done ( ) ;
18
+ } ) ;
19
+ } ) ;
5
20
} ) ;
6
21
7
22
context ( 'when the upload succeeds' , ( ) => {
23
+ const uploadMock = sinon . mock ( ) . withArgs ( params ) . yields ( null , { } ) ;
24
+ const s3Stub = { upload : uploadMock } ;
8
25
26
+ it ( 'resolves the promise with the data' , async ( ) => {
27
+ const data = await upload ( params , s3Stub ) ;
28
+ expect ( data ) . to . deep . equal ( { } ) ;
29
+ uploadMock . verify ( ) ;
30
+ } ) ;
9
31
} ) ;
10
32
} ) ;
11
33
} ) ;
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import S3 from 'aws-sdk/clients/s3';
8
8
*
9
9
* @returns {Promise } - A Promise.
10
10
*/
11
- const upload = ( params : any , s3 : S3 ) : Promise < any > => {
11
+ const upload = ( params : any , s3 : any ) : Promise < any > => {
12
12
return new Promise ( ( resolve , reject ) => {
13
13
s3 . upload ( params , ( error , data ) => {
14
14
if ( error ) {
You can’t perform that action at this time.
0 commit comments