@tiledesk/tiledesk-server 2.10.87 → 2.10.89

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.
@@ -303,20 +303,23 @@ describe('FaqKBRoute', () => {
303
303
  expect(res.body.name).to.equal("testbot");
304
304
  var id_faq_kb = res.body._id;
305
305
 
306
- chai.request(server)
307
- .get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
308
- .auth(email, pwd)
309
- .end((err, res) => {
310
-
311
- if (err) { console.error("err: ", err); }
312
- if (log) { console.log("res.body", res.body); }
313
-
314
- res.should.have.status(200);
315
- res.body.should.be.an('array').that.is.not.empty;
316
-
317
- done();
306
+ setTimeout(() => {
318
307
 
319
- })
308
+ chai.request(server)
309
+ .get('/' + savedProject._id + '/faq?id_faq_kb=' + id_faq_kb)
310
+ .auth(email, pwd)
311
+ .end((err, res) => {
312
+
313
+ if (err) { console.error("err: ", err); }
314
+ if (log) { console.log("res.body", res.body); }
315
+
316
+ res.should.have.status(200);
317
+ res.body.should.be.an('array').that.is.not.empty;
318
+
319
+ done();
320
+
321
+ })
322
+ }, 1000)
320
323
 
321
324
 
322
325
 
@@ -401,7 +404,7 @@ describe('FaqKBRoute', () => {
401
404
 
402
405
  if (err) { console.error("err: ", err); }
403
406
  if (log) { console.log("res.body", res.body); }
404
- console.log("res.body", res.body);
407
+
405
408
  res.should.have.status(200);
406
409
 
407
410
  done();
@@ -415,7 +418,6 @@ describe('FaqKBRoute', () => {
415
418
 
416
419
  });
417
420
 
418
-
419
421
  describe('Update', () => {
420
422
 
421
423
  it('update-chatbot-no-slug', (done) => {
@@ -835,9 +837,10 @@ describe('FaqKBRoute', () => {
835
837
  projectService.create('test-faqkb-create', savedUser._id).then((savedProject) => {
836
838
 
837
839
  chai.request(server)
838
- .post('/' + savedProject._id + '/faq_kb?replace=true')
840
+ //.post('/' + savedProject._id + '/faq_kb?replace=true')
841
+ .post('/' + savedProject._id + '/faq_kb')
839
842
  .auth(email, pwd)
840
- .send({ "name": "testbot", type: "tilebot", language: "en", template: "blank " })
843
+ .send({ "name": "testbot", type: "tilebot", language: "en", template: "empty" })
841
844
  .end((err, res) => {
842
845
 
843
846
  if (err) { console.error("err: ", err); }
@@ -870,11 +873,11 @@ describe('FaqKBRoute', () => {
870
873
 
871
874
  if (err) { console.error("err: ", err); }
872
875
  if (log) { console.log("import json res: ", JSON.stringify(res.body, null, 2)); }
873
-
876
+
874
877
  res.should.have.status(200);
875
- //res.should.be.a('object');
876
- //expect(res.body.name).to.equal("examplebot");
877
- //expect(res.body.language).to.equal("en");
878
+ res.should.be.a('object');
879
+ expect(res.body.name).to.equal("example bot");
880
+ expect(res.body.language).to.equal("en");
878
881
 
879
882
  done();
880
883
  })
@@ -986,7 +989,7 @@ describe('FaqKBRoute', () => {
986
989
 
987
990
  if (err) { console.error("err: ", err) };
988
991
  if (log) { console.log("res.body: ", res.body) };
989
-
992
+
990
993
  res.should.have.status(200);
991
994
  //res.body.should.be.a('string');
992
995
 
@@ -1082,7 +1085,7 @@ describe('FaqKBRoute', () => {
1082
1085
 
1083
1086
  if (err) { console.error("err: ", err) };
1084
1087
  if (log) { console.log("res.body: ", res.body) };
1085
- console.log("res.body: ", res.body)
1088
+
1086
1089
  res.should.have.status(200);
1087
1090
  res.should.be.a('object');
1088
1091
  expect(res.body.name).to.equal("Flow 1");
@@ -1113,6 +1116,145 @@ describe('FaqKBRoute', () => {
1113
1116
 
1114
1117
  })
1115
1118
 
1119
+ describe('Delete', () => {
1120
+
1121
+ it('logical-delete-with-ttl', (done) => {
1122
+
1123
+ var email = "test-signup-" + Date.now() + "@email.com";
1124
+ var pwd = "pwd";
1125
+
1126
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1127
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
1128
+
1129
+ chai.request(server)
1130
+ .post('/' + savedProject._id + '/faq_kb')
1131
+ .auth(email, pwd)
1132
+ .send({ name: "testbot", type: "tilebot", subtype: "chatbot", template: "blank", language: 'en' })
1133
+ .end((err, res) => {
1134
+
1135
+ if (err) { console.error("err: ", err); }
1136
+ if (log) { console.log("res.body", res.body); }
1137
+
1138
+ res.should.have.status(200);
1139
+ res.body.should.be.a('object');
1140
+ expect(res.body.name).to.equal("testbot");
1141
+ expect(res.body.language).to.equal("en");
1142
+
1143
+ let chatbot_id = res.body._id;
1144
+
1145
+ chai.request(server)
1146
+ .put('/' + savedProject._id + '/faq_kb/' + chatbot_id)
1147
+ .auth(email, pwd)
1148
+ .send({ trashed: true })
1149
+ .end((err, res) => {
1150
+
1151
+ if (err) { console.error("err: ", err); }
1152
+ if (log) { console.log("res.body", res.body); }
1153
+
1154
+ res.should.have.status(200);
1155
+ res.body.should.be.a('object');
1156
+ expect(res.body.trashed).to.equal(true);
1157
+ expect(res.body.trashedAt).to.exist;
1158
+
1159
+ chai.request(server)
1160
+ .get('/' + savedProject._id + '/faq/?id_faq_kb=' + chatbot_id)
1161
+ .auth(email, pwd)
1162
+ .end((err, res) => {
1163
+
1164
+ if (err) { console.error("err: ", err); }
1165
+ if (log) { console.log("res.body", res.body); }
1166
+
1167
+ res.should.have.status(200);
1168
+ res.body.should.be.a('array');
1169
+ expect(res.body.length).to.equal(3);
1170
+ expect(res.body[0].trashed).to.equal(true);
1171
+ expect(res.body[0].trashedAt).to.exist;
1172
+
1173
+ done();
1174
+ })
1175
+
1176
+ })
1177
+ });
1178
+ });
1179
+ });
1180
+ })
1181
+
1182
+ it('logical-webhook-delete-with-ttl', (done) => {
1183
+
1184
+ var email = "test-signup-" + Date.now() + "@email.com";
1185
+ var pwd = "pwd";
1186
+
1187
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1188
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
1189
+
1190
+ chai.request(server)
1191
+ .post('/' + savedProject._id + '/faq_kb')
1192
+ .auth(email, pwd)
1193
+ .send({ name: "test-webhook", type: "tilebot", subtype: "webhook", template: "blank_webhook", language: 'en' })
1194
+ .end((err, res) => {
1195
+
1196
+ if (err) { console.error("err: ", err); }
1197
+ if (log) { console.log("res.body", res.body); }
1198
+
1199
+ res.should.have.status(200);
1200
+ res.body.should.be.a('object');
1201
+ expect(res.body.name).to.equal("test-webhook");
1202
+ expect(res.body.language).to.equal("en");
1203
+
1204
+ let chatbot_id = res.body._id;
1205
+
1206
+ chai.request(server)
1207
+ .post('/' + savedProject._id + '/webhooks')
1208
+ .auth(email, pwd)
1209
+ .send({ chatbot_id: chatbot_id, block_id: "example-block-id", async: false })
1210
+ .end((err, res) => {
1211
+
1212
+ if (err) { console.error("err: ", err); }
1213
+ if (log) { console.log("res.body", res.body); }
1214
+
1215
+ res.should.have.status(200);
1216
+ res.body.should.be.a('object');
1217
+
1218
+ chai.request(server)
1219
+ .put('/' + savedProject._id + '/faq_kb/' + chatbot_id)
1220
+ .auth(email, pwd)
1221
+ .send({ trashed: true })
1222
+ .end((err, res) => {
1223
+
1224
+ if (err) { console.error("err: ", err); }
1225
+ if (log) { console.log("res.body", res.body); }
1226
+
1227
+ res.should.have.status(200);
1228
+ res.body.should.be.a('object');
1229
+ expect(res.body.trashed).to.equal(true);
1230
+ expect(res.body.trashedAt).to.exist;
1231
+
1232
+ chai.request(server)
1233
+ .get('/' + savedProject._id + '/faq/?id_faq_kb=' + chatbot_id)
1234
+ .auth(email, pwd)
1235
+ .end((err, res) => {
1236
+
1237
+ if (err) { console.error("err: ", err); }
1238
+ if (log) { console.log("res.body", res.body); }
1239
+
1240
+ res.should.have.status(200);
1241
+ res.body.should.be.a('array');
1242
+ expect(res.body.length).to.equal(2);
1243
+ expect(res.body[0].trashed).to.equal(true);
1244
+ expect(res.body[0].trashedAt).to.exist;
1245
+
1246
+ done();
1247
+ })
1248
+
1249
+ })
1250
+ })
1251
+
1252
+ });
1253
+ });
1254
+ });
1255
+ })
1256
+ })
1257
+
1116
1258
  // describe('Train', () => {
1117
1259
 
1118
1260
  // it('train', (done) => {
@@ -4,6 +4,7 @@ process.env.LOG_LEVEL = 'error';
4
4
 
5
5
  var projectService = require('../services/projectService');
6
6
  var userService = require('../services/userService');
7
+ let chatbot_mock = require('./chatbot-mock');
7
8
  let log = false;
8
9
 
9
10
  //Require the dev-dependencies
@@ -59,6 +60,8 @@ describe('WebhookRoute', () => {
59
60
  expect(res.body.id_project).to.equal(savedProject._id.toString());
60
61
  expect(res.body.chatbot_id).to.equal(chatbot_id);
61
62
  expect(res.body.block_id).to.equal(webhook_intent_id);
63
+ expect(res.body.name).to.equal("testbot-webhook");
64
+ expect(res.body.enabled).to.equal(true);
62
65
  should.exist(res.body.webhook_id)
63
66
  expect(res.body).to.haveOwnProperty('webhook_id')
64
67
  expect(res.body.webhook_id).to.have.length(32)
@@ -124,6 +127,26 @@ describe('WebhookRoute', () => {
124
127
  expect(res.body).to.haveOwnProperty('webhook_id')
125
128
  expect(res.body.webhook_id).to.have.length(32)
126
129
 
130
+ let webhook_id = res.body.webhook_id;
131
+
132
+ chai.request(server)
133
+ .get('/' + savedProject._id + '/webhooks/id/' + webhook_id)
134
+ .auth(email, pwd)
135
+ .end((err, res) => {
136
+ if (err) { console.error("err: ", err); }
137
+ if (log) { console.log("res.body", res.body); }
138
+
139
+ res.should.have.status(200);
140
+ res.body.should.be.a('object');
141
+ expect(res.body.async).to.equal(true);
142
+ expect(res.body.id_project).to.equal(savedProject._id.toString());
143
+ expect(res.body.chatbot_id).to.equal(chatbot_id);
144
+ expect(res.body.block_id).to.equal(webhook_intent_id);
145
+ should.exist(res.body.webhook_id)
146
+ expect(res.body).to.haveOwnProperty('webhook_id')
147
+ expect(res.body.webhook_id).to.have.length(32)
148
+ })
149
+
127
150
  })
128
151
 
129
152
  done();
@@ -301,7 +324,144 @@ describe('WebhookRoute', () => {
301
324
  res.should.have.status(200);
302
325
  res.body.should.be.a('object');
303
326
  expect(res.body.success).to.equal(true);
304
- expect(res.body.message).to.equal("Webhook for chatbot " + chatbot_id + " deleted successfully")
327
+ expect(res.body.message).to.equal("Webhook for chatbot " + chatbot_id + " deleted successfully")
328
+
329
+ done();
330
+
331
+ });
332
+ });
333
+
334
+ });
335
+ });
336
+ });
337
+ })
338
+
339
+ it('preload-and-run-webhook', (done) => {
340
+
341
+ var email = "test-signup-" + Date.now() + "@email.com";
342
+ var pwd = "pwd";
343
+
344
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
345
+ projectService.create("test-webhook-preload", savedUser._id).then(function (savedProject) {
346
+
347
+ chai.request(server)
348
+ .post('/' + savedProject._id + '/faq_kb')
349
+ .auth(email, pwd)
350
+ .send({ name: "testbot", type: "tilebot", subtype: "webhook", language: "en", template: "blank" })
351
+ .end((err, res) => {
352
+
353
+ if (err) { console.error("err: ", err); }
354
+ if (log) { console.log("res.body", res.body); }
355
+
356
+ res.should.have.status(200);
357
+ res.body.should.be.a('object');
358
+
359
+ let chatbot_id = res.body._id;
360
+ let webhook_intent_id = "3bfda939-ff76-4762-bbe0-fc0f0dc4c777"
361
+
362
+ chai.request(server)
363
+ .post('/' + savedProject._id + '/webhooks/')
364
+ .auth(email, pwd)
365
+ .send({ chatbot_id: chatbot_id, block_id: webhook_intent_id })
366
+ .end((err, res) => {
367
+
368
+ if (err) { console.error("err: ", err); }
369
+ if (log) { console.log("res.body", res.body); }
370
+
371
+ res.should.have.status(200);
372
+ res.body.should.be.a('object');
373
+
374
+ let webhook_id = res.body.webhook_id;
375
+
376
+ chai.request(server)
377
+ .post('/' + savedProject._id + '/webhooks/preload/' + webhook_id)
378
+ .auth(email, pwd)
379
+ .end((err, res) => {
380
+
381
+ if (err) { console.error("err: ", err); }
382
+ if (log) { console.log("res.body", res.body); }
383
+
384
+ res.should.have.status(200);
385
+ res.body.should.be.a('object');
386
+ expect(res.body.success).to.equal(true);
387
+ expect(res.body.message).to.equal("Webhook preloaded successfully");
388
+ assert(res.body.request_id.startsWith('automation-request-' + savedProject._id ))
389
+
390
+ chai.request(server)
391
+ .post('/webhook/' + webhook_id + "/dev")
392
+ .auth(email, pwd)
393
+ .end((err, res) => {
394
+
395
+ if (err) { console.error("err: ", err); }
396
+ if (log) { console.log("res.body", res.body); }
397
+
398
+ res.should.have.status(200);
399
+ res.body.should.be.a('object');
400
+ expect(res.body.success).to.equal(true);
401
+ expect(res.body.message).to.equal("Webhook disabled in test mode");
402
+
403
+
404
+ done();
405
+
406
+ });
407
+ })
408
+ });
409
+
410
+ });
411
+ });
412
+ });
413
+ })
414
+
415
+ it('run-webhook-without-preloading', (done) => {
416
+
417
+ var email = "test-signup-" + Date.now() + "@email.com";
418
+ var pwd = "pwd";
419
+
420
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
421
+ projectService.create("test-webhook-preload", savedUser._id).then(function (savedProject) {
422
+
423
+ chai.request(server)
424
+ .post('/' + savedProject._id + '/faq_kb')
425
+ .auth(email, pwd)
426
+ .send({ name: "testbot", type: "tilebot", subtype: "webhook", language: "en", template: "blank" })
427
+ .end((err, res) => {
428
+
429
+ if (err) { console.error("err: ", err); }
430
+ if (log) { console.log("res.body", res.body); }
431
+
432
+ res.should.have.status(200);
433
+ res.body.should.be.a('object');
434
+
435
+ let chatbot_id = res.body._id;
436
+ let webhook_intent_id = "3bfda939-ff76-4762-bbe0-fc0f0dc4c777"
437
+
438
+ chai.request(server)
439
+ .post('/' + savedProject._id + '/webhooks/')
440
+ .auth(email, pwd)
441
+ .send({ chatbot_id: chatbot_id, block_id: webhook_intent_id })
442
+ .end((err, res) => {
443
+
444
+ if (err) { console.error("err: ", err); }
445
+ if (log) { console.log("res.body", res.body); }
446
+
447
+ res.should.have.status(200);
448
+ res.body.should.be.a('object');
449
+
450
+ let webhook_id = res.body.webhook_id;
451
+
452
+ chai.request(server)
453
+ .post('/webhook/' + webhook_id + "/dev")
454
+ .auth(email, pwd)
455
+ .end((err, res) => {
456
+
457
+ if (err) { console.error("err: ", err); }
458
+ if (log) { console.log("res.body", res.body); }
459
+
460
+ res.should.have.status(422);
461
+ res.body.should.be.a('object');
462
+ expect(res.body.success).to.equal(false);
463
+ expect(res.body.message).to.equal("Development webhook is currently turned off");
464
+ expect(res.body.code).to.equal(13001);
305
465
 
306
466
  done();
307
467
 
@@ -313,7 +473,7 @@ describe('WebhookRoute', () => {
313
473
  });
314
474
  })
315
475
 
316
- it('run-webhook', (done) => {
476
+ it('run-draft-webhook', (done) => {
317
477
 
318
478
  var email = "test-signup-" + Date.now() + "@email.com";
319
479
  var pwd = "pwd";
@@ -372,4 +532,89 @@ describe('WebhookRoute', () => {
372
532
  });
373
533
  });
374
534
  })
535
+
536
+ it('run-published-webhook', (done) => {
537
+
538
+ var email = "test-signup-" + Date.now() + "@email.com";
539
+ var pwd = "pwd";
540
+
541
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
542
+ projectService.create("test-webhook-create", savedUser._id).then(function (savedProject) {
543
+
544
+ class chatbot_service {
545
+ async fork(id_faq_kb, api_url, token, project_id) {
546
+ let forked_bot_id = id_faq_kb.substr(id_faq_kb, id_faq_kb.length - 4) + "1111";
547
+ return { bot_id: forked_bot_id }
548
+ }
549
+
550
+ async setModified(chatbot_id, modified) {
551
+ return true;
552
+ }
553
+ }
554
+
555
+ server.set('chatbot_service', new chatbot_service());
556
+
557
+ chai.request(server)
558
+ .post('/' + savedProject._id + '/faq_kb')
559
+ .auth(email, pwd)
560
+ .send({ "name": "testbot", type: "tilebot", language: "en", template: "blank" })
561
+ .end((err, res) => {
562
+
563
+ if (err) { console.error("err: ", err); }
564
+ if (log) { console.log("res.body", res.body); }
565
+
566
+ res.should.have.status(200);
567
+ res.body.should.be.a('object');
568
+
569
+ let chatbot_id = res.body._id;
570
+ let webhook_intent_id = "3bfda939-ff76-4762-bbe0-fc0f0dc4c777"
571
+
572
+ chai.request(server)
573
+ .put('/' + savedProject._id + '/faq_kb/' + chatbot_id + '/publish')
574
+ .auth(email, pwd)
575
+ .end((err, res) => {
576
+
577
+ if (err) { console.error("err: ", err); }
578
+ if (log) { console.log("res.body", res.body); }
579
+
580
+ res.should.have.status(200);
581
+ res.body.should.be.a('object');
582
+
583
+ chai.request(server)
584
+ .post('/' + savedProject._id + '/webhooks/')
585
+ .auth(email, pwd)
586
+ .send({ chatbot_id: chatbot_id, block_id: webhook_intent_id })
587
+ .end((err, res) => {
588
+
589
+ if (err) { console.error("err: ", err); }
590
+ if (log) { console.log("res.body", res.body); }
591
+
592
+ res.should.have.status(200);
593
+ res.body.should.be.a('object');
594
+
595
+ let webhook_id = res.body.webhook_id;
596
+
597
+ chai.request(server)
598
+ .post('/webhook/' + webhook_id)
599
+ .auth(email, pwd)
600
+ .end((err, res) => {
601
+
602
+ if (err) { console.error("err: ", err); }
603
+ if (log) { console.log("res.body", res.body); }
604
+
605
+ res.should.have.status(200);
606
+ res.body.should.be.a('object');
607
+ expect(res.body.success).to.equal(true);
608
+ expect(res.body.message).to.equal("Webhook disabled in test mode");
609
+
610
+ done();
611
+
612
+ });
613
+ });
614
+
615
+ })
616
+ });
617
+ });
618
+ });
619
+ })
375
620
  });
package/utils/TdCache.js CHANGED
@@ -255,11 +255,11 @@ class TdCache {
255
255
 
256
256
  async del(key, callback) {
257
257
  return new Promise( async (resolve, reject) => {
258
- await this.client.del(key);
258
+ let result = await this.client.del(key);
259
259
  if (callback) {
260
- callback();
260
+ callback(result);
261
261
  }
262
- return resolve();
262
+ return resolve(result);
263
263
  })
264
264
  }
265
265
  }