@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.
@@ -0,0 +1,9 @@
1
+ const emailMock = {
2
+ from: 'email@from.com',
3
+ to: 'to@from.com',
4
+ subject: 'Email Subject',
5
+ body: 'Email Body',
6
+ createdAt: new Date('2023-10-25T08:45:54.058Z')
7
+ }
8
+
9
+ module.exports = { emailMock }
@@ -0,0 +1,46 @@
1
+ const messageMock = {
2
+ senderFullname: 'Test Sender',
3
+ type: 'text',
4
+ text: 'Hello!',
5
+ conversationWith: "support-group-63d540d370133e00128d6e59-f384a142258c4f2da2341770213cb5e7",
6
+ recipientFullname: "Test Sender ",
7
+ projectid: "63d540d370133e00128d6e59",
8
+ channelType: "group",
9
+ createdBy: '5badfe5d553d1844ad654072',
10
+ attributes: {}
11
+ }
12
+
13
+ // const messageMock = {
14
+ // "senderFullname": "guest#32d1 ",
15
+ // "text": "test 1",
16
+ // "type": "text",
17
+ // "metadata": "",
18
+ // "conversationWith": "support-group-63d540d370133e00128d6e59-f384a142258c4f2da2341770213cb5e7",
19
+ // "recipientFullname": "guest#32d1 ",
20
+ // "attributes": {
21
+ // "departmentId": "649c4644d71dcc0013909e6c",
22
+ // "departmentName": "NEW MESSAGE TEST",
23
+ // "ipAddress": "5.91.158.145",
24
+ // "client": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
25
+ // "sourcePage": "http://localhost:4203/assets/twp/index-dev.html?tiledesk_projectid=63d540d370133e00128d6e59&tiledesk_align=right&project_name=Demo%20email&tiledesk_singleConversation=false&tiledeks_nativeRating=true&tiledesk_mobileMarginY=35px&tiledesk_showLogoutOption=true&tiledesk_isLogEnabled=true&quiz",
26
+ // "sourceTitle": "Widget test page",
27
+ // "projectId": "63d540d370133e00128d6e59",
28
+ // "widgetVer": "v.5.0.71-rc.4",
29
+ // "payload": [],
30
+ // "userFullname": "guest#32d1 ",
31
+ // "requester_id": "32d1a53f-ec47-459a-9956-b52392e99079",
32
+ // "userEmail": "ddd@dd.it",
33
+ // "preChatForm": null,
34
+ // "cookie": "_ga=GA1.1.1543507943.1667828274; _cioid=5fd34e4249610e0034985078; hubspotutk=2edc9ab132fa5d509da1f3b63bbd4363; __stripe_mid=83a31c6b-0f17-4db4-8141-db2b31aa8e00e3feb8; ajs_user_id=638a2d68903f950014304c2a; ajs_anonymous_id=62a9e436-bd3f-4ac3-a1e7-78aad9d3e428; __hssrc=1; _clck=1xdqm39|2|fdt|0|1253; __hstc=181257784.2edc9ab132fa5d509da1f3b63bbd4363.1679477625553.1690960089317.1690977927174.140; _ga_BKHKLWGG6F=GS1.1.1690977924.245.1.1690984596.0.0.0; _clsk=1qgjsgo|1690984597675|2|1|y.clarity.ms/collect",
35
+ // "action": "#d8f15799-4209-46b9-874d-ca5818873146",
36
+ // "subtype": "",
37
+ // "lang": "en",
38
+ // "tempUID": "385c56fa-471a-4ce9-a7d8-7b9d179a85b0"
39
+ // },
40
+ // "projectid": "63d540d370133e00128d6e59",
41
+ // "channelType": "group"
42
+ // }
43
+
44
+
45
+
46
+ module.exports = { messageMock }
@@ -0,0 +1,171 @@
1
+ const mockProjectUser = {
2
+ "_id": "64e36f5dbf72263f7c056666",
3
+ "id_project": "64e36f5dbf72263f7c059999",
4
+ "id_user": "64e36f5dbf72263f7c057777",
5
+ "role": 'owner',
6
+ "user_available": true,
7
+ "createdBy": "64e36f5dbf72263f7c057777",
8
+ "updatedBy": "64e36f5dbf72263f7c057777"
9
+ }
10
+
11
+ const mockProjectFreeTrialPlan = {
12
+ "_id": "64e36f5dbf72263f7c059999",
13
+ "status": 100,
14
+ "ipFilterEnabled": false,
15
+ "ipFilter": [],
16
+ "ipFilterDenyEnabled": false,
17
+ "ipFilterDeny": [],
18
+ "name": "mock-project",
19
+ "activeOperatingHours": false,
20
+ "createdBy": "64e36f5cbf72263f7c05ba36",
21
+ "profile": {
22
+ "name": "free",
23
+ "trialDays": 14,
24
+ "agents": 0,
25
+ "type": "free"
26
+ },
27
+ "versions": 20115,
28
+ "channels": [
29
+ {
30
+ "name": "chat21"
31
+ }
32
+ ],
33
+ "createdAt": new Date('2023-10-16T08:45:54.058Z')
34
+ }
35
+
36
+ const mockProjectSandboxPlan = {
37
+ "_id": "64e36f5dbf72263f7c059999",
38
+ "status": 100,
39
+ "ipFilterEnabled": false,
40
+ "ipFilter": [],
41
+ "ipFilterDenyEnabled": false,
42
+ "ipFilterDeny": [],
43
+ "name": "mock-project",
44
+ "activeOperatingHours": false,
45
+ "createdBy": "64e36f5cbf72263f7c05ba36",
46
+ "profile": {
47
+ "name": "Sandbox",
48
+ "trialDays": 14,
49
+ "agents": 0,
50
+ "type": "payment",
51
+ "subStart": new Date('2023-10-20T08:45:54.058Z')
52
+ },
53
+ "versions": 20115,
54
+ "channels": [
55
+ {
56
+ "name": "chat21"
57
+ }
58
+ ],
59
+ "createdAt": new Date('2023-10-16T08:45:54.058Z')
60
+ }
61
+
62
+ const mockProjectBasicPlan = {
63
+ "_id": "64e36f5dbf72263f7c059999",
64
+ "status": 100,
65
+ "ipFilterEnabled": false,
66
+ "ipFilter": [],
67
+ "ipFilterDenyEnabled": false,
68
+ "ipFilterDeny": [],
69
+ "name": "mock-project",
70
+ "activeOperatingHours": false,
71
+ "createdBy": "64e36f5cbf72263f7c05ba36",
72
+ "profile": {
73
+ "name": "Basic",
74
+ "trialDays": 14,
75
+ "agents": 0,
76
+ "type": "payment",
77
+ "subStart": new Date('2023-10-20T08:45:54.058Z')
78
+ },
79
+ "versions": 20115,
80
+ "channels": [
81
+ {
82
+ "name": "chat21"
83
+ }
84
+ ],
85
+ "createdAt": new Date('2023-10-16T08:45:54.058Z')
86
+ }
87
+
88
+ const mockProjectPremiumPlan = {
89
+ "_id": "64e36f5dbf72263f7c059999",
90
+ "status": 100,
91
+ "ipFilterEnabled": false,
92
+ "ipFilter": [],
93
+ "ipFilterDenyEnabled": false,
94
+ "ipFilterDeny": [],
95
+ "name": "mock-project",
96
+ "activeOperatingHours": false,
97
+ "createdBy": "64e36f5cbf72263f7c05ba36",
98
+ "profile": {
99
+ "name": "Premium",
100
+ "trialDays": 14,
101
+ "agents": 0,
102
+ "type": "payment",
103
+ "subStart": new Date('2023-10-20T08:45:54.058Z')
104
+ },
105
+ "versions": 20115,
106
+ "channels": [
107
+ {
108
+ "name": "chat21"
109
+ }
110
+ ],
111
+ "createdAt": new Date('2023-10-16T08:45:54.058Z')
112
+ }
113
+
114
+ const mockProjectCustomPlan = {
115
+ "_id": "64e36f5dbf72263f7c059999",
116
+ "status": 100,
117
+ "ipFilterEnabled": false,
118
+ "ipFilter": [],
119
+ "ipFilterDenyEnabled": false,
120
+ "ipFilterDeny": [],
121
+ "name": "mock-project",
122
+ "activeOperatingHours": false,
123
+ "createdBy": "64e36f5cbf72263f7c05ba36",
124
+ "profile": {
125
+ "name": "Custom",
126
+ "trialDays": 14,
127
+ "agents": 0,
128
+ "type": "payment",
129
+ "subStart": new Date('2023-10-20T08:45:54.058Z')
130
+ },
131
+ "versions": 20115,
132
+ "channels": [
133
+ {
134
+ "name": "chat21"
135
+ }
136
+ ],
137
+ "createdAt": new Date('2023-10-16T08:45:54.058Z')
138
+ }
139
+
140
+ const mockOldProjecPlusPlan = {
141
+ "_id": "64e36f5dbf72263f7c059999",
142
+ "status": 100,
143
+ "ipFilterEnabled": false,
144
+ "ipFilter": [],
145
+ "name": "mock-project",
146
+ "activeOperatingHours": false,
147
+ "createdBy": "64e36f5cbf72263f7c05ba36",
148
+ "profile": {
149
+ "name": "Plus",
150
+ "trialDays": 30,
151
+ "agents": 40,
152
+ "type": "payment",
153
+ "subStart": new Date('2023-10-20T08:45:54.058Z'),
154
+ "subEnd": new Date('2024-3-29T08:45:54.058Z'),
155
+ "subscriptionId": "sub_1MjKLHG7zhjGozkvDsXITiDf",
156
+ "last_stripe_event": "invoice.payment_succeeded"
157
+ },
158
+ "versions": 20115,
159
+ "channels": [
160
+ {
161
+ "name": "chat21"
162
+ }
163
+ ],
164
+ "createdAt": new Date('2023-10-18T08:45:54.058Z'),
165
+ "updatedAt": new Date('2023-10-20T08:45:54.058Z'),
166
+ "bannedUsers": [],
167
+ "ipFilterDeny": [],
168
+ "ipFilterDenyEnabled": false
169
+ }
170
+
171
+ module.exports = { mockProjectUser, mockProjectFreeTrialPlan, mockProjectSandboxPlan, mockProjectBasicPlan, mockProjectPremiumPlan, mockProjectCustomPlan, mockOldProjecPlusPlan };
@@ -0,0 +1,127 @@
1
+ const requestMock = {
2
+ "_id": "652e46f283a36264e8e8b331",
3
+ "status": 200,
4
+ "preflight": false,
5
+ "hasBot": false,
6
+ "participants": [
7
+ "652e46f183a36264e8e8b256"
8
+ ],
9
+ "priority": "medium",
10
+ "followers": [],
11
+ "participantsAgents": [
12
+ "652e46f183a36264e8e8b256"
13
+ ],
14
+ "participantsBots": [],
15
+ "request_id": "support-group-652e46f183a36264e8e8b27b-16c334bd0d214579a4c98f2f0e7794ad",
16
+ "requester": "652e46f183a36264e8e8b299",
17
+ "lead": "652e46f283a36264e8e8b323",
18
+ "first_text": "first_text",
19
+ "department": "652e46f183a36264e8e8b2a7",
20
+ "assigned_at": new Date('2023-10-17T08:45:54.058Z'),
21
+ "id_project": "652e46f183a36264e8e8b27b",
22
+ "createdBy": "652e46f183a36264e8e8b256",
23
+ "channel": {
24
+ "name": "chat21"
25
+ },
26
+ "createdAt": new Date('2023-10-19T08:45:54.058Z')
27
+ }
28
+
29
+ // const requestMock = {
30
+ // "_id": "652e46f283a36264e8e8b331",
31
+ // "status": 200,
32
+ // "preflight": false,
33
+ // "hasBot": false,
34
+ // "participants": [
35
+ // "652e46f183a36264e8e8b256"
36
+ // ],
37
+ // "priority": "medium",
38
+ // "followers": [],
39
+ // "participantsAgents": [
40
+ // "652e46f183a36264e8e8b256"
41
+ // ],
42
+ // "participantsBots": [],
43
+ // "request_id": "support-group-652e46f183a36264e8e8b27b-16c334bd0d214579a4c98f2f0e7794ad",
44
+ // "requester": "652e46f183a36264e8e8b299",
45
+ // "lead": "652e46f283a36264e8e8b323",
46
+ // "first_text": "first_text",
47
+ // "department": "652e46f183a36264e8e8b2a7",
48
+ // "assigned_at": new Date('2023-10-17T08:45:54.058Z'),
49
+ // "id_project": "652e46f183a36264e8e8b27b",
50
+ // "createdBy": "652e46f183a36264e8e8b256",
51
+ // "channel": {
52
+ // "name": "chat21"
53
+ // },
54
+ // "snapshot": {
55
+ // "department": {
56
+ // "routing": "assigned",
57
+ // "default": true,
58
+ // "status": 1,
59
+ // "_id": "652e46f183a36264e8e8b2a7",
60
+ // "name": "Default Department",
61
+ // "id_project": "652e46f183a36264e8e8b27b",
62
+ // "createdBy": "652e46f183a36264e8e8b256",
63
+ // "tags": [],
64
+ // "createdAt": new Date('2023-10-17T08:41:48.140Z'),
65
+ // "updatedAt": new Date('2023-10-17T08:41:48.140Z'),
66
+ // "__v": 0
67
+ // },
68
+ // "agents": [
69
+ // {
70
+ // "user_available": true,
71
+ // "number_assigned_requests": 0,
72
+ // "last_login_at": new Date('2023-10-17T08:33:51.266Z'),
73
+ // "status": "active",
74
+ // "_id": "652e46f183a36264e8e8b299",
75
+ // "id_project": "652e46f183a36264e8e8b27b",
76
+ // "id_user": "652e46f183a36264e8e8b256",
77
+ // "role": "owner",
78
+ // "createdBy": "652e46f183a36264e8e8b256",
79
+ // "tags": [],
80
+ // "createdAt": new Date('2023-10-17T08:33:53.484Z'),
81
+ // "updatedAt": new Date('2023-10-17T08:33:53.484Z'),
82
+ // "__v": 0
83
+ // }
84
+ // ],
85
+ // "availableAgentsCount": 1,
86
+ // "requester": {
87
+ // "user_available": true,
88
+ // "number_assigned_requests": 0,
89
+ // "last_login_at": new Date('2023-10-17T08:33:51.266Z'),
90
+ // "status": "active",
91
+ // "_id": "652e46f183a36264e8e8b299",
92
+ // "id_project": "652e46f183a36264e8e8b27b",
93
+ // "id_user": "652e46f183a36264e8e8b256",
94
+ // "role": "owner",
95
+ // "createdBy": "652e46f183a36264e8e8b256",
96
+ // "tags": [],
97
+ // "createdAt": new Date('2023-10-17T08:33:53.484Z'),
98
+ // "updatedAt": new Date('2023-10-17T08:33:53.484Z'),
99
+ // "__v": 0
100
+ // },
101
+ // "lead": {
102
+ // "tags": [],
103
+ // "status": 100,
104
+ // "_id": "652e46f283a36264e8e8b323",
105
+ // "lead_id": "652e46f183a36264e8e8b256",
106
+ // "fullname": "Test Firstname Test lastname",
107
+ // "email": "test-request-create-1697531633210@email.com",
108
+ // "id_project": "652e46f183a36264e8e8b27b",
109
+ // "createdBy": "system",
110
+ // "createdAt": new Date('2023-10-17T08:33:54.035Z'),
111
+ // "updatedAt": new Date('2023-10-17T08:33:54.035Z'),
112
+ // "__v": 0
113
+ // }
114
+ // },
115
+ // "tags": [],
116
+ // "notes": [],
117
+ // "channelOutbound": {
118
+ // "name": "chat21"
119
+ // },
120
+ // "smartAssignment": true,
121
+ // "createdAt": new Date('2023-10-19T08:45:54.058Z'),
122
+ // "updatedAt": new Date('2023-10-19T08:45:54.058Z'),
123
+ // "ticket_id": 1,
124
+ // "__v": 0
125
+ // }
126
+
127
+ module.exports = { requestMock }
@@ -0,0 +1,282 @@
1
+ const { QuoteManager } = require('../services/QuoteManager');
2
+ const pubModulesManager = require('../pubmodules/pubModulesManager'); // on constructor init is undefined beacusae pub module is loaded after
3
+ var projectService = require('../services/projectService');
4
+ var userService = require('../services/userService');
5
+
6
+
7
+ let chai = require('chai');
8
+ let chaiHttp = require('chai-http');
9
+ let server = require('../app');
10
+ let should = chai.should();
11
+
12
+ let expect = require('chai').expect;
13
+ let assert = require('chai').assert;
14
+
15
+ chai.use(chaiHttp);
16
+
17
+ // MOCK
18
+ const projectMock = require('./mock/projectMock');
19
+ const requestMock = require('./mock/requestMock');
20
+ const messageMock = require('./mock/messageMock');
21
+ const emailMock = require('./mock/emailMock');
22
+ const { MockTdCache } = require('./mock/MockTdCache');
23
+ const mockTdCache = new MockTdCache();
24
+
25
+ let log = true;
26
+
27
+ // CONNECT REDIS - CHECK IT
28
+ const { TdCache } = require('../utils/TdCache');
29
+ tdCache = new TdCache({
30
+ host: '127.0.0.1',
31
+ port: '6379'
32
+ });
33
+
34
+ tdCache.connect();
35
+ // var redis = require('redis')
36
+ // var redis_client;
37
+
38
+ // const dateList = [
39
+ // "2023-10-17T08:45:54.058Z",
40
+ // "2023-10-20T08:45:54.058Z",
41
+ // "2023-10-28T08:45:54.058Z",
42
+ // "2023-10-31T08:45:54.058Z",
43
+ // "2023-11-19T08:45:54.058Z",
44
+ // "2023-11-22T08:45:54.058Z",
45
+ // "2023-11-27T08:45:54.058Z",
46
+ // "2023-12-01T08:45:54.058Z",
47
+ // "2023-12-20T08:45:54.058Z",
48
+ // "2023-12-21T08:45:54.058Z"
49
+ // ]
50
+
51
+ const dateList = [
52
+ "2023-10-24T08:45:54.058Z",
53
+ "2023-10-25T08:45:54.058Z",
54
+ "2023-10-26T08:45:54.058Z",
55
+ "2023-10-27T08:45:54.058Z",
56
+ "2023-10-28T08:45:54.058Z",
57
+ "2023-10-29T08:45:54.058Z"
58
+ ]
59
+
60
+ // connectRedis();
61
+
62
+ // function connectRedis() {
63
+ // console.log(">>> connectRedis")
64
+ // redis_client = redis.createClient({
65
+ // host: "127.0.0.1",
66
+ // port: 6379,
67
+ // });
68
+
69
+ // redis_client.on('error', err => {
70
+ // console.log('(quoteManager TEST) Connect Redis Error ' + err);
71
+ // })
72
+
73
+ // redis_client.on('ready', () => {
74
+ // console.log("(quoteManager TEST) Redis ready!")
75
+ // })
76
+ // }
77
+
78
+
79
+
80
+ // let cacheClient = undefined;
81
+ // if (pubModulesManager.cache) {
82
+ // cacheClient = pubModulesManager.cache._cache._cache; //_cache._cache to jump directly to redis modules without cacheoose wrapper (don't support await)
83
+ // }
84
+
85
+ // let tdCache = undefined;
86
+ // if (cacheClient) {
87
+ // tdCache = cacheClient;
88
+ // console.log("using 'cacheClient' for the test")
89
+ // } else if (redis_client) {
90
+ // tdCache = redis_client
91
+ // console.log("using 'redis_client' for the test")
92
+ // } else {
93
+ // tdCache = mockTdCache;
94
+ // console.log("using 'mockTdCache' for the test")
95
+ // }
96
+
97
+ let quoteManager = new QuoteManager({ tdCache: tdCache });
98
+ quoteManager.start();
99
+
100
+
101
+ describe('QuoteManager', function () {
102
+
103
+
104
+
105
+ it('incrementRequestsCount', async function () {
106
+ let mockProject = projectMock.mockProjectSandboxPlan;
107
+ let mockRequest = requestMock.requestMock;
108
+
109
+
110
+ mockRequest.createdAt = new Date(dateList[0]);
111
+
112
+ let initial_quote = await quoteManager.getCurrentQuote(mockProject, mockRequest, 'requests');
113
+ if (log) { console.log("[Quote Test] initial_quote: ", initial_quote); }
114
+
115
+ let key_incremented = await quoteManager.incrementRequestsCount(mockProject, mockRequest);
116
+ if (log) { console.log("[Quote Test] key_incremented: ", key_incremented); }
117
+
118
+ let final_quote = await quoteManager.getCurrentQuote(mockProject, mockRequest, 'requests');
119
+ if (log) { console.log("[Quote Test] final_quote: ", final_quote); }
120
+
121
+ expect(key_incremented).to.equal("quotes:requests:64e36f5dbf72263f7c059999:20/10/2023");
122
+ expect(final_quote).to.equal(initial_quote + 1);
123
+ })
124
+
125
+ it('incrementMessagesCount', async function () {
126
+ let mockProject = projectMock.mockProjectSandboxPlan;
127
+ let mockMessage = messageMock.messageMock;
128
+
129
+ mockMessage.createdAt = new Date();
130
+
131
+ let initial_quote = await quoteManager.getCurrentQuote(mockProject, mockMessage, 'messages');
132
+ if (log) { console.log("[Quote Test] initial_quote: ", initial_quote); }
133
+
134
+ let key_incremented = await quoteManager.incrementMessagesCount(mockProject, mockMessage);
135
+ if (log) { console.log("[Quote Test] key_incremented: ", key_incremented); }
136
+
137
+ let final_quote = await quoteManager.getCurrentQuote(mockProject, mockMessage, 'messages');
138
+ if (log) { console.log("[Quote Test] current quote: ", final_quote); }
139
+
140
+ //expect(key_incremented).to.equal("quotes:messages:64e36f5dbf72263f7c059999:20/10/2023");
141
+ expect(final_quote).to.equal(initial_quote + 1);
142
+
143
+ })
144
+
145
+ it('incrementEmailCount', async function () {
146
+ let mockProject = projectMock.mockProjectSandboxPlan;
147
+ let mockEmail = emailMock.emailMock;
148
+
149
+ let result = await quoteManager.checkQuote(mockProject, mockEmail, 'email');
150
+ console.log("checkQuote result: ", result)
151
+
152
+ let initial_quote = await quoteManager.getCurrentQuote(mockProject, mockEmail, 'email');
153
+ if (log) { console.log("[Quote Test] initial_quote: ", initial_quote); }
154
+
155
+ let key_incremented = await quoteManager.incrementEmailCount(mockProject, mockEmail);
156
+ if (log) { console.log("[Quote Test] key_incremented: ", key_incremented); }
157
+
158
+ let final_quote = await quoteManager.getCurrentQuote(mockProject, mockEmail, 'email');
159
+ if (log) { console.log("[Quote Test] current quote: ", final_quote); }
160
+
161
+ expect(key_incremented).to.equal("quotes:email:64e36f5dbf72263f7c059999:20/10/2023");
162
+ expect(final_quote).to.equal(initial_quote + 1);
163
+
164
+ })
165
+
166
+ it('sendEmailDirect', (done) => {
167
+
168
+ var email = "test-signup-" + Date.now() + "@email.com";
169
+ var pwd = "pwd";
170
+
171
+ userService.signup(email, pwd, "Test Firstname", "Test lastname").then(function (savedUser) {
172
+ projectService.create("test-send-email-direct", savedUser._id).then(function (savedProject) {
173
+ chai.request(server)
174
+ .post('/' + savedProject._id + '/emails/internal/send')
175
+ .auth(email, pwd)
176
+ .send({ to: "giovanni.troisiub@gmail.com", text: "Hello", subject: "HelloSub", replyto: "giovanni.troisiub@gmail.com" })
177
+ .end((err, res) => {
178
+ console.log("email internal send err", err);
179
+ console.log("email internal send res.body", res.body);
180
+ done();
181
+ });
182
+ });
183
+ });
184
+
185
+ })
186
+
187
+ it('incrementTokensCount', (done) => {
188
+
189
+ var email = "test-quote-" + Date.now() + "@email.com";
190
+ var pwd = "pwd";
191
+
192
+ userService.signup(email, pwd, "Test Firstname", "Test Lastname").then((savedUser) => {
193
+ projectService.create("quote-project", savedUser._id).then((savedProject) => {
194
+
195
+ let createdAt = new Date();
196
+ createdAt.setDate(createdAt.getDate() + 1)
197
+
198
+ chai.request(server)
199
+ .post('/' + savedProject._id + "/openai/quotes")
200
+ .auth(email, pwd)
201
+ .send({ createdAt: createdAt , tokens: 128 })
202
+ .end((err, res) => {
203
+ if (log) { console.log("res.body", res.body )};
204
+ res.should.have.status(200);
205
+ res.body.should.be.a('object');
206
+
207
+ let date = new Date().toLocaleDateString();
208
+
209
+ let key = "quotes:tokens:" + savedProject._id + ":" + date;
210
+ let message_resp = "value incremented for key " + key;
211
+ expect(res.body.message).to.equal(message_resp);
212
+ expect(res.body.key).to.equal(key);
213
+ expect(res.body.currentQuote).to.equal(128);
214
+
215
+
216
+ done();
217
+ })
218
+ })
219
+ })
220
+
221
+
222
+ })
223
+
224
+
225
+
226
+
227
+ // it('incrementRequestCountMulti', async function () {
228
+ // let mockProject = projectMock.mockProjectSandboxPlan;
229
+ // let mockRequest = requestMock.requestMock;
230
+
231
+ // let quoteManager = new QuoteManager({ project: mockProject, tdCache: tdCache });
232
+
233
+ // for (let date of dateList) {
234
+ // mockRequest.createdAt = new Date(date);
235
+ // let result = await quoteManager.incrementRequestsCount(mockRequest);
236
+ // console.log("result: ", result);
237
+ // console.log("\n\n");
238
+ // }
239
+
240
+ // })
241
+
242
+ // it('incrementRequestCountLimitReached', async function () {
243
+
244
+ // let mockProject = projectMock.mockProjectSandboxPlan;
245
+ // let mockRequest = requestMock.requestMock;
246
+
247
+ // // for the test the limit is fixed to 5
248
+
249
+ // let i;
250
+ // let quoteManager = new QuoteManager({ project: mockProject, tdCache: tdCache });
251
+
252
+ // for (i = 0; i < 5; i++) {
253
+ // mockRequest.createdAt = new Date(dateList[i]);
254
+ // await quoteManager.incrementRequestsCount(mockRequest);
255
+ // }
256
+
257
+ // mockRequest.createdAt = new Date(dateList[i]);
258
+ // let result = await quoteManager.incrementRequestsCount(mockRequest);
259
+ // console.log("result: ", result);
260
+
261
+
262
+ // })
263
+
264
+ // it('getCurrentCount', async function() {
265
+ // let mockProject = projectMock.mockProjectSandboxPlan;
266
+ // let mockRequest = requestMock.requestMock;
267
+
268
+ // let quoteManager = new QuoteManager({ project: mockProject, tdCache: mockTdCache } );
269
+
270
+ // for (let date of dateList) {
271
+ // mockRequest.createdAt = new Date(date);
272
+ // let result = await quoteManager.incrementRequestCount(mockRequest);
273
+ // console.log("result: ", result);
274
+ // }
275
+
276
+ // let today = new Date('2023-12-22T08:45:54.058Z');
277
+ // let quote = await quoteManager.getCurrentQuote(today, 'requests');
278
+ // console.log("request quote: ", quote)
279
+
280
+
281
+ // })
282
+ })
@@ -50,7 +50,7 @@ describe('RequestRoute', () => {
50
50
  .send({"first_text":"first_text"})
51
51
  .end(function(err, res) {
52
52
  //console.log("res", res);
53
- console.log("res.body", res.body);
53
+ //console.log("res.body", res.body);
54
54
  res.should.have.status(200);
55
55
  res.body.should.be.a('object');
56
56