Skip to content

Commit 7ac6a6e

Browse files
committed
Adding s3 module tests
1 parent 3e024dd commit 7ac6a6e

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

packages/build/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,11 @@
3535
"handlebars": "^4.7.6",
3636
"pkg": "^4.4.3",
3737
"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"
3844
}
3945
}

packages/build/src/s3.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
1+
import { expect } from 'chai';
2+
import sinon from 'sinon';
3+
import upload from './s3';
4+
15
describe('s3 module', () => {
26
describe('.upload', () => {
7+
const params = { ACL: 'public-read' };
8+
39
context('when the upload errors', () => {
10+
const uploadMock = sinon.mock().withArgs(params).yields('error', {});
11+
const s3Stub = { upload: uploadMock };
412

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+
});
520
});
621

722
context('when the upload succeeds', () => {
23+
const uploadMock = sinon.mock().withArgs(params).yields(null, {});
24+
const s3Stub = { upload: uploadMock };
825

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+
});
931
});
1032
});
1133
});

packages/build/src/s3.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import S3 from 'aws-sdk/clients/s3';
88
*
99
* @returns {Promise} - A Promise.
1010
*/
11-
const upload = (params: any, s3: S3): Promise<any> => {
11+
const upload = (params: any, s3: any): Promise<any> => {
1212
return new Promise((resolve, reject) => {
1313
s3.upload(params, (error, data) => {
1414
if (error) {

0 commit comments

Comments
 (0)