99x / serverless-dynamodb-client

Serverless Dynamodb Client to automatically switch between AWS and Local instances
MIT License
74 stars 19 forks source link

Refactored the code. Works with mocks now. #6

Open iaforek opened 6 years ago

iaforek commented 6 years ago

Changed object properties to methods in order to get this to work with aws-sdk-mock. When running sls invoke test isOffline() will return false. Therefore, you must set IS_OFFFLINE=true as environment variable manually prior running test locally or you can add to your tests:

before((done) => {
    process.env.IS_OFFLINE = true;
    ...
    done();
});

and

after((done) => {
    delete process.env.IS_OFFLINE;
    ...
    done();
});

In the code use: docClient = dynamodb.doc() instead of const docClient = dynamodb.doc. This will work with AWS, serverless offline and mocks.

Additionally, made ESLint changes.