1
|
|
|
/** |
2
|
|
|
* hsBot: Supply template and your bot is ready. |
3
|
|
|
* |
4
|
|
|
* Hardik Shah <[email protected]> |
5
|
|
|
* |
6
|
|
|
* MIT License |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
var expect = require('chai').expect; |
10
|
|
|
var Bot = require('../lib/index'); |
11
|
|
|
var Analysis = require('../analysis'); |
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('Analysis', function() { |
17
|
|
|
|
18
|
|
|
describe('getUserAnalysis()', function() { |
19
|
|
|
it('Initiate by welcoming user by asking name', function() { |
20
|
|
|
var bot = new Bot(topicList, topics); |
21
|
|
|
bot.transformAndReply("aQ11zyTr4u7I", null, null, function(err, response){ |
22
|
|
|
expect(response).to.match(/^What is your name?/); |
23
|
|
|
}); |
24
|
|
|
}); |
25
|
|
|
|
26
|
|
|
it('Should remember your name.', function() { |
27
|
|
|
var bot = new Bot(topicList, topics); |
28
|
|
|
bot.transformAndReply("aQ11zyTr4u7I", null, "Hardik Shah", function(err, response){ |
29
|
|
|
expect(response).to.match(/^Hello Hardik Shah, I am HSBOT and I will help you./); |
30
|
|
|
}); |
31
|
|
|
}); |
32
|
|
|
|
33
|
|
|
it('Should Analyze data.', function() { |
34
|
|
|
var bot = new Bot(topicList, topics); |
35
|
|
|
var userAnalysis = bot.getUserAnalysis("aQ11zyTr4u7I"); |
36
|
|
|
expect(userAnalysis).to.have.all.keys('timeSpent', 'frequentBotText', 'frequentUserText'); |
37
|
|
|
}); |
38
|
|
|
}); |
39
|
|
|
|
40
|
|
|
describe('getChatHistory()', function() { |
41
|
|
|
it('Should return user details.', function() { |
42
|
|
|
var bot = new Bot(topicList, topics); |
43
|
|
|
var user = bot.getChatHistory("aQ11zyTr4u7I"); |
44
|
|
|
expect(user).to.have.all.keys('userId', 'userName', 'activities', 'loggedIn'); |
45
|
|
|
expect(user.activities).to.have.length(2); |
46
|
|
|
}); |
47
|
|
|
}); |
48
|
|
|
|
49
|
|
|
describe('getAllUserChatHistory()', function() { |
50
|
|
|
it('Should return all user details.', function() { |
51
|
|
|
var bot = new Bot(topicList, topics); |
52
|
|
|
var user = bot.getAllUserChatHistory(); |
53
|
|
|
expect(user).to.have.length(1); |
54
|
|
|
expect(user[0]).to.have.all.keys('userId', 'userName', 'activities', 'loggedIn'); |
55
|
|
|
}); |
56
|
|
|
}); |
57
|
|
|
|
58
|
|
|
describe('analysis._analyzed()', function() { |
59
|
|
|
it('Should return all user details.', function() { |
60
|
|
|
var userData = dummyData.userData; |
61
|
|
|
var analysis = new Analysis(); |
62
|
|
|
var userAnalysis = analysis._analyzed(userData); |
63
|
|
|
expect(userAnalysis).to.have.all.keys('timeSpent', 'frequentBotText', 'frequentUserText'); |
64
|
|
|
}); |
65
|
|
|
}); |
66
|
|
|
|
67
|
|
|
}); |