@tiledesk/tiledesk-server 2.4.99 → 2.4.101

Sign up to get free protection for your applications and to get access to all the features.
@@ -57,7 +57,11 @@ class TrainingService {
57
57
  if (webhook_enabled === true) {
58
58
  json.webhook_url = process.env.API_URL || configGlobal.apiUrl + "/" + faq_kb.id_project + "/bots/" + faq_kb._id+"/training"
59
59
  }
60
-
60
+
61
+ let index = faqs.findIndex(f => f.intent_display_name === "start");
62
+ faqs.slice(index);
63
+
64
+
61
65
  faqs.forEach((f) => {
62
66
  if (f.enabled == true) {
63
67
  let intent = {
@@ -74,7 +78,7 @@ class TrainingService {
74
78
  }
75
79
  })
76
80
 
77
- winston.debug("training json: \n", json);
81
+ winston.info("training json: \n", json);
78
82
 
79
83
  await axios({
80
84
  url: training_api_url,
@@ -0,0 +1,134 @@
1
+ //During the test the env variable is set to test
2
+ process.env.NODE_ENV = 'test';
3
+
4
+ var userService = require('../services/userService');
5
+ var projectService = require('../services/projectService');
6
+
7
+ let log = true;
8
+
9
+ //Require the dev-dependencies
10
+ let chai = require('chai');
11
+ let chaiHttp = require('chai-http');
12
+ let server = require('../app');
13
+ let should = chai.should();
14
+ var fs = require('fs');
15
+ const path = require('path');
16
+
17
+ // chai.config.includeStack = true;
18
+
19
+ var expect = chai.expect;
20
+ var assert = chai.assert;
21
+
22
+ chai.use(chaiHttp);
23
+
24
+ describe('KbRoute', () => {
25
+
26
+ describe('/create', () => {
27
+
28
+ it('createNewKb', (done) => {
29
+
30
+ var email = "test-signup-" + Date.now() + "@email.com";
31
+ var pwd = "pwd";
32
+
33
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
34
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
35
+
36
+ let kb = {
37
+ name: "example_name5",
38
+ type: "url",
39
+ source: "https://www.exampleurl5.com",
40
+ content: ""
41
+ }
42
+
43
+ chai.request(server)
44
+ .post('/' + savedProject._id + '/kb')
45
+ .auth(email, pwd)
46
+ .send(kb) // can be empty
47
+ .end((err, res) => {
48
+ if (log) { console.log("create kb res.body: ", res.body); }
49
+ res.should.have.status(200);
50
+ // res.body.should.be.a('object');
51
+ // expect(res.body.id_project).to.equal(savedProject._id.toString());
52
+
53
+ done();
54
+ // chai.request(server)
55
+ // .get('/' + savedProject._id + "/kbsettings")
56
+ // .auth(email, pwd)
57
+ // .end((err, res) => {
58
+ // if (log) { console.log("get kbsettings res.body: ", res.body); }
59
+ // res.should.have.status(200);
60
+ // res.body.should.be.a('object');
61
+ // expect(res.body.id_project).to.equal(savedProject._id.toString())
62
+ // expect(res.body.maxKbsNumber).to.equal(3);
63
+ // expect(res.body.maxPagesNumber).to.equal(1000);
64
+ // expect(res.body.kbs).is.an('array').that.is.empty;
65
+
66
+
67
+ // })
68
+
69
+ })
70
+
71
+ });
72
+ });
73
+
74
+ });
75
+
76
+ it('scrapeSingle', (done) => {
77
+
78
+ var email = "test-signup-" + Date.now() + "@email.com";
79
+ var pwd = "pwd";
80
+
81
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
82
+ projectService.create("test-faqkb-create", savedUser._id).then(function (savedProject) {
83
+
84
+ let kb = {
85
+ name: "example_name6",
86
+ type: "url",
87
+ source: "https://www.exampleurl6.com",
88
+ content: ""
89
+ }
90
+
91
+ chai.request(server)
92
+ .post('/' + savedProject._id + '/kb')
93
+ .auth(email, pwd)
94
+ .send(kb) // can be empty
95
+ .end((err, res) => {
96
+ if (log) { console.log("create kb res.body: ", res.body); }
97
+ res.should.have.status(200);
98
+
99
+ let kbid = res.body.value._id;
100
+ console.log("kbid: ", kbid)
101
+ chai.request(server)
102
+ .post('/' + savedProject._id + "/kb/scrape/single")
103
+ .auth(email, pwd)
104
+ .send({ id: kbid })
105
+ .end((err, res) => {
106
+ if (log) { console.log("single scrape res.body: ", res.body); }
107
+ //res.should.have.status(200);
108
+ // res.body.should.be.a('object');
109
+ // expect(res.body.id_project).to.equal(savedProject._id.toString())
110
+ // expect(res.body.maxKbsNumber).to.equal(3);
111
+ // expect(res.body.maxPagesNumber).to.equal(1000);
112
+ // expect(res.body.kbs).is.an('array').that.is.empty;
113
+ done();
114
+
115
+ })
116
+
117
+
118
+ // res.body.should.be.a('object');
119
+ // expect(res.body.id_project).to.equal(savedProject._id.toString());
120
+
121
+
122
+
123
+
124
+ })
125
+
126
+ });
127
+ });
128
+
129
+ });
130
+
131
+ })
132
+ });
133
+
134
+
@@ -25,7 +25,7 @@ describe('KbSettingsRoute', () => {
25
25
 
26
26
  describe('/create', () => {
27
27
 
28
- it('create kb settings', (done) => {
28
+ it('createKbSettings', (done) => {
29
29
 
30
30
  var email = "test-signup-" + Date.now() + "@email.com";
31
31
  var pwd = "pwd";
@@ -65,7 +65,7 @@ describe('KbSettingsRoute', () => {
65
65
 
66
66
  });
67
67
 
68
- it('create kb settings if not exists', (done) => {
68
+ it('createKbSettingsIfNotExists', (done) => {
69
69
 
70
70
  var email = "test-signup-" + Date.now() + "@email.com";
71
71
  var pwd = "pwd";
@@ -93,7 +93,7 @@ describe('KbSettingsRoute', () => {
93
93
  });
94
94
 
95
95
 
96
- it('add kb to kb settings', (done) => {
96
+ it('addKbToKbSettings', (done) => {
97
97
 
98
98
  var email = "test-signup-" + Date.now() + "@email.com";
99
99
  var pwd = "pwd";
@@ -111,25 +111,27 @@ describe('KbSettingsRoute', () => {
111
111
  res.body.should.be.a('object');
112
112
  expect(res.body.id_project).to.equal(savedProject._id.toString());
113
113
 
114
+ let settings_id = res.body._id;
115
+
114
116
  chai.request(server)
115
- .post('/' + savedProject._id + "/kbsettings/" + res.body._id)
117
+ .post('/' + savedProject._id + "/kbsettings/" + settings_id)
116
118
  .auth(email, pwd)
117
119
  .send({ name: "exampleurl.com/kb/", url: "https://exampleurl.com/kb/" })
118
120
  .end((err, res) => {
119
121
  if (log) { console.log("add kb to kb settings res.body: ", res.body); }
120
122
  res.should.have.status(200);
121
123
  res.body.should.be.a('object');
122
- expect(res.body.kbs).to.have.length(1)
124
+ //expect(res.body.kbs).to.have.length(1)
123
125
 
124
126
  chai.request(server)
125
- .post('/' + savedProject._id + "/kbsettings/" + res.body._id)
127
+ .post('/' + savedProject._id + "/kbsettings/" + settings_id)
126
128
  .auth(email, pwd)
127
129
  .send({ name: "secondurl.com/support/", url: "https://secondurl.com/support/" })
128
130
  .end((err, res) => {
129
131
  if (log) { console.log("add kb to kb settings res.body: ", res.body); }
130
132
  res.should.have.status(200);
131
133
  res.body.should.be.a('object');
132
- expect(res.body.kbs).to.have.length(2)
134
+ //expect(res.body.kbs).to.have.length(2)
133
135
 
134
136
  done();
135
137
  })
@@ -142,7 +144,7 @@ describe('KbSettingsRoute', () => {
142
144
 
143
145
  });
144
146
 
145
- it('update kb settings', (done) => {
147
+ it('updateKbSettings', (done) => {
146
148
 
147
149
  var email = "test-signup-" + Date.now() + "@email.com";
148
150
  var pwd = "pwd";
@@ -178,7 +180,7 @@ describe('KbSettingsRoute', () => {
178
180
 
179
181
  });
180
182
 
181
- it('delete kb from list', (done) => {
183
+ it('deleteKbFromList', (done) => {
182
184
 
183
185
  var email = "test-signup-" + Date.now() + "@email.com";
184
186
  var pwd = "pwd";
@@ -206,9 +208,9 @@ describe('KbSettingsRoute', () => {
206
208
  if (log) { console.log("add kb to kb settings res.body: ", res.body); }
207
209
  res.should.have.status(200);
208
210
  res.body.should.be.a('object');
209
- expect(res.body.kbs).to.have.length(1)
211
+ //expect(res.body.kbs).to.have.length(1)
210
212
 
211
- let kb_to_delete_id = res.body.kbs[0]._id;
213
+ let kb_to_delete_id = res.body._id;
212
214
 
213
215
  chai.request(server)
214
216
  .post('/' + savedProject._id + "/kbsettings/" + settings_id)
@@ -218,7 +220,7 @@ describe('KbSettingsRoute', () => {
218
220
  if (log) { console.log("add kb to kb settings res.body: ", res.body); }
219
221
  res.should.have.status(200);
220
222
  res.body.should.be.a('object');
221
- expect(res.body.kbs).to.have.length(2)
223
+ //expect(res.body.kbs).to.have.length(2)
222
224
 
223
225
  chai.request(server)
224
226
  .delete('/' + savedProject._id + "/kbsettings/" + settings_id + "/" + kb_to_delete_id)
@@ -3,7 +3,12 @@ process.env.NODE_ENV = 'test';
3
3
 
4
4
  var expect = require('chai').expect;
5
5
 
6
- var assert = require('chai').assert;
6
+ var chai = require("chai");
7
+ chai.config.includeStack = true;
8
+
9
+ var expect = chai.expect;
10
+ var assert = chai.assert;
11
+ let should = chai.should();
7
12
  var config = require('../config/database');
8
13
  var mongoose = require('mongoose');
9
14
  var winston = require('../config/winston');
@@ -23,20 +28,77 @@ var projectService = require('../services/projectService');
23
28
 
24
29
  var Request = require("../models/request");
25
30
 
31
+ var { QuoteManager } = require('../services/QuoteManager');
32
+
33
+ // CONNECT REDIS - CHECK IT
34
+ const { TdCache } = require('../utils/TdCache');
35
+ let tdCache = new TdCache({
36
+ host: '127.0.0.1',
37
+ port: '6379'
38
+ });
39
+
40
+ tdCache.connect();
26
41
 
27
42
  describe('messageService', function () {
28
43
 
29
44
  var userid = "5badfe5d553d1844ad654072";
30
45
 
46
+ it('createMessageQuote', function (done) {
47
+ // this.timeout(10000);
48
+ let qm = new QuoteManager({ tdCache: tdCache });
49
+ qm.start();
50
+
51
+ projectService.create("test1", userid).then(function (savedProject) {
52
+ // create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata, language) {
53
+
54
+ messageService.create(userid, "test sender", "testrecipient-createMessage", "hello",
55
+ savedProject._id, userid, undefined, { a1: "a1" }, undefined, undefined, "it").then(function (savedMessage) {
56
+ winston.debug("resolve savedMessage", savedMessage.toObject());
57
+
58
+ expect(savedMessage.text).to.equal("hello");
59
+ expect(savedMessage.sender).to.equal(userid);
60
+ expect(savedMessage.senderFullname).to.equal("test sender");
61
+ expect(savedMessage.recipient).to.equal("testrecipient-createMessage");
62
+ expect(savedMessage.language).to.equal("it");
63
+ expect(savedMessage.attributes.a1).to.equal("a1");
64
+ expect(savedMessage.channel_type).to.equal("group");
65
+ expect(savedMessage.channel.name).to.equal("chat21");
66
+
67
+
68
+ setTimeout(async () => {
69
+ let obj = { createdAt: new Date() }
70
+
71
+ let quotes = await qm.getAllQuotes(savedProject, obj);
72
+ console.log("quotes: ", quotes);
73
+ quotes.messages.quote.should.be.a('string');
74
+ expect(quotes.messages.quote).to.equal('1');
75
+
76
+ done();
77
+
78
+ }, 1000);
79
+
80
+
81
+ }).catch(function (err) {
82
+ assert.isNotOk(err, 'Promise error');
83
+ done();
84
+ });
85
+
86
+ });
87
+ });
88
+
31
89
  it('createMessage', function (done) {
32
90
  // this.timeout(10000);
33
91
 
34
- projectService.create("test1", userid).then(function(savedProject) {
35
- // create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata, language) {
36
- messageService.create(userid, "test sender", "testrecipient-createMessage", "hello",
37
- savedProject._id, userid, undefined, {a1:"a1"}, undefined, undefined, "it" ).then(function(savedMessage){
38
- winston.debug("resolve savedMessage", savedMessage.toObject());
39
-
92
+ projectService.create("test1", userid).then(function (savedProject) {
93
+ // create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata, language) {
94
+
95
+ let quoteManager = new QuoteManager({ project: savedProject, tdCache: tdCache })
96
+ quoteManager.start();
97
+
98
+ messageService.create(userid, "test sender", "testrecipient-createMessage", "hello",
99
+ savedProject._id, userid, undefined, { a1: "a1" }, undefined, undefined, "it").then(function (savedMessage) {
100
+ winston.debug("resolve savedMessage", savedMessage.toObject());
101
+
40
102
  expect(savedMessage.text).to.equal("hello");
41
103
  expect(savedMessage.sender).to.equal(userid);
42
104
  expect(savedMessage.senderFullname).to.equal("test sender");
@@ -47,49 +109,49 @@ describe('messageService', function () {
47
109
  expect(savedMessage.channel.name).to.equal("chat21");
48
110
  done();
49
111
 
50
- }).catch(function(err){
51
- assert.isNotOk(err,'Promise error');
112
+ }).catch(function (err) {
113
+ assert.isNotOk(err, 'Promise error');
52
114
  done();
53
115
  });
54
116
 
55
- });
56
117
  });
57
-
118
+ });
119
+
58
120
 
59
121
 
60
122
 
61
123
  it('createMessageAndUpdateTwoMessagesCount', function (done) {
62
124
  // this.timeout(10000);
63
- // projectService.create("test1", userid).then(function(savedProject) {
64
- projectService.createAndReturnProjectAndProjectUser("test1", userid).then(function(savedProjectAndPU) {
65
- var savedProject = savedProjectAndPU.project;
125
+ // projectService.create("test1", userid).then(function(savedProject) {
126
+ projectService.createAndReturnProjectAndProjectUser("test1", userid).then(function (savedProjectAndPU) {
127
+ var savedProject = savedProjectAndPU.project;
66
128
 
67
- // attento reqid
68
- // requestService.createWithId("request_id-createTwoMessage", "requester_id1", savedProject._id, "first_text").then(function(savedRequest) {
69
- requestService.createWithIdAndRequester("request_id-createTwoMessage", savedProjectAndPU.project_user._id,null, savedProject._id, "first_text").then(function(savedRequest) {
129
+ // attento reqid
130
+ // requestService.createWithId("request_id-createTwoMessage", "requester_id1", savedProject._id, "first_text").then(function(savedRequest) {
131
+ requestService.createWithIdAndRequester("request_id-createTwoMessage", savedProjectAndPU.project_user._id, null, savedProject._id, "first_text").then(function (savedRequest) {
70
132
 
71
- messageService.create(userid, "test sender", savedRequest.request_id, "hello",
72
- savedProject._id, userid).then(function(savedMessage){
133
+ messageService.create(userid, "test sender", savedRequest.request_id, "hello",
134
+ savedProject._id, userid).then(function (savedMessage) {
73
135
 
74
- // Promise.all([requestService.incrementMessagesCountByRequestId(savedRequest.request_id, savedProject._id),
75
- // requestService.incrementMessagesCountByRequestId(savedRequest.request_id, savedProject._id)]).then(function(savedMessage) {
136
+ // Promise.all([requestService.incrementMessagesCountByRequestId(savedRequest.request_id, savedProject._id),
137
+ // requestService.incrementMessagesCountByRequestId(savedRequest.request_id, savedProject._id)]).then(function(savedMessage) {
76
138
 
77
- Request.findOne({"request_id": "request_id-createTwoMessage","id_project": savedProject._id}).exec().then(function(req) {
78
- console.log("test resolve", req);
139
+ Request.findOne({ "request_id": "request_id-createTwoMessage", "id_project": savedProject._id }).exec().then(function (req) {
140
+ console.log("test resolve", req);
79
141
 
80
- // expect(req.messages_count).to.equal(2);
142
+ // expect(req.messages_count).to.equal(2);
81
143
 
82
- done();
83
- }).catch(function(err){
84
- winston.error("test reject", err);
85
- assert.isNotOk(err,'Promise error');
86
- done();
87
- });
88
- // });
144
+ done();
145
+ }).catch(function (err) {
146
+ winston.error("test reject", err);
147
+ assert.isNotOk(err, 'Promise error');
148
+ done();
149
+ });
150
+ // });
89
151
  });
90
- });
152
+ });
91
153
  });
92
-
154
+
93
155
 
94
156
  });
95
157
 
@@ -106,30 +168,30 @@ describe('messageService', function () {
106
168
 
107
169
 
108
170
  var messageTransformerInterceptor = require('../pubmodules/messageTransformer/messageTransformerInterceptor');
109
- console.log("messageTransformerInterceptor",messageTransformerInterceptor);
171
+ console.log("messageTransformerInterceptor", messageTransformerInterceptor);
110
172
  messageTransformerInterceptor.listen();
111
173
 
112
174
 
113
175
 
114
- projectService.create("test1", userid).then(function(savedProject) {
115
- // create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata) {
176
+ projectService.create("test1", userid).then(function (savedProject) {
177
+ // create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata) {
116
178
  messageService.create(userid, "test sender", "testrecipient-createMessage", "${LABEL_PLACEHOLDER}",
117
- savedProject._id, userid).then(function(savedMessage){
118
- winston.debug("resolve savedMessage", savedMessage.toObject());
119
-
179
+ savedProject._id, userid).then(function (savedMessage) {
180
+ winston.debug("resolve savedMessage", savedMessage.toObject());
181
+
120
182
  expect(savedMessage.text).to.equal("type your message..");
121
183
  expect(savedMessage.sender).to.equal(userid);
122
184
  expect(savedMessage.senderFullname).to.equal("test sender");
123
185
  expect(savedMessage.recipient).to.equal("testrecipient-createMessage");
124
186
  done();
125
187
 
126
- }).catch(function(err){
127
- assert.isNotOk(err,'Promise error');
188
+ }).catch(function (err) {
189
+ assert.isNotOk(err, 'Promise error');
128
190
  done();
129
191
  });
130
192
 
131
- });
132
193
  });
194
+ });
133
195
 
134
196
 
135
197
 
@@ -138,103 +200,103 @@ describe('messageService', function () {
138
200
 
139
201
 
140
202
  var messageTransformerInterceptor = require('../pubmodules/messageTransformer/messageTransformerInterceptor');
141
- console.log("messageTransformerInterceptor",messageTransformerInterceptor);
203
+ console.log("messageTransformerInterceptor", messageTransformerInterceptor);
142
204
  messageTransformerInterceptor.listen();
143
205
 
144
206
 
145
207
 
146
- projectService.create("test1", userid).then(function(savedProject) {
147
- // create(sender, senderFullname, recipient, text, id_project, createdBy) {
208
+ projectService.create("test1", userid).then(function (savedProject) {
209
+ // create(sender, senderFullname, recipient, text, id_project, createdBy) {
148
210
  messageService.create(userid, "test sender", "testrecipient-createMessage", "${NOTFOUND_LABEL}",
149
- savedProject._id, userid).then(function(savedMessage){
150
- winston.debug("resolve savedMessage", savedMessage.toObject());
151
-
211
+ savedProject._id, userid).then(function (savedMessage) {
212
+ winston.debug("resolve savedMessage", savedMessage.toObject());
213
+
152
214
  expect(savedMessage.text).to.equal("${NOTFOUND_LABEL}");
153
215
  expect(savedMessage.sender).to.equal(userid);
154
216
  expect(savedMessage.senderFullname).to.equal("test sender");
155
217
  expect(savedMessage.recipient).to.equal("testrecipient-createMessage");
156
218
  done();
157
219
 
158
- }).catch(function(err){
159
- assert.isNotOk(err,'Promise error');
220
+ }).catch(function (err) {
221
+ assert.isNotOk(err, 'Promise error');
160
222
  done();
161
223
  });
162
224
 
163
- });
164
225
  });
226
+ });
165
227
 
166
228
 
167
229
 
168
230
 
169
231
 
170
- it('createMessageMultiLanguageNOLanguage', function (done) {
171
- // this.timeout(10000);
172
-
173
-
174
- var messageTransformerInterceptor = require('../pubmodules/messageTransformer/messageTransformerInterceptor');
175
- console.log("messageTransformerInterceptor",messageTransformerInterceptor);
176
- messageTransformerInterceptor.listen();
177
-
178
-
179
-
180
- projectService.create("test1", userid).then(function(savedProject) {
181
- // create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata, language) {
182
- messageService.create(userid, "test sender", "testrecipient-createMessage", "${LABEL_PLACEHOLDER}",
183
- savedProject._id, userid, undefined, undefined, undefined, undefined, "XXXX").then(function(savedMessage){
232
+ it('createMessageMultiLanguageNOLanguage', function (done) {
233
+ // this.timeout(10000);
234
+
235
+
236
+ var messageTransformerInterceptor = require('../pubmodules/messageTransformer/messageTransformerInterceptor');
237
+ console.log("messageTransformerInterceptor", messageTransformerInterceptor);
238
+ messageTransformerInterceptor.listen();
239
+
240
+
241
+
242
+ projectService.create("test1", userid).then(function (savedProject) {
243
+ // create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata, language) {
244
+ messageService.create(userid, "test sender", "testrecipient-createMessage", "${LABEL_PLACEHOLDER}",
245
+ savedProject._id, userid, undefined, undefined, undefined, undefined, "XXXX").then(function (savedMessage) {
184
246
  winston.debug("resolve savedMessage", savedMessage.toObject());
185
-
186
- expect(savedMessage.text).to.equal("type your message.."); //EN default
187
- expect(savedMessage.sender).to.equal(userid);
188
- expect(savedMessage.senderFullname).to.equal("test sender");
189
- expect(savedMessage.recipient).to.equal("testrecipient-createMessage");
190
- done();
191
-
192
- }).catch(function(err){
193
- assert.isNotOk(err,'Promise error');
194
- done();
195
- });
196
-
247
+
248
+ expect(savedMessage.text).to.equal("type your message.."); //EN default
249
+ expect(savedMessage.sender).to.equal(userid);
250
+ expect(savedMessage.senderFullname).to.equal("test sender");
251
+ expect(savedMessage.recipient).to.equal("testrecipient-createMessage");
252
+ done();
253
+
254
+ }).catch(function (err) {
255
+ assert.isNotOk(err, 'Promise error');
256
+ done();
197
257
  });
198
- });
199
-
258
+
259
+ });
260
+ });
200
261
 
201
262
 
202
263
 
203
264
 
204
265
 
205
266
 
206
- // mocha test/messageService.js --grep 'createMessageMicroLanguageWithAttribute'
267
+
268
+ // mocha test/messageService.js --grep 'createMessageMicroLanguageWithAttribute'
207
269
 
208
270
  it('createMessageMicroLanguageWithAttribute', function (done) {
209
271
  // this.timeout(10000);
210
272
 
211
273
 
212
274
  var microLanguageTransformerInterceptor = require('../pubmodules/messageTransformer/microLanguageTransformerInterceptor');
213
- console.log("microLanguageTransformerInterceptor",microLanguageTransformerInterceptor);
275
+ console.log("microLanguageTransformerInterceptor", microLanguageTransformerInterceptor);
214
276
  microLanguageTransformerInterceptor.listen();
215
277
 
216
278
 
217
279
 
218
- projectService.create("test1", userid).then(function(savedProject) {
219
- // create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata) {
220
- messageService.create("bot_"+userid, "test sender", "testrecipient-createMessageMicroLanguageWithAttribute", "ciao\n* Button1",
221
- savedProject._id, userid, undefined, {microlanguage:true}).then(function(savedMessage){
222
- winston.debug("resolve savedMessage", savedMessage.toObject());
223
-
280
+ projectService.create("test1", userid).then(function (savedProject) {
281
+ // create(sender, senderFullname, recipient, text, id_project, createdBy, status, attributes, type, metadata) {
282
+ messageService.create("bot_" + userid, "test sender", "testrecipient-createMessageMicroLanguageWithAttribute", "ciao\n* Button1",
283
+ savedProject._id, userid, undefined, { microlanguage: true }).then(function (savedMessage) {
284
+ winston.debug("resolve savedMessage", savedMessage.toObject());
285
+
224
286
  expect(savedMessage.text).to.equal("ciao");
225
287
  expect(savedMessage.type).to.equal("text");
226
- expect(savedMessage.attributes._raw_message).to.equal("ciao\n* Button1","attachment");
227
- expect(savedMessage.attributes.attachment.type).to.equal("template");
288
+ expect(savedMessage.attributes._raw_message).to.equal("ciao\n* Button1", "attachment");
289
+ expect(savedMessage.attributes.attachment.type).to.equal("template");
228
290
  expect(savedMessage.attributes.attachment.buttons[0].value).to.equal("Button1");
229
- expect(savedMessage.sender).to.equal("bot_"+userid);
291
+ expect(savedMessage.sender).to.equal("bot_" + userid);
230
292
  expect(savedMessage.senderFullname).to.equal("test sender");
231
293
  expect(savedMessage.recipient).to.equal("testrecipient-createMessageMicroLanguageWithAttribute");
232
294
  done();
233
295
 
234
296
  })
235
- });
236
297
  });
298
+ });
299
+
237
300
 
238
-
239
301
 
240
302
  });
@@ -0,0 +1,46 @@
1
+
2
+ class MockTdCache {
3
+
4
+ constructor() {
5
+ this.db = new Map();
6
+ }
7
+
8
+ async set(k, v) {
9
+ return new Promise((resolve, reject) => {
10
+ this.db.set(k, "" + v);
11
+ resolve();
12
+ })
13
+ }
14
+
15
+ async incr(k) {
16
+ let value = await this.get(k);
17
+ if (value == undefined || value == null) {
18
+ value = 0;
19
+ }
20
+
21
+ try {
22
+ value = Number(value);
23
+ } catch(error) {
24
+ value = 0;
25
+ }
26
+
27
+ let v_incr = Number(value) + 1;
28
+ this.db.set(k, "" + v_incr);
29
+ }
30
+
31
+ async get(k) {
32
+ return new Promise((resolve, reject) => {
33
+ const v = this.db.get(k);
34
+ resolve(v);
35
+ })
36
+ }
37
+
38
+ async del(k) {
39
+ return new Promise((resolve, reject) => {
40
+ const v = this.db.delete(k);
41
+ resolve();
42
+ })
43
+ }
44
+ }
45
+
46
+ module.exports = { MockTdCache };