chat-platform 1.3.0 → 2.0.0

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/.eslintrc CHANGED
@@ -1,17 +1,24 @@
1
1
  {
2
- "globals": {
3
- "Promise": true
4
- },
5
- "env": {
6
- "node": true,
7
- "es6": true
8
- },
9
- "extends": "eslint:recommended",
10
- "rules": {
11
- "quotes": ["error", "single"],
12
- "no-useless-escape": 0
13
- },
14
- "parserOptions": {
15
- "ecmaVersion": 8
16
- }
17
- }
2
+ "globals": {
3
+ "Promise": true
4
+ },
5
+ "env": {
6
+ "node": true,
7
+ "es6": true,
8
+ "jest/globals": true
9
+ },
10
+ "extends": "eslint:recommended",
11
+ "rules": {
12
+ "quotes": [
13
+ "error",
14
+ "single"
15
+ ],
16
+ "no-useless-escape": 0
17
+ },
18
+ "parserOptions": {
19
+ "ecmaVersion": 8
20
+ },
21
+ "plugins": [
22
+ "jest"
23
+ ]
24
+ }
@@ -1,222 +1,181 @@
1
1
  const _ = require('underscore');
2
2
  const assert = require('chai').assert;
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+
3
6
  const RED = require('../lib/red-stub')();
4
7
  const ContextProviders = require('../chat-context-factory');
5
- const { when } = require('../lib/utils');
6
8
 
7
9
  describe('Chat context provider memory', () => {
8
-
9
10
  const contextProviders = ContextProviders(RED);
11
+ const path = os.tmpdir();
12
+ const getProvider = () => contextProviders.getProvider('memory', {
13
+ chatbotId: 'my-bot'
14
+ });
10
15
 
11
- beforeEach(() => {
12
- const provider = contextProviders.getProvider('memory');
13
- provider.reset();
16
+ beforeAll(async () => {
17
+ const provider = getProvider();
18
+ await provider.start();
14
19
  });
15
20
 
16
- it('should create a context provider with some default params with chatId', () => {
21
+ afterAll(async () => {
22
+ });
23
+
24
+ it('should create a context provider with some default params with userId', async () => {
17
25
 
18
26
  assert.isTrue(contextProviders.hasProvider('memory'));
19
- const provider = contextProviders.getProvider('memory');
27
+ const provider = getProvider();
20
28
  assert.isFunction(provider.getOrCreate);
21
29
  assert.isFunction(provider.get);
30
+ const chatContext = await provider.getOrCreateContext(43, { chatId: 43 });
31
+ await chatContext.set({ myVariable: 'initial value' })
32
+ assert.isFunction(chatContext.get);
33
+ assert.isFunction(chatContext.set);
34
+ assert.isFunction(chatContext.all);
35
+ assert.isFunction(chatContext.remove);
36
+ assert.isFunction(chatContext.clear);
37
+ const myVariable = await chatContext.get('myVariable');
38
+
39
+ assert.equal(myVariable, 'initial value');
40
+ });
22
41
 
23
- return when(provider.getOrCreate(43, null, { myVariable: 'initial value'}))
24
- .then(chatContext => {
25
- assert.isFunction(chatContext.get);
26
- assert.isFunction(chatContext.set);
27
- assert.isFunction(chatContext.all);
28
- assert.isFunction(chatContext.remove);
29
- assert.isFunction(chatContext.clear);
30
- return chatContext.get('myVariable');
31
- }).then(myVariable => {
32
- assert.equal(myVariable, 'initial value');
33
- });
42
+ it('should create a userId given the chatId and transport', async () => {
43
+ const provider = getProvider();
44
+
45
+ const userId = await provider.getOrCreateUserId('42', 'telegram');
46
+ assert.equal(userId, '42');
47
+ const context42 = await provider.getOrCreateContext('42', { });
48
+ await context42.set('myVar', 'guido');
49
+ await context42.set('anotherVar', 'guidone');
50
+ assert.equal(await context42.get('myVar'), 'guido');
51
+ assert.equal(await context42.get('anotherVar'), 'guidone');
52
+
53
+ const anotherUserId = await provider.getOrCreateUserId('43', 'facebook');
54
+ assert.equal(anotherUserId, '43');
55
+ const context43 = await provider.getOrCreateContext('43', { });
56
+ await context43.set('againAnotherVar', 'something');
57
+ assert.equal(await context43.get('againAnotherVar'), 'something');
58
+
59
+ await provider.mergeUserId('43', '42');
60
+
61
+ assert.equal(await provider.getUserId('42', 'telegram'), '42');
62
+ assert.equal(await provider.getUserId('43', 'facebook'), '42');
63
+ assert.equal(await provider.getChatId('42', 'telegram'), '42');
64
+ assert.equal(await provider.getChatId('42', 'facebook'), '43');
65
+
66
+ const newContext = await provider.getOrCreateContext('42');
67
+ assert.equal(await newContext.get('myVar'), 'guido');
68
+ assert.equal(await newContext.get('anotherVar'), 'guidone');
34
69
  });
35
70
 
36
- it('should create a context provider with some default params with userId', () => {
71
+ });
37
72
 
38
- assert.isTrue(contextProviders.hasProvider('memory'));
39
- const provider = contextProviders.getProvider('memory');
40
- assert.isFunction(provider.getOrCreate);
41
- assert.isFunction(provider.get);
42
-
43
- return when(provider.getOrCreate(null, 44, { myVariable: 'initial value'}))
44
- .then(chatContext => {
45
- assert.isFunction(chatContext.get);
46
- assert.isFunction(chatContext.set);
47
- assert.isFunction(chatContext.all);
48
- assert.isFunction(chatContext.remove);
49
- assert.isFunction(chatContext.clear);
50
- return chatContext.get('myVariable');
51
- }).then(myVariable => {
52
- assert.equal(myVariable, 'initial value');
53
- });
54
- });
73
+ describe('Chat context provider memory', () => {
74
+ const contextProviders = ContextProviders(RED);
75
+ const getProvider = () => contextProviders.getProvider('memory', {
76
+ chatbotId: 'my-bot'
77
+ });
55
78
 
79
+ beforeAll(async () => {
80
+ const provider = getProvider();
81
+ await provider.start();
82
+ });
56
83
 
57
- it('should set some value and then get and remove it with chatId', () => {
84
+ afterAll(async () => {
85
+ });
58
86
 
59
- const provider = contextProviders.getProvider('memory');
87
+ beforeEach(async () => {
88
+ const provider = getProvider();
89
+ await provider.reset();
90
+ });
60
91
 
61
- return when(provider.getOrCreate(42, null, {}))
62
- .then(chatContext => chatContext.set('firstName', 'Guidone'))
63
- .then(() => when(provider.get(42).get('firstName')))
64
- .then(firstName => assert.equal(firstName, 'Guidone'))
65
- .then(() => when(provider.get(42).remove('firstName')))
66
- .then(() => when(provider.get(42).get('firstName')))
67
- .then(
68
- () => {},
69
- firstName => {
70
- assert.isUndefined(firstName);
71
- });
92
+ it('should create a context provider with some default params with userId', async () => {
93
+ assert.isTrue(contextProviders.hasProvider('memory'));
94
+ const provider = getProvider();
95
+ assert.isFunction(provider.getOrCreate);
96
+ assert.isFunction(provider.get);
97
+ const chatContext = await provider.getOrCreateContext(44, { chatId: 43 });
98
+ await chatContext.set({ myVariable: 'initial value' })
99
+ assert.isFunction(chatContext.get);
100
+ assert.isFunction(chatContext.set);
101
+ assert.isFunction(chatContext.all);
102
+ assert.isFunction(chatContext.remove);
103
+ assert.isFunction(chatContext.clear);
104
+ const myVariable = await chatContext.get('myVariable');
105
+ assert.equal(myVariable, 'initial value');
72
106
  });
73
107
 
74
- it('should set some value and then get and remove it with userId', () => {
108
+ it('should set some value and then get and remove it with userId', async () => {
109
+ const provider = getProvider();
110
+ const chatContext = await provider.getOrCreateContext(43, { userId: 43 });
111
+ await chatContext.set('firstName', 'Guidone');
112
+ let firstName = await chatContext.get('firstName');
113
+ assert.equal(firstName, 'Guidone');
114
+ await chatContext.remove('firstName')
115
+ firstName = await chatContext.get('firstName');
116
+ assert.isNull(firstName);
117
+ });
75
118
 
76
- const provider = contextProviders.getProvider('memory');
119
+ it('should set some values and then get and remove it with userId', async () => {
120
+ const provider = getProvider();
121
+ const chatContext = await provider.getOrCreateContext(43, { userId: 43 });
122
+ await chatContext.set({firstName: 'Guido', lastName: 'Bellomo'});
123
+ const firstName = await chatContext.get('firstName');
124
+ assert.equal(firstName, 'Guido');
125
+ const lastName = await chatContext.get('lastName');
126
+ assert.equal(lastName, 'Bellomo');
127
+ const json = await chatContext.get('firstName', 'lastName');
128
+ assert.isObject(json);
129
+ assert.equal(json.firstName, 'Guido');
130
+ assert.equal(json.lastName, 'Bellomo');
131
+ });
77
132
 
78
- return when(provider.getOrCreate(null, 43, {}))
79
- .then(chatContext => chatContext.set('firstName', 'Guidone'))
80
- .then(() => when(provider.get(null, 43).get('firstName')))
81
- .then(firstName => assert.equal(firstName, 'Guidone'))
82
- .then(() => when(provider.get(null, 43).remove('firstName')))
83
- .then(() => when(provider.get(null, 43).get('firstName')))
84
- .then(
85
- () => {},
86
- firstName => {
87
- assert.isUndefined(firstName);
88
- });
133
+ it('should set some values and get the dump with userId', async () => {
134
+ const provider = getProvider();
135
+ const chatContext = await provider.getOrCreateContext(43, { userId: 43 });
136
+ await chatContext.set({ firstName: 'Guido', lastName: 'Bellomo', email: 'spam@gmail.com' })
137
+ const json = await chatContext.all();
138
+ assert.isObject(json);
139
+ assert.equal(json.firstName, 'Guido');
140
+ assert.equal(json.lastName, 'Bellomo');
141
+ assert.equal(json.email, 'spam@gmail.com');
89
142
  });
90
143
 
91
- it('should set some values and then get and remove it with chatId', () => {
144
+ it('should set some values and remove all with userId', async () => {
145
+ const provider = getProvider();
146
+ const chatContext = await provider.getOrCreateContext(43, { userId: 43 });
147
+ await chatContext.set({ firstName: 'Guido', lastName: 'Bellomo' });
148
+ await chatContext.clear();
149
+ const json = await chatContext.all();
150
+ assert.isObject(json);
151
+ assert.isTrue(_.isEmpty(json));
152
+ });
92
153
 
93
- const provider = contextProviders.getProvider('memory');
154
+ it('should set some value the remove with multiple arguments', async () => {
155
+ const provider = getProvider();
156
+ const chatContext = await provider.getOrCreateContext(44, { chatId: 42 });
157
+ await chatContext.set({ firstName: 'Guidone', lastName: 'Bellomo', email: 'some@email' });
158
+ const firstName = await chatContext.get('firstName');
159
+ assert.equal(firstName, 'Guidone');
160
+ await chatContext.remove('firstName', 'lastName', 'email');
161
+ const json = await chatContext.all();
162
+ assert.isUndefined(json.firstName);
163
+ assert.isUndefined(json.lastName);
164
+ assert.isUndefined(json.email);
165
+ });
94
166
 
95
- return when(provider.getOrCreate(42, null, {}))
96
- .then(chatContext => chatContext.set({firstName: 'Guido', lastName: 'Bellomo'}))
97
- .then(() => when(provider.get(42).get('firstName')))
98
- .then(firstName => assert.equal(firstName, 'Guido'))
99
- .then(() =>when(provider.get(42).get('lastName')))
100
- .then(lastName => assert.equal(lastName, 'Bellomo'))
101
- .then(() => when(provider.get(42).get('firstName', 'lastName')))
102
- .then(json => {
103
- assert.isObject(json);
104
- assert.equal(json.firstName, 'Guido');
105
- assert.equal(json.lastName, 'Bellomo');
106
- });
107
- });
108
-
109
- it('should set some values and then get and remove it with userId', () => {
110
-
111
- const provider = contextProviders.getProvider('memory');
112
-
113
- return when(provider.getOrCreate(null, 43, {}))
114
- .then(chatContext => chatContext.set({firstName: 'Guido', lastName: 'Bellomo'}))
115
- .then(() => when(provider.get(null, 43).get('firstName')))
116
- .then(firstName => assert.equal(firstName, 'Guido'))
117
- .then(() =>when(provider.get(null, 43).get('lastName')))
118
- .then(lastName => assert.equal(lastName, 'Bellomo'))
119
- .then(() => when(provider.get(null, 43).get('firstName', 'lastName')))
120
- .then(json => {
121
- assert.isObject(json);
122
- assert.equal(json.firstName, 'Guido');
123
- assert.equal(json.lastName, 'Bellomo');
124
- });
125
- });
126
-
127
- it('should set some values and get the dump with chatId', () => {
128
-
129
- const provider = contextProviders.getProvider('memory');
130
-
131
- return when(provider.getOrCreate(42, null, {}))
132
- .then(chatContext => chatContext.set({firstName: 'Guido', lastName: 'Bellomo', email: 'spam@gmail.com'}))
133
- .then(() => when(provider.get(42).all()))
134
- .then(json => {
135
- assert.isObject(json);
136
- assert.equal(json.firstName, 'Guido');
137
- assert.equal(json.lastName, 'Bellomo');
138
- assert.equal(json.email, 'spam@gmail.com');
139
- });
140
- });
141
-
142
- it('should set some values and get the dump with userId', () => {
143
-
144
- const provider = contextProviders.getProvider('memory');
145
-
146
- return when(provider.getOrCreate(null, 43, {}))
147
- .then(chatContext => chatContext.set({firstName: 'Guido', lastName: 'Bellomo', email: 'spam@gmail.com'}))
148
- .then(() => when(provider.get(null, 43).all()))
149
- .then(json => {
150
- assert.isObject(json);
151
- assert.equal(json.firstName, 'Guido');
152
- assert.equal(json.lastName, 'Bellomo');
153
- assert.equal(json.email, 'spam@gmail.com');
154
- });
155
- });
156
-
157
- it('should set some values and remove all with chatId', () => {
158
-
159
- const provider = contextProviders.getProvider('memory');
160
-
161
- return when(provider.getOrCreate(42, null, {}))
162
- .then(chatContext => chatContext.set({firstName: 'Guido', lastName: 'Bellomo'}))
163
- .then(() => when(provider.get(42).clear()))
164
- .then(() => when(provider.get(42).all()))
165
- .then(json => {
166
- assert.isObject(json);
167
- assert.isTrue(_.isEmpty(json));
168
- });
169
- });
170
-
171
- it('should set some values and remove all with userId', () => {
172
-
173
- const provider = contextProviders.getProvider('memory');
174
-
175
- return when(provider.getOrCreate(null, 43, {}))
176
- .then(chatContext => chatContext.set({firstName: 'Guido', lastName: 'Bellomo'}))
177
- .then(() => when(provider.get(null, 43).clear()))
178
- .then(() => when(provider.get(null, 43).all()))
179
- .then(json => {
180
- assert.isObject(json);
181
- assert.isTrue(_.isEmpty(json));
182
- });
183
- });
184
-
185
- it('should set some value the remove with multiple arguments', () => {
186
-
187
- const provider = contextProviders.getProvider('memory');
188
-
189
- return when(provider.getOrCreate(42, null, {}))
190
- .then(chatContext =>chatContext.set({firstName: 'Guidone', lastName: 'Bellomo', email: 'some@email'}))
191
- .then(() => when(provider.get(42).get('firstName')))
192
- .then(firstName => assert.equal(firstName, 'Guidone'))
193
- .then(() => when(provider.get(42).remove('firstName', 'lastName', 'email')))
194
- .then(() => when(provider.get(42).all()))
195
- .then(json => {
196
- assert.isUndefined(json.firstName);
197
- assert.isUndefined(json.lastName);
198
- assert.isUndefined(json.email);
199
- });
200
- });
201
-
202
- it('should set some value with chatId and userId', () => {
203
- const provider = contextProviders.getProvider('memory');
204
- return when(provider.getOrCreate(42, 44, { myVar: 123 }))
205
- .then(chatContext => chatContext.set('firstName', 'Guidone'))
206
- .then(() => when(provider.get(null, 44).get('firstName')))
207
- .then(firstName => assert.equal(firstName, 'Guidone'))
208
- .then(() => when(provider.get(null, 44, { myVar: 123 })))
209
- .then(chatContext => {
210
- assert.equal(chatContext.get('firstName'), 'Guidone');
211
- assert.equal(chatContext.get('myVar'), 123);
212
- })
213
- .then(() => when(provider.get(null, 44).remove('firstName')))
214
- .then(() => when(provider.get(null, 44).get('firstName')))
215
- /*.then(
216
- () => {},
217
- firstName => {
218
- assert.isUndefined(firstName);
219
- });*/
167
+ it('should set some value with chatId and userId', async () => {
168
+ const provider = getProvider();
169
+ let chatContext = await provider.getOrCreateContext(44, { userId: 44, chatId: 42 });
170
+ await chatContext.set('firstName', 'Guidone');
171
+ let firstName = await chatContext.get('firstName');
172
+ assert.equal(firstName, 'Guidone');
173
+ chatContext = await provider.getOrCreateContext(44, { userId: 44, chatId: 42 });
174
+ assert.equal(await chatContext.get('userId'), 44);
175
+ assert.equal(await chatContext.get('firstName'), 'Guidone');
176
+ await chatContext.remove('firstName');
177
+ firstName = await chatContext.get('firstName');
178
+ assert.isNull(firstName);
220
179
  });
221
180
 
222
181
  });
@@ -1,10 +1,10 @@
1
1
  const _ = require('underscore');
2
2
  const assert = require('chai').assert;
3
3
  const fs = require('fs');
4
+ const os = require('os');
5
+
4
6
  const RED = require('../lib/red-stub')();
5
7
  const ContextProviders = require('../chat-context-factory');
6
- const { when } = require('../lib/utils');
7
- const os = require('os');
8
8
 
9
9
  const copyFile = (source, destination) => new Promise((resolve, reject) => {
10
10
  fs.copyFile(source, destination, error => {
@@ -29,7 +29,10 @@ const removeFile = file => new Promise((resolve, reject) => {
29
29
  describe('Chat context provider sqlite - missing file', () => {
30
30
  const contextProviders = ContextProviders(RED);
31
31
  const path = os.tmpdir();
32
- const getProvider = () => contextProviders.getProvider('sqlite', { dbPath: path + '/mission-control.sqlite' });
32
+ const getProvider = () => contextProviders.getProvider('sqlite', {
33
+ dbPath: path + '/mission-control.sqlite',
34
+ chatbotId: 'my-bot'
35
+ });
33
36
 
34
37
  beforeAll(async () => {
35
38
  const provider = getProvider();
@@ -40,13 +43,13 @@ describe('Chat context provider sqlite - missing file', () => {
40
43
  await removeFile(path + '/mission-control.sqlite');
41
44
  });
42
45
 
43
- it('should create a context provider with some default params with chatId', async () => {
46
+ it('should create a context provider with some default params with userId', async () => {
44
47
 
45
48
  assert.isTrue(contextProviders.hasProvider('sqlite'));
46
49
  const provider = getProvider();
47
50
  assert.isFunction(provider.getOrCreate);
48
51
  assert.isFunction(provider.get);
49
- const chatContext = await provider.getOrCreate(43, null, { chatId: 43 });
52
+ const chatContext = await provider.getOrCreateContext(43, { chatId: 43 });
50
53
  await chatContext.set({ myVariable: 'initial value' })
51
54
  assert.isFunction(chatContext.get);
52
55
  assert.isFunction(chatContext.set);
@@ -58,13 +61,43 @@ describe('Chat context provider sqlite - missing file', () => {
58
61
  assert.equal(myVariable, 'initial value');
59
62
  });
60
63
 
64
+ it('should create a userId given the chatId and transport', async () => {
65
+ const provider = getProvider();
61
66
 
62
- });
67
+ const userId = await provider.getOrCreateUserId('42', 'telegram');
68
+ assert.equal(userId, '42');
69
+ const context42 = await provider.getOrCreateContext('42', { });
70
+ await context42.set('myVar', 'guido');
71
+ await context42.set('anotherVar', 'guidone');
72
+ assert.equal(await context42.get('myVar'), 'guido');
73
+ assert.equal(await context42.get('anotherVar'), 'guidone');
74
+
75
+ const anotherUserId = await provider.getOrCreateUserId('43', 'facebook');
76
+ assert.equal(anotherUserId, '43');
77
+ const context43 = await provider.getOrCreateContext('43', { });
78
+ await context43.set('againAnotherVar', 'something');
79
+ assert.equal(await context43.get('againAnotherVar'), 'something');
80
+
81
+ await provider.mergeUserId('43', '42');
63
82
 
83
+ assert.equal(await provider.getUserId('42', 'telegram'), '42');
84
+ assert.equal(await provider.getUserId('43', 'facebook'), '42');
85
+ assert.equal(await provider.getChatId('42', 'telegram'), '42');
86
+ assert.equal(await provider.getChatId('42', 'facebook'), '43');
87
+
88
+ const newContext = await provider.getOrCreateContext('42');
89
+ assert.equal(await newContext.get('myVar'), 'guido');
90
+ assert.equal(await newContext.get('anotherVar'), 'guidone');
91
+ });
92
+
93
+ });
64
94
 
65
95
  describe('Chat context provider sqlite', () => {
66
96
  const contextProviders = ContextProviders(RED);
67
- const getProvider = () => contextProviders.getProvider('sqlite', { dbPath: __dirname + '/dummy/mission-control.sqlite' });
97
+ const getProvider = () => contextProviders.getProvider('sqlite', {
98
+ dbPath: __dirname + '/dummy/mission-control.sqlite',
99
+ chatbotId: 'my-bot'
100
+ });
68
101
 
69
102
  beforeAll(async () => {
70
103
  await copyFile(__dirname + '/dummy/mission-control.backup', __dirname + '/dummy/mission-control.sqlite');
@@ -81,30 +114,12 @@ describe('Chat context provider sqlite', () => {
81
114
  await provider.reset();
82
115
  });
83
116
 
84
- it('should create a context provider with some default params with chatId', async () => {
85
-
86
- assert.isTrue(contextProviders.hasProvider('sqlite'));
87
- const provider = getProvider();
88
- assert.isFunction(provider.getOrCreate);
89
- assert.isFunction(provider.get);
90
- const chatContext = await provider.getOrCreate(43, null, { chatId: 43 });
91
- await chatContext.set({ myVariable: 'initial value' })
92
- assert.isFunction(chatContext.get);
93
- assert.isFunction(chatContext.set);
94
- assert.isFunction(chatContext.all);
95
- assert.isFunction(chatContext.remove);
96
- assert.isFunction(chatContext.clear);
97
- const myVariable = await chatContext.get('myVariable');
98
-
99
- assert.equal(myVariable, 'initial value');
100
- });
101
-
102
117
  it('should create a context provider with some default params with userId', async () => {
103
118
  assert.isTrue(contextProviders.hasProvider('sqlite'));
104
119
  const provider = getProvider();
105
120
  assert.isFunction(provider.getOrCreate);
106
121
  assert.isFunction(provider.get);
107
- const chatContext = await provider.getOrCreate(null, 44, { userId: 44 });
122
+ const chatContext = await provider.getOrCreateContext(44, { chatId: 43 });
108
123
  await chatContext.set({ myVariable: 'initial value' })
109
124
  assert.isFunction(chatContext.get);
110
125
  assert.isFunction(chatContext.set);
@@ -115,21 +130,9 @@ describe('Chat context provider sqlite', () => {
115
130
  assert.equal(myVariable, 'initial value');
116
131
  });
117
132
 
118
-
119
- it('should set some value and then get and remove it with chatId', async () => {
120
- const provider = getProvider();
121
- const chatContext = await provider.getOrCreate(42, null, { chatId: 42 });
122
- await chatContext.set('firstName', 'Guidone');
123
- let firstName = await chatContext.get('firstName');
124
- assert.equal(firstName, 'Guidone')
125
- await chatContext.remove('firstName')
126
- firstName = await chatContext.get('firstName')
127
- assert.isNull(firstName);
128
- });
129
-
130
133
  it('should set some value and then get and remove it with userId', async () => {
131
134
  const provider = getProvider();
132
- const chatContext = await provider.getOrCreate(null, 43, { userId: 43 });
135
+ const chatContext = await provider.getOrCreateContext(43, { userId: 43 });
133
136
  await chatContext.set('firstName', 'Guidone');
134
137
  let firstName = await chatContext.get('firstName');
135
138
  assert.equal(firstName, 'Guidone');
@@ -138,24 +141,9 @@ describe('Chat context provider sqlite', () => {
138
141
  assert.isNull(firstName);
139
142
  });
140
143
 
141
-
142
- it('should set some values and then get and remove it with chatId', async () => {
143
- const provider = getProvider();
144
- const chatContext = await provider.getOrCreate(42, null, { chatId: 42 });
145
- await chatContext.set({ firstName: 'Guido', lastName: 'Bellomo' });
146
- let firstName = await chatContext.get('firstName');
147
- assert.equal(firstName, 'Guido');
148
- let lastName = await chatContext.get('lastName');
149
- assert.equal(lastName, 'Bellomo')
150
- const json = await chatContext.get('firstName', 'lastName');
151
- assert.isObject(json);
152
- assert.equal(json.firstName, 'Guido');
153
- assert.equal(json.lastName, 'Bellomo');
154
- });
155
-
156
144
  it('should set some values and then get and remove it with userId', async () => {
157
145
  const provider = getProvider();
158
- const chatContext = await provider.getOrCreate(null, 43, { userId: 43 });
146
+ const chatContext = await provider.getOrCreateContext(43, { userId: 43 });
159
147
  await chatContext.set({firstName: 'Guido', lastName: 'Bellomo'});
160
148
  const firstName = await chatContext.get('firstName');
161
149
  assert.equal(firstName, 'Guido');
@@ -167,20 +155,9 @@ describe('Chat context provider sqlite', () => {
167
155
  assert.equal(json.lastName, 'Bellomo');
168
156
  });
169
157
 
170
- it('should set some values and get the dump with chatId', async () => {
171
- const provider = getProvider();
172
- const chatContext = await provider.getOrCreate(42, null, { chatId: 42 });
173
- await chatContext.set({ firstName: 'Guido', lastName: 'Bellomo', email: 'spam@gmail.com' });
174
- const json = await chatContext.all();
175
- assert.isObject(json);
176
- assert.equal(json.firstName, 'Guido');
177
- assert.equal(json.lastName, 'Bellomo');
178
- assert.equal(json.email, 'spam@gmail.com');
179
- });
180
-
181
158
  it('should set some values and get the dump with userId', async () => {
182
159
  const provider = getProvider();
183
- const chatContext = await provider.getOrCreate(null, 43, { userId: 43 });
160
+ const chatContext = await provider.getOrCreateContext(43, { userId: 43 });
184
161
  await chatContext.set({ firstName: 'Guido', lastName: 'Bellomo', email: 'spam@gmail.com' })
185
162
  const json = await chatContext.all();
186
163
  assert.isObject(json);
@@ -189,19 +166,9 @@ describe('Chat context provider sqlite', () => {
189
166
  assert.equal(json.email, 'spam@gmail.com');
190
167
  });
191
168
 
192
- it('should set some values and remove all with chatId', async () => {
193
- const provider = getProvider();
194
- const chatContext = await provider.getOrCreate(42, null, { userId: 42 });
195
- await chatContext.set({ firstName: 'Guido', lastName: 'Bellomo' });
196
- await chatContext.clear();
197
- const json = await chatContext.all();
198
- assert.isObject(json);
199
- assert.isTrue(_.isEmpty(json));
200
- });
201
-
202
169
  it('should set some values and remove all with userId', async () => {
203
170
  const provider = getProvider();
204
- const chatContext = await provider.getOrCreate(null, 43, { userId: 43 });
171
+ const chatContext = await provider.getOrCreateContext(43, { userId: 43 });
205
172
  await chatContext.set({ firstName: 'Guido', lastName: 'Bellomo' });
206
173
  await chatContext.clear();
207
174
  const json = await chatContext.all();
@@ -211,7 +178,7 @@ describe('Chat context provider sqlite', () => {
211
178
 
212
179
  it('should set some value the remove with multiple arguments', async () => {
213
180
  const provider = getProvider();
214
- const chatContext = await provider.getOrCreate(42, null, { chatId: 42 });
181
+ const chatContext = await provider.getOrCreateContext(44, { chatId: 42 });
215
182
  await chatContext.set({ firstName: 'Guidone', lastName: 'Bellomo', email: 'some@email' });
216
183
  const firstName = await chatContext.get('firstName');
217
184
  assert.equal(firstName, 'Guidone');
@@ -224,11 +191,11 @@ describe('Chat context provider sqlite', () => {
224
191
 
225
192
  it('should set some value with chatId and userId', async () => {
226
193
  const provider = getProvider();
227
- let chatContext = await provider.getOrCreate(42, 44, { userId: 44, chatId: 42 });
194
+ let chatContext = await provider.getOrCreateContext(44, { userId: 44, chatId: 42 });
228
195
  await chatContext.set('firstName', 'Guidone');
229
196
  let firstName = await chatContext.get('firstName');
230
197
  assert.equal(firstName, 'Guidone');
231
- chatContext = await provider.getOrCreate(null, 44, { userId: 44, chatId: 42 });
198
+ chatContext = await provider.getOrCreateContext(44, { userId: 44, chatId: 42 });
232
199
  assert.equal(await chatContext.get('userId'), 44);
233
200
  assert.equal(await chatContext.get('firstName'), 'Guidone');
234
201
  await chatContext.remove('firstName');
@@ -236,4 +203,4 @@ describe('Chat context provider sqlite', () => {
236
203
  assert.isNull(firstName);
237
204
  });
238
205
 
239
- });
206
+ });