Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strick';
- var aws = require('aws-sdk')
- aws.config.update({region:'ap-northeast-1'})
- class Users {
- constructor() {
- this.table = 'Users'
- this.dynamodb = new aws.DynamoDB()
- }
- getData(email) {
- let params = {
- TableName: this.table,
- Key : { 'email': {'S':email} }
- }
- return this.dynamodb.getItem(params).promise()
- }
- }
- // module.exports = Users // ← this will be success.
- module.exports = new Users(); // ← this will be failure.
- 'use strict';
- var aws = require('aws-sdk-mock'),
- users = require('./user'),
- chai = require('chai'),
- path = require('path'),
- should = chai.should(),
- input = 'test@gmail.com',
- usersObj;
- aws.setSDK(path.resolve('node_modules/aws-sdk'));
- describe('All Tests', function () {
- // this.timeout(0);
- beforeEach(function () {
- aws.mock('DynamoDB', 'getItem', function (params, callback) {
- callback(null, {Item: {email: params.Key.email.S}});
- });
- // usersObj = new users(); ← this will be success.
- usersObj = users; // ← this will be failure.
- });
- it('getData', function (done) {
- usersObj.getData(input).then(function (res) {
- console.log(res);
- res.Item.email.should.equal(input);
- done();
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement