Issues (3)

test/hs.bot.spec.js (1 issue)

Severity
1
/**
2
 * hsBot: Supply template and your bot is ready.
3
 * 
4
 * Hardik Shah <[email protected]>
5
 * 
6
 * MIT License
7
 */
8
9
var should = require('chai').should();
10
var Bot = require('../lib/index');
11
var ChatDB = require('../db/chatdb');
12
var dummyData = require('./dummy.data.json');
13
var topicList = require('../db/data/topicList.json');
14
var topics = require('../db/data/topics.json');
15
16
describe('Bot', function() {
17
  describe('version', function() {
18
    it('Should be exposed', function() {
19
      Bot.version.should.be.ok;
0 ignored issues
show
The result of the property access to Bot.version.should.be.ok is not used.
Loading history...
20
    });
21
  });
22
23
  describe('constructor', function() {
24
    it('Should load topic list and topics', function() {
25
      var bot = new Bot(topicList, topics);
26
      bot.topicList.should.eql(topicList);
27
      bot.topics.should.eql(topics);
28
    });
29
  });
30
31
  describe('.transformAndReply()', function() {
32
33
    it('Should answer even if userId is undefined', function() {
34
      var bot = new Bot(topicList, topics);
35
      bot.transformAndReply(null, null, null, function(err, response){
36
        err.should.eql("UserId is not defined.");
37
        should.not.exist(response);
38
      });
39
    });
40
41
    it('Initiate by welcoming user by asking name', function() {
42
      var bot = new Bot(topicList, topics);
43
      bot.transformAndReply("aQ11zyTr4u7K", null, null, function(err, response){
44
        response.should.eql("What is your name?");
45
      });
46
    });
47
48
    it('Should remember your name.', function() {
49
      var bot = new Bot(topicList, topics);
50
      bot.transformAndReply("aQ11zyTr4u7K", null, "Hardik Shah", function(err, response){
51
        response.should.eql("Hello Hardik Shah, I am HSBOT and I will help you.");
52
      });
53
    });
54
55
    it('Should not register user again by same userId.', function() {
56
      var bot = new Bot(topicList, topics);
57
      bot.transformAndReply("aQ11zyTr4u7K", null, null, function(err, response){
58
        response.should.eql("Hello Hardik Shah, I am HSBOT and I will help you.");
59
      });
60
    });
61
62
    it('Should trigger @hs command properly.', function() {
63
      var bot = new Bot(topicList, topics);
64
      bot.transformAndReply("aQ11zyTr4u7K", null, "@hs", function(err, response){
65
        response.should.eql("1. Product List \n 2. Product on the way \n 3. Branch List \n 4. Customer care \n 5. Store detail");
66
      });
67
    });
68
69
    it('Should return default message if any string not match.', function() {
70
      var bot = new Bot(topicList, topics);
71
      bot.transformAndReply("aQ11zyTr4u7K", null, "XYZ", function(err, response){
72
        response.should.eql("Thank you for contacting us. you can call me by typing @hs anytime for further help.");
73
      });
74
    });
75
76
    it('Should register user directly and remember name.', function() {
77
      var bot = new Bot(topicList, topics);
78
      bot.transformAndReply("aQ11zyTr4e32", "Kartik Shah", null, function(err, response){
79
        response.should.eql("Hello Kartik Shah, I am HSBOT and I will help you.");
80
      });
81
    });
82
83
    it('Should continue flow by replying to bot.', function() {
84
      var bot = new Bot(topicList, topics);
85
      bot.transformAndReply("aQ11zyTr4e32", "Kartik Shah", "ok", function(err, response){
86
        response.should.eql("In order to support you better, I will take small survey.");
87
      });
88
    });
89
90
    it('Should return valid answer on direct command (@HS customer care).', function() {
91
      var bot = new Bot(topicList, topics);
92
      bot.transformAndReply("aQ11zyTr4u7K", null, "@HS customer care", function(err, response){
93
        response.should.eql("Help line number is 00 000 0000 0000");
94
      });
95
    });
96
97
    it('Should return valid answer on direct command (@HS address).', function() {
98
      var bot = new Bot(topicList, topics);
99
      bot.transformAndReply("aQ11zyTr4u7K", null, "@HS address", function(err, response){
100
        response.should.eql("23-D XXXX, Near XXXX, Opposite XXX, Pincode : XXXXXX");
101
      });
102
    });
103
104
    it('Should take a next topic on specific command.', function() {
105
      var bot = new Bot(topicList, topics);
106
      bot.transformAndReply("aQ11zyTr4u7K", null, "call2", function(err, response){
107
        response.should.eql("Hello Hardik Shah, I am HSBOT and I will help you.");
108
      });
109
    });
110
111
    describe('Negative test cases', function() {
112
      it('Should return undefined if default message not found.', function() {
113
        var topicList = dummyData.witout_defaultMessage_topicList;
114
        var topics = dummyData.empty_arr;
115
        var chatDB = new ChatDB(topicList, topics);
116
        var response = chatDB.getDefaultMessage();
117
        should.not.exist(response);
118
      });
119
120
      it('Should return undefined if default topic not found.', function() {
121
        var topicList = dummyData.witout_defaultMessage_topicList;
122
        var topics = dummyData.empty_arr;
123
        var chatDB = new ChatDB(topicList, topics);
124
        var response = chatDB._findDefaultTopic();
125
        should.not.exist(response);
126
      });
127
128
      it('Should return undefined if default topic not found.', function() {
129
        var topicList = dummyData.witout_defaultMessage_topicList;
130
        var topics = dummyData.topics;
131
        var chatDB = new ChatDB(topicList, topics);
132
        var response = chatDB.getTopicFlow("XYZ");
133
        should.not.exist(response);
134
      });
135
      
136
      it('Should return undefined if redirect topic not found.', function() {
137
        var topicList = dummyData.witout_defaultMessage_topicList;
138
        var topics = dummyData.topics;
139
        var chatDB = new ChatDB(topicList, topics);
140
        var response = chatDB.getTemplateObj("Hardik Shah", topics, null, null);
141
        should.not.exist(response);
142
      });
143
      
144
      it('Should return undefined if defaul topic not found.', function() {
145
        var topicList = dummyData.witout_defaultMessage_topicList;
146
        var topics = dummyData.topics;
147
        var chatDB = new ChatDB(topicList, topics);
148
        var response = chatDB.getTemplateObj(null, topics, null, null);
149
        should.not.exist(response);
150
      });
151
      
152
      it('Should return undefined if pattern not found from topics.', function() {
153
        var topicList = dummyData.witout_defaultMessage_topicList;
154
        var topics = dummyData.topics;
155
        var chatDB = new ChatDB(topicList, topics);
156
        var response = chatDB.getTemplateObj(null, topics, "XYZ", null);
157
        should.not.exist(response);
158
      });
159
      
160
      it('Should return undefined if pattern and preQ not found from topics.', function() {
161
        var topicList = dummyData.witout_defaultMessage_topicList;
162
        var topics = dummyData.topics;
163
        var chatDB = new ChatDB(topicList, topics);
164
        var response = chatDB.getTemplateObj(null, topics, "XYZ", "XYZ");
165
        should.not.exist(response);
166
      });
167
      
168
    });
169
170
  });
171
});