Skip to content

Commit a5deeea

Browse files
committed
adds single test that stubbing s3.upload works
1 parent a8e9756 commit a5deeea

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ function stubService(service) {
5353
client.__proto__
5454
);
5555

56-
5756
var spy = sinon.spy(FakeService);
5857
spy.restore = function() { setService(service, Original); };
5958

test/index.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,23 @@ test('[multipleMethods] replacement function', function(assert) {
233233
assert.end();
234234
});
235235
});
236+
237+
test('[upload] methods inherited multiple times', function(assert) {
238+
var upload = AWS.stub('S3', 'upload', function(params, callback) {
239+
callback(null, data);
240+
});
241+
242+
app.upload(function(err, data) {
243+
assert.ifError(err, 'success');
244+
assert.equal(data, 'hello world');
245+
246+
assert.equal(AWS.S3.callCount, 1, 'one s3 client created');
247+
assert.ok(AWS.S3.calledWithExactly({ region }), 's3 client created for the correct region');
248+
249+
assert.equal(upload.callCount, 1, 'called s3.upload once');
250+
assert.ok(upload.calledWith(expected), 'called s3.upload with expected params');
251+
252+
AWS.S3.restore();
253+
assert.end();
254+
});
255+
});

test/test-app.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var AWS = require('aws-sdk');
22

3-
module.exports = { useCallback, usePromise, streaming, useEvents, multipleMethods };
3+
module.exports = { useCallback, usePromise, streaming, useEvents, multipleMethods, upload };
44

55
function useCallback(callback) {
66
var s3 = new AWS.S3({ region: 'eu-west-1' });
@@ -47,3 +47,11 @@ function multipleMethods(callback) {
4747
.then(function(data) { callback(null, data.Body.toString()); })
4848
.catch(callback);
4949
}
50+
51+
function upload(callback) {
52+
var s3 = new AWS.S3({ region: 'eu-west-1' });
53+
s3.upload({ Bucket: 'bucket', Key: 'key' }, function(err, data) {
54+
if (err) return callback(err);
55+
callback(null, data.Body.toString());
56+
});
57+
}

0 commit comments

Comments
 (0)