dwyl/aws-sdk-mock

When some client has multiple instances, and we do remock, not all instances are updated

Closed this issue ยท 2 comments

Issues

  1. When some client has multiple instances, and we do remock, not all instances are updated
  2. When some client has multiple instances, and we do restore, not all instances are restored

How to reproduce issue 1

// mock DynamoDB.getItem
awsMock.mock('DynamoDB', 'getItem', function(params, callback){
      callback(null, 'value1');
});

// you have multiple instances in your code
const ddb1 = new AWS.DynamoDB();
const ddb2 = new AWS.DynamoDB();
    
awsMock.remock('DynamoDB', 'getItem', function(params, callback){
   callback(null, 'value2');
});

Currently, only ONE of instances is updated in this case, and that is strange.
ddb1.getItem() returns value1, and ddb2.getItem() returns value2.

How to reproduce issue 2

awsMock.mock('SNS', 'publish', function(params, callback){
      callback(null, 'message');
});

const sns1 = new AWS.SNS();
const sns2 = new AWS.SNS();

// publish function on both instances is mocked

st.equals(AWS.SNS.isSinonProxy, true);
st.equals(sns1.publish.isSinonProxy, true);
st.equals(sns2.publish.isSinonProxy, true);

 awsMock.restore('SNS', 'publish');

// only publish function on second instance (sns2) is restored

Pull request with fix
I opened a pull request with fix #218

@nelsonic could you please check my PR

@ellenaua apologies for the delay getting to this. โŒ›
This will be a legit use case for some people. ๐Ÿ‘
Ideally we would also add to the Docs so people know it's possible to mock multiple instances. ๐Ÿ“
Your PR has been merged. โœ…

New version published to NPM: aws-sdk-mock@5.4.0 ๐Ÿ“ฆ
Invitation to be a maintainer of the repo sent. โœ‰๏ธ