Skip to content

Instantly share code, notes, and snippets.

@azarboon
Created July 6, 2019 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azarboon/53448f76d915f57c491bae9739412202 to your computer and use it in GitHub Desktop.
Save azarboon/53448f76d915f57c491bae9739412202 to your computer and use it in GitHub Desktop.
'use strict';
const AWS_MOCK = require('aws-sdk-mock');
const AWS = require('aws-sdk');
const test = require('ava');
AWS_MOCK.setSDKInstance(AWS);
const App = require('../../app.js');
let event, context;
test.after('restore all methods and services', async t => {
AWS_MOCK.restore();
});
test('test readItem by mocking', async t => {
//making dynamoDb's get method to return our expected item.
AWS_MOCK.mock('DynamoDB.DocumentClient', 'get', function(params, callback) {
callback(null, {
'item': {
'key1': 'value1'
}
});
});
const DynamoDB = new AWS.DynamoDB.DocumentClient();
// injecting db with the expected behaviour into buisness logic
const app = new App(DynamoDB);
try {
let result = await app.readItem("one");
t.is(result.statusCode, 200)
t.is(JSON.parse(result.body).message.item.key1, "value1")
} catch (e) {
t.fail(e)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment