@tiledesk/tiledesk-server 2.9.26 → 2.9.27

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,7 +25,7 @@ const emailMock = require('./mock/emailMock');
25
25
  const { MockTdCache } = require('./mock/MockTdCache');
26
26
  const mockTdCache = new MockTdCache();
27
27
 
28
- let log = true;
28
+ let log = false;
29
29
 
30
30
  // CONNECT REDIS - CHECK IT
31
31
  const { TdCache } = require('../utils/TdCache');
@@ -60,6 +60,41 @@ const dateList = [
60
60
  "2023-10-29T08:45:54.058Z"
61
61
  ]
62
62
 
63
+ const dateListStress = [
64
+ "2024-02-05T10:30:00.058Z",
65
+ "2024-03-05T10:30:00.058Z",
66
+ "2024-04-05T10:30:00.058Z",
67
+ "2024-05-05T10:30:00.058Z",
68
+ "2024-06-05T10:30:00.058Z",
69
+ "2024-07-05T10:30:00.058Z",
70
+ "2024-08-05T10:30:00.058Z",
71
+ "2024-09-05T10:30:00.058Z",
72
+ "2024-10-05T10:30:00.058Z",
73
+ "2024-11-05T10:30:00.058Z",
74
+ "2024-12-05T10:30:00.058Z",
75
+ "2025-01-05T10:30:00.058Z",
76
+ "2025-02-05T10:30:00.058Z",
77
+ "2025-03-05T10:30:00.058Z"
78
+ ]
79
+
80
+ const expectedSlotStarts = [
81
+ "31/01/2024",
82
+ "29/02/2024",
83
+ "31/03/2024",
84
+ "30/04/2024",
85
+ "31/05/2024",
86
+ "30/06/2024",
87
+ "31/07/2024",
88
+ "31/08/2024",
89
+ "30/09/2024",
90
+ "31/10/2024",
91
+ "30/11/2024",
92
+ "31/12/2024",
93
+ "31/01/2025",
94
+ "28/02/2025",
95
+ "31/03/2025",
96
+
97
+ ]
63
98
  // connectRedis();
64
99
 
65
100
  // function connectRedis() {
@@ -104,12 +139,44 @@ quoteManager.start();
104
139
  describe('QuoteManager', function () {
105
140
 
106
141
 
142
+ it('incrementRequestsCountStress', (done) => {
143
+ /**
144
+ * For this test the subscription starts on 31 Genuary.
145
+ * Slots must start on 31 Gen, 28/29 Feb, 31 Mar, 30 Apr, ...
146
+ */
147
+ let mockProject = projectMock.mockProjectPremiumPlan2;
148
+ let mockRequest = requestMock.requestMock;
149
+
150
+ console.log("Starting stress test with one year long cycle of renewals")
151
+
152
+ let i = 0;
153
+ async function test(date) {
154
+
155
+ mockRequest.createdAt = new Date(date);
156
+ let key_incremented = await quoteManager.incrementRequestsCount(mockProject, mockRequest);
157
+ if (log) { console.log("request_date: ", mockRequest.createdAt, "key_incremented: ", key_incremented); }
158
+
159
+ let slot_start = key_incremented.substring(key_incremented.lastIndexOf(':') + 1)
160
+ expect(slot_start).to.equal(expectedSlotStarts[i]);
161
+
162
+ i += 1;
163
+ if (i < dateListStress.length) {
164
+ setTimeout(() => {
165
+ test(dateListStress[i])
166
+ }, 250);
167
+ } else {
168
+ console.log("All dates tested successfully.")
169
+ done();
170
+ }
171
+ }
172
+ test(dateListStress[0]);
173
+
174
+ }).timeout(5000)
107
175
 
108
176
  it('incrementRequestsCount', async function () {
109
- let mockProject = projectMock.mockProjectSandboxPlan;
177
+ let mockProject = projectMock.mockProjectBasicPlan;
110
178
  let mockRequest = requestMock.requestMock;
111
179
 
112
-
113
180
  mockRequest.createdAt = new Date(dateList[0]);
114
181
 
115
182
  let initial_quote = await quoteManager.getCurrentQuote(mockProject, mockRequest, 'requests');
@@ -207,8 +274,13 @@ describe('QuoteManager', function () {
207
274
  res.should.have.status(200);
208
275
  res.body.should.be.a('object');
209
276
 
210
- let date = new Date().toLocaleDateString();
211
-
277
+ const options = {
278
+ day: '2-digit',
279
+ month: '2-digit',
280
+ year: 'numeric',
281
+ };
282
+ let date = new Date().toLocaleDateString(undefined, options);
283
+
212
284
  let key = "quotes:tokens:" + savedProject._id + ":" + date;
213
285
  let message_resp = "value incremented for key " + key;
214
286
  expect(res.body.message).to.equal(message_resp);
@@ -1226,6 +1226,48 @@ describe('RequestRoute', () => {
1226
1226
 
1227
1227
  })
1228
1228
 
1229
+ it('countConversations', function (done) {
1230
+ // this.timeout(10000);
1231
+
1232
+ var email = "test-request-create-" + Date.now() + "@email.com";
1233
+ var pwd = "pwd";
1234
+
1235
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
1236
+ projectService.create("request-create", savedUser._id, { email: { template: { assignedRequest: "123" } } }).then(function (savedProject) {
1237
+
1238
+ chai.request(server)
1239
+ .post('/' + savedProject._id + '/requests/')
1240
+ .auth(email, pwd)
1241
+ .set('content-type', 'application/json')
1242
+ .send({ "first_text": "first_text" })
1243
+ .end(function (err, res) {
1244
+
1245
+ if (err) { console.log("err: ", err) };
1246
+ if (log) { console.log("res.body: ", res.body) };
1247
+
1248
+ res.should.have.status(200);
1249
+ res.body.should.be.a('object');
1250
+
1251
+ console.log("request created")
1252
+ chai.request(server)
1253
+ .get('/' + savedProject._id + '/requests/count?conversation_quota=true')
1254
+ .auth(email, pwd)
1255
+ .end((err, res) => {
1256
+
1257
+ if (err) { console.log("err: ", err) };
1258
+ if (log) { console.log("res.body: ", res.body) };
1259
+ console.log("res.body: ", res.body)
1260
+
1261
+ res.should.have.status(200);
1262
+
1263
+ done();
1264
+ })
1265
+
1266
+ });
1267
+ });
1268
+ });
1269
+ });
1270
+
1229
1271
  // it('assign', (done) => {
1230
1272
 
1231
1273
 
@@ -197,6 +197,27 @@ class WebSocketServer {
197
197
 
198
198
  var projectId = urlSub[1];
199
199
  winston.debug('projectId: ' + projectId);
200
+
201
+ // sponz support 65203e12f8c0cf002cf4110b
202
+ // johnny support 62c3f10152dc7400352bab0d
203
+ // sponz collaudo 66acec0cf7ebf80013d67974
204
+ // johnny collaudo 6613ff078890fc0013ad3c3a
205
+ // sponz prod 6565047fdd64fd001323f37c
206
+ // mweb prod 656054000410fa00132e5dcc
207
+
208
+ if (projectId === "65203e12f8c0cf002cf4110b"
209
+ || projectId === "62c3f10152dc7400352bab0d"
210
+ || projectId === "66acec0cf7ebf80013d67974"
211
+ || projectId === "6613ff078890fc0013ad3c3a"
212
+ || projectId === "6565047fdd64fd001323f37c"
213
+ || projectId === "656054000410fa00132e5dcc") {
214
+
215
+ console.log('WSS onSubscribeCallback - ProjectID ' + projectId);
216
+ console.log("x-forwarded-for: ", req.headers['x-forwarded-for'], "remote port: ", req.socket.remotePort);
217
+ console.log("remoteAddress: ", req.socket.remoteAddress)
218
+ }
219
+
220
+
200
221
 
201
222
  let q = Project.findOne({ _id: projectId, status: 100 })
202
223