Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Awsprovider - adding support for SDK sub-classes. #7031

Merged
merged 2 commits into from
Nov 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/plugins/aws/provider/awsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ class AwsProvider {
if (options && !_.isUndefined(options.region)) {
credentials.region = options.region;
}
const awsService = new that.sdk[service](credentials);
const Service = _.get(that.sdk, service);
const awsService = new Service(credentials);
const req = awsService[method](params);

// TODO: Add listeners, put Debug statements here...
Expand Down
35 changes: 35 additions & 0 deletions lib/plugins/aws/provider/awsProvider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,41 @@ describe('AwsProvider', () => {
});
});

it('should handle subclasses', () => {
class DocumentClient {
constructor(credentials) {
this.credentials = credentials;
}

put() {
return {
send: cb => cb(null, { called: true }),
};
}
}

awsProvider.sdk = {
DynamoDB: {
DocumentClient,
},
};
awsProvider.serverless.service.environment = {
vars: {},
stages: {
dev: {
vars: {
profile: 'default',
},
regions: {},
},
},
};

return awsProvider.request('DynamoDB.DocumentClient', 'put', {}).then(data => {
expect(data.called).to.equal(true);
});
});

it('should call correct aws method with a promise', () => {
// mocking API Gateway for testing
class FakeAPIGateway {
Expand Down