Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. 'use strick';
  2.  
  3. var aws = require('aws-sdk')
  4. aws.config.update({region:'ap-northeast-1'})
  5.  
  6. class Users {
  7.  
  8. constructor() {
  9. this.table = 'Users'
  10. this.dynamodb = new aws.DynamoDB()
  11. }
  12.  
  13. getData(email) {
  14. let params = {
  15. TableName: this.table,
  16. Key : { 'email': {'S':email} }
  17. }
  18.  
  19. return this.dynamodb.getItem(params).promise()
  20. }
  21. }
  22. // module.exports = Users // ← this will be success.
  23. module.exports = new Users(); // ← this will be failure.
  24.  
  25. 'use strict';
  26.  
  27. var aws = require('aws-sdk-mock'),
  28. users = require('./user'),
  29. chai = require('chai'),
  30. path = require('path'),
  31. should = chai.should(),
  32. input = 'test@gmail.com',
  33. usersObj;
  34.  
  35. aws.setSDK(path.resolve('node_modules/aws-sdk'));
  36.  
  37. describe('All Tests', function () {
  38. // this.timeout(0);
  39. beforeEach(function () {
  40. aws.mock('DynamoDB', 'getItem', function (params, callback) {
  41. callback(null, {Item: {email: params.Key.email.S}});
  42. });
  43.  
  44. // usersObj = new users(); ← this will be success.
  45. usersObj = users; // ← this will be failure.
  46. });
  47.  
  48. it('getData', function (done) {
  49. usersObj.getData(input).then(function (res) {
  50.  
  51. console.log(res);
  52.  
  53. res.Item.email.should.equal(input);
  54. done();
  55. });
  56. });
  57. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement