Created
July 6, 2019 08:43
-
-
Save azarboon/53448f76d915f57c491bae9739412202 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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