1

How can I see where this function: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#copyObject-property

copyObject(params = {}, callback) ⇒ AWS.Request

is defined?

What I tried:

var AWS = require('aws-sdk');
AWS.S3.prototype.copyObject
=> undefined

But that is undefined

I want to know it because I want to stub this function with proxyquire:

 var aws_stub = {};
 var Mover =  proxyquire('../../callback/mover',
                         {'aws-sdk': aws_stub}
                         ).Mover;

 var fake_aws_copyObject = function(params, func){func(null, "succeed")};
     fake_aws_copyObject_stub = sinon.spy(fake_aws_copyObject);
     aws_stub.AWS.S3 ... ??   = fake_aws_copyObject_stub; 
John Smith
  • 6,105
  • 16
  • 58
  • 109

1 Answers1

1

It's specific to the version of the API you choose to use, so you have to create a new instance of your service first var s3 = new AWS.S3();.

You can find the definition of the service based on which it is generated somewhere in file describing the API: aws-sdk/apis/s3-2006-03-01.min.json.

The API files in apis are loaded in lib/api_loader.js.

You can see in lib/service.js that they are actually added to the prototype, but that only happens after you created a new instance of the service:

/**
 * Adds one method for each operation described in the api configuration
 *
 * @api private
 */
 defineMethods: function defineMethods(svc) {
     AWS.util.each(svc.prototype.api.operations, function iterator(method) {
         if (svc.prototype[method]) return;
         svc.prototype[method] = function (params, callback) {
             return this.makeRequest(method, params, callback);
         };
     });
 }