@tiledesk/tiledesk-server 2.3.36 → 2.3.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/test/faqRoute.js CHANGED
@@ -11,6 +11,8 @@ let chaiHttp = require('chai-http');
11
11
  let server = require('../app');
12
12
  let should = chai.should();
13
13
  var fs = require('fs');
14
+ const path = require('path');
15
+
14
16
 
15
17
  // chai.config.includeStack = true;
16
18
 
@@ -69,128 +71,74 @@ describe('FaqKBRoute', () => {
69
71
 
70
72
 
71
73
  });
72
- });
74
+ });
73
75
 
74
76
  });
75
77
 
76
- it('create with template example', (done) => {
78
+ it('create with form (createFaqKb function)', (done) => {
79
+
80
+
81
+ // this.timeout();
77
82
 
78
83
  var email = "test-signup-" + Date.now() + "@email.com";
79
84
  var pwd = "pwd";
80
-
81
- userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
82
- projectService.create("test-faqkb-create", savedUser._id).then((savedProject) => {
85
+ let example_form = {
86
+ fields: [
87
+ {
88
+ name: "userFullname",
89
+ type: "text",
90
+ label: "What is your name?"
91
+ },
92
+ {
93
+ name: "userEmail",
94
+ type: "text",
95
+ regex: "/^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'+/0-9=?A-Z^_`a-z{|}~]+(.[-!#$%&'+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/",
96
+ label: "Your email?",
97
+ errorLabel: "This email address is invalid\n\nCan you insert a correct email address?"
98
+ }
99
+ ]
100
+ }
101
+
102
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
103
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
83
104
 
84
105
  chai.request(server)
85
- .post('/'+ savedProject._id + '/faq_kb')
106
+ .post('/' + savedProject._id + '/faq_kb')
86
107
  .auth(email, pwd)
87
- .send({"name":"testbot", type: "internal", template: "example" })
108
+ .send({ "name": "testbot", type: "external", language: 'fr' })
88
109
  .end((err, res) => {
89
110
  //console.log("res", res);
90
- console.log("res.body", res.body);
111
+ console.log("res.body", res.body);
91
112
  res.should.have.status(200);
92
113
  res.body.should.be.a('object');
93
- expect(res.body.name).to.equal("testbot");
114
+ expect(res.body.name).to.equal("testbot");
115
+ expect(res.body.language).to.equal("fr");
94
116
  var id_faq_kb = res.body._id;
95
117
 
96
118
  chai.request(server)
97
- .get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
119
+ .post('/'+ savedProject._id + '/faq')
98
120
  .auth(email, pwd)
121
+ .send({id_faq_kb: id_faq_kb, form: example_form})
99
122
  .end((err, res) => {
100
- console.log("faq_list: ", res.body);
123
+ //console.log("res", res);
124
+ console.log("res.body", res.body);
101
125
  res.should.have.status(200);
102
- res.body.should.be.an('array').that.is.not.empty;
103
-
126
+ res.body.should.be.a('object');
127
+ expect(res.body.id_faq_kb).to.equal(id_faq_kb);
128
+ expect(res.body.form).to.exist;
129
+ res.body.form.should.be.a('object');
130
+ expect(res.body.intent_display_name).to.not.equal(undefined);
131
+ expect(res.body.webhook_enabled).to.equal(false);
132
+
104
133
  done();
105
-
106
- })
107
-
108
-
109
-
134
+ });
110
135
  });
111
- })
112
- })
113
- })
114
-
115
-
116
- it('create with template empty', (done) => {
117
-
118
-
119
- // this.timeout();
120
-
121
- var email = "test-signup-" + Date.now() + "@email.com";
122
- var pwd = "pwd";
123
-
124
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
125
- projectService.create("test-faqkb-create", savedUser._id).then(function(savedProject) {
126
- chai.request(server)
127
- .post('/'+ savedProject._id + '/faq_kb')
128
- .auth(email, pwd)
129
- .send({"name":"testbot", type: "tilebot"})
130
- .end((err, res) => {
131
- //console.log("res", res);
132
- console.log("res.body (faqkb)", res.body);
133
- res.should.have.status(200);
134
- res.body.should.be.a('object');
135
- expect(res.body.name).to.equal("testbot");
136
- expect(res.body.type).to.equal("tilebot");
137
- var id_faq_kb = res.body._id;
138
136
 
139
- chai.request(server)
140
- .get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
141
- .auth(email, pwd)
142
- .end((err, res) => {
143
- console.log("faq_list: ", res.body);
144
- res.should.have.status(200);
145
- res.body.should.be.an('array').that.is.empty;
146
-
147
- var reply_example = {
148
- type: "text",
149
- text: "Hello with buttons",
150
- attributes: {
151
- attachment: {
152
- type:"template",
153
- buttons: [
154
- {
155
- type: "text",
156
- value: "REPLY ONE"
157
- },
158
- {
159
- type: "text",
160
- value: "REPLY TWO"
161
- }
162
- ]
163
- }
164
- }
165
- }
166
-
167
- chai.request(server)
168
- .post('/'+ savedProject._id + '/faq')
169
- .auth(email, pwd)
170
- .send({id_faq_kb: id_faq_kb, question: "question1", reply: reply_example })
171
- .end((err, res) => {
172
- //console.log("res", res);
173
- console.log("res.body (faq reply)", res.body);
174
- res.should.have.status(200);
175
- res.body.should.be.a('object');
176
- res.body.reply.should.be.a('object');
177
- expect(res.body.id_faq_kb).to.equal(id_faq_kb);
178
- expect(res.body.question).to.equal("question1");
179
- expect(res.body.reply.type).to.equal(reply_example.type);
180
- expect(res.body.reply.text).to.equal(reply_example.text);
181
- expect(res.body.intent_display_name).to.not.equal(undefined);
182
- expect(res.body.webhook_enabled).to.equal(false);
183
-
184
- done();
185
- });
186
137
 
187
- })
188
- });
189
- });
190
138
  });
191
- });
192
-
139
+ });
193
140
 
141
+ }).timeout(20000);
194
142
 
195
143
 
196
144
 
@@ -394,7 +342,7 @@ describe('FaqKBRoute', () => {
394
342
  .post('/'+ savedProject._id + '/faq/uploadcsv')
395
343
  .auth(email, pwd)
396
344
  .set('Content-Type', 'text/csv')
397
- .attach('uploadFile', fs.readFileSync(path.resolve(__dirname,'./example-faqs.csv')))
345
+ .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-faqs.csv')), 'example-faqs.csv')
398
346
  .field('id_faq_kb', id_faq_kb)
399
347
  .field('delimiter', ';')
400
348
  // .send({id_faq_kb: id_faq_kb})
@@ -448,7 +396,7 @@ describe('FaqKBRoute', () => {
448
396
  .post('/'+ savedProject._id + '/faq/uploadcsv')
449
397
  .auth(email, pwd)
450
398
  .set('Content-Type', 'text/csv')
451
- .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-faqs.csv')))
399
+ .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-faqs.csv')), 'example-faqs.csv')
452
400
  .field('id_faq_kb', id_faq_kb)
453
401
  .field('delimiter', ';')
454
402
  // .send({id_faq_kb: id_faq_kb})
@@ -6,11 +6,15 @@ var projectService = require('../services/projectService');
6
6
  var userService = require('../services/userService');
7
7
  var faqService = require('../services/faqService');
8
8
 
9
+
10
+
9
11
  //Require the dev-dependencies
10
12
  let chai = require('chai');
11
13
  let chaiHttp = require('chai-http');
12
14
  let server = require('../app');
13
15
  let should = chai.should();
16
+ var fs = require('fs');
17
+ const path = require('path');
14
18
 
15
19
  // chai.config.includeStack = true;
16
20
 
@@ -21,104 +25,238 @@ chai.use(chaiHttp);
21
25
 
22
26
  describe('FaqKBRoute', () => {
23
27
 
24
- describe('/create', () => {
25
-
26
-
28
+ describe('/create', () => {
29
+
27
30
 
28
- it('create', (done) => {
31
+ it('create', (done) => {
29
32
 
30
-
31
- // this.timeout();
32
33
 
33
- var email = "test-signup-" + Date.now() + "@email.com";
34
- var pwd = "pwd";
34
+ // this.timeout();
35
35
 
36
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
37
- projectService.create("test-faqkb-create", savedUser._id).then(function(savedProject) {
36
+ var email = "test-signup-" + Date.now() + "@email.com";
37
+ var pwd = "pwd";
38
+
39
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
40
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
38
41
  chai.request(server)
39
- .post('/'+ savedProject._id + '/faq_kb')
42
+ .post('/' + savedProject._id + '/faq_kb')
40
43
  .auth(email, pwd)
41
- .send({"name":"testbot", type: "external", language: 'fr'})
44
+ .send({ "name": "testbot", type: "external", language: 'fr' })
42
45
  .end((err, res) => {
43
46
  //console.log("res", res);
44
- console.log("res.body", res.body);
47
+ console.log("res.body", res.body);
45
48
  res.should.have.status(200);
46
49
  res.body.should.be.a('object');
47
- expect(res.body.name).to.equal("testbot");
48
- expect(res.body.language).to.equal("fr");
49
-
50
+ expect(res.body.name).to.equal("testbot");
51
+ expect(res.body.language).to.equal("fr");
52
+
50
53
  done();
51
54
  });
52
55
 
53
-
54
- });
56
+
55
57
  });
56
-
57
- }).timeout(20000);
58
+ });
59
+
60
+ }).timeout(20000);
61
+
62
+
63
+ it('create with template example', (done) => {
64
+
65
+ var email = "test-signup-" + Date.now() + "@email.com";
66
+ var pwd = "pwd";
67
+
68
+ userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
69
+ projectService.create("test-faqkb-create", savedUser._id).then((savedProject) => {
70
+
71
+ chai.request(server)
72
+ .post('/'+ savedProject._id + '/faq_kb')
73
+ .auth(email, pwd)
74
+ .send({"name":"testbot", type: "internal", template: "example" })
75
+ .end((err, res) => {
76
+ //console.log("res", res);
77
+ console.log("res.body", res.body);
78
+ res.should.have.status(200);
79
+ res.body.should.be.a('object');
80
+ expect(res.body.name).to.equal("testbot");
81
+ var id_faq_kb = res.body._id;
82
+
83
+ chai.request(server)
84
+ .get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
85
+ .auth(email, pwd)
86
+ .end((err, res) => {
87
+ console.log("faq_list: ", res.body);
88
+ res.should.have.status(200);
89
+ res.body.should.be.an('array').that.is.not.empty;
90
+
91
+ done();
92
+
93
+ })
94
+
95
+
96
+
97
+ });
98
+ })
99
+ })
100
+ })
101
+
102
+ it('import json', (done) => {
58
103
 
104
+ var email = "test-signup-" + Date.now() + "@email.com";
105
+ var pwd = "pwd";
59
106
 
107
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
108
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
109
+
110
+ chai.request(server)
111
+ .post('/' + savedProject._id + '/faq_kb')
112
+ .auth(email, pwd)
113
+ .send({ "name": "testbot", type: "internal", language: 'fr' })
114
+ .end((err, res) => {
115
+ console.log("res.body: ", res.body);
116
+ res.should.have.status(200);
117
+ res.body.should.be.a('object');
118
+ expect(res.body.name).to.equal("testbot");
119
+ expect(res.body.language).to.equal("fr");
120
+ let id_faq_kb = res.body._id;
60
121
 
122
+ chai.request(server)
123
+ .post('/' + savedProject._id + '/faq_kb/importjson/' + id_faq_kb)
124
+ .auth(email, pwd)
125
+ .set('Content-Type', 'text/plain')
126
+ .attach('uploadFile', fs.readFileSync(path.resolve(__dirname, './example-json.txt')), 'example-json.txt')
127
+ .end((err, res) => {
128
+ console.log("import json res: ", res.body);
129
+ res.should.have.status(200);
130
+ res.should.be.a('object');
131
+ expect(res.body.name).to.equal("examplebot");
132
+ expect(res.body.language).to.equal("en");
61
133
 
134
+ chai.request(server)
135
+ .get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
136
+ .auth(email, pwd)
137
+ .end((err, res) => {
138
+ console.log("faq_list: ", res.body);
139
+ res.should.have.status(200);
140
+ res.body.should.be.an('array').that.is.not.empty;
141
+
142
+ done();
143
+
144
+ })
145
+ })
146
+ })
147
+ })
148
+ })
149
+ })
62
150
 
63
151
 
152
+ it('export json', (done) => {
64
153
 
65
- // mocha test/faqkbRoute.js --grep 'train'
66
- it('train', (done) => {
67
154
 
68
-
69
- // this.timeout();
70
-
71
- var email = "test-signup-" + Date.now() + "@email.com";
72
- var pwd = "pwd";
73
-
74
- userService.signup( email ,pwd, "Test Firstname", "Test lastname").then(function(savedUser) {
75
- projectService.create("test-faqkb-train", savedUser._id).then(function(savedProject) {
76
- faqService.create("testbot", "http://54.228.177.1644", savedProject._id, savedUser._id).then(function(savedBot) {
155
+ // this.timeout();
156
+
157
+ var email = "test-signup-" + Date.now() + "@email.com";
158
+ var pwd = "pwd";
159
+
160
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
161
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
162
+
163
+ chai.request(server)
164
+ .post('/' + savedProject._id + '/faq_kb')
165
+ .auth(email, pwd)
166
+ .send({ "name": "testbot", type: "internal", template: "example", language: 'fr' })
167
+ .end((err, res) => {
168
+ //console.log("res", res);
169
+ console.log("res.body", res.body);
170
+ res.should.have.status(200);
171
+ res.body.should.be.a('object');
172
+ expect(res.body.name).to.equal("testbot");
173
+ expect(res.body.language).to.equal("fr");
174
+ let id_faq_kb = res.body._id;
175
+ console.log("res.body._id: ", res.body._id)
176
+
177
+ chai.request(server)
178
+ .get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
179
+ .auth(email, pwd)
180
+ .end((err, res) => {
181
+ console.log("faq_list: ", res.body);
182
+ res.should.have.status(200);
183
+ res.body.should.be.an('array').that.is.not.empty;
184
+
185
+ chai.request(server)
186
+ .get('/' + savedProject._id + '/faq_kb/exportjson/' + id_faq_kb)
187
+ .auth(email, pwd)
188
+ .end((err, res) => {
189
+ console.log("export json res: ", res.body);
190
+ res.should.have.status(200);
191
+ //res.body.should.be.a('string');
192
+
193
+ done();
194
+ })
195
+ })
196
+ });
197
+ });
198
+ });
199
+
200
+ }).timeout(20000);
201
+
202
+
203
+ // mocha test/faqkbRoute.js --grep 'train'
204
+ it('train', (done) => {
205
+
206
+
207
+ // this.timeout();
208
+
209
+ var email = "test-signup-" + Date.now() + "@email.com";
210
+ var pwd = "pwd";
211
+
212
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
213
+ projectService.create("test-faqkb-train", savedUser._id).then(function (savedProject) {
214
+ faqService.create("testbot", "http://54.228.177.1644", savedProject._id, savedUser._id).then(function (savedBot) {
77
215
 
78
216
  var newFaq = new Faq({
79
- id_faq_kb: savedBot._id,
80
- question: "question1\nquestion2",
81
- answer: "answer",
82
- id_project: savedProject._id,
83
- topic: "default",
84
- createdBy: savedUser._id,
85
- updatedBy: savedUser._id
217
+ id_faq_kb: savedBot._id,
218
+ question: "question1\nquestion2",
219
+ answer: "answer",
220
+ id_project: savedProject._id,
221
+ topic: "default",
222
+ createdBy: savedUser._id,
223
+ updatedBy: savedUser._id
86
224
  });
87
-
225
+
88
226
  newFaq.save(function (err, savedFaq) {
89
- console.log("err", err);
90
- console.log("savedFaq", savedFaq);
91
- expect(savedBot.name).to.equal("testbot");
92
- expect(savedBot.secret).to.not.equal(null);
93
-
94
- chai.request(server)
95
- .post('/'+ savedProject._id + '/faq_kb/train')
96
- .auth(email, pwd)
97
- .send({"id_faq_kb":savedBot._id})
98
- .end((err, res) => {
99
- //console.log("res", res);
100
- console.log("res.body", res.body);
101
- res.should.have.status(200);
102
- res.body.should.be.a('object');
103
- expect(res.body.train.nlu.intent).to.equal(savedBot.intent_display_name);
104
- // expect(res.body.text).to.equal("addestramento avviato");
105
-
106
-
107
- done();
108
- });
109
-
110
-
111
- });
227
+ console.log("err", err);
228
+ console.log("savedFaq", savedFaq);
229
+ expect(savedBot.name).to.equal("testbot");
230
+ expect(savedBot.secret).to.not.equal(null);
231
+
232
+ chai.request(server)
233
+ .post('/' + savedProject._id + '/faq_kb/train')
234
+ .auth(email, pwd)
235
+ .send({ "id_faq_kb": savedBot._id })
236
+ .end((err, res) => {
237
+ //console.log("res", res);
238
+ console.log("res.body", res.body);
239
+ res.should.have.status(200);
240
+ res.body.should.be.a('object');
241
+ expect(res.body.train.nlu.intent).to.equal(savedBot.intent_display_name);
242
+ // expect(res.body.text).to.equal("addestramento avviato");
243
+
244
+
245
+ done();
246
+ });
247
+
248
+
249
+ });
112
250
  });
113
- });
251
+ });
114
252
  });
115
253
  }).timeout(20000);
116
-
117
-
118
254
 
119
255
 
120
256
 
121
- });
257
+
258
+
259
+ });
122
260
 
123
261
  });
124
262