@wazo/sdk 0.43.11 → 0.43.13

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.
@@ -1,63 +1,191 @@
1
1
  import moment from 'moment';
2
- import CallLog from '../CallLog';
2
+ import CallLog, { Response, CallLogResponse, CALL_LOG_VALID_REQUESTED_VERSION } from '../CallLog';
3
3
  import Recording from '../Recording';
4
+ import Session from '../Session';
5
+ import Profile from '../Profile';
6
+ import Line from '../Line';
4
7
 
5
- describe('CallLog domain', () => {
6
- it('can parse a plain call log to domain', () => {
7
- const response = {
8
- filtered: 6,
9
- items: [{
10
- answer: moment('2017-08-07T13:51:18.892002+00:00').toDate(),
11
- answered: true,
12
- call_direction: 'outbound',
13
- source_extension: '8020',
14
- source_name: 'Jonathan Lessard',
15
- source_user_uuid: '123',
16
- destination_extension: '4182250459',
17
- destination_name: null,
18
- destination_user_uuid: '456',
19
- duration: 4,
20
- start: '2017-08-06T13:50:55.819057+00:00',
21
- end: '2017-08-08T13:51:23.822529+00:00',
22
- requested_extension: '',
23
- requested_name: '',
24
- id: 215,
25
- recordings: [{
26
- deleted: false,
27
- end_time: '2021-08-11T13:22:50.519733+00:00',
28
- filename: '2021-08-11T13_22_45UTC-61886-xxxx-5c72-4072-8503-e3ad9a41c0a0.wav',
29
- start_time: '2021-08-11T13:22:45.161954+00:00',
30
- uuid: '0394ad6f-5c72-4072-8503-e3ad9a41c0a0',
8
+ const ALICE_EXTENSION = '41';
9
+ const ALICE_UUID = '11111111-1111-1111-1111-111111111111';
10
+
11
+ const BOB_EXTENSION = '42';
12
+ const BOB_UUID = '22222222-2222-2222-2222-222222222222';
13
+
14
+ const CHARLIE_EXTENSION = '43';
15
+ const CHARLIE_UUID = '33333333-3333-3333-3333-333333333333';
16
+
17
+ // Default scenario: Alice > Bob (No anwser forward) > Charlie
18
+ const CALL_LOG_RESPONSE: CallLogResponse = {
19
+ id: 1,
20
+ answer: '2024-01-02T00:00:00.000000+00:00',
21
+ answered: true,
22
+ call_direction: 'internal',
23
+ source_name: 'Alice',
24
+ source_extension: ALICE_EXTENSION,
25
+ source_user_uuid: ALICE_UUID,
26
+ requested_name: 'Bob',
27
+ requested_extension: BOB_EXTENSION,
28
+ requested_user_uuid: BOB_UUID,
29
+ destination_name: 'Charlie',
30
+ destination_extension: CHARLIE_EXTENSION,
31
+ destination_user_uuid: CHARLIE_UUID,
32
+ duration: 4,
33
+ start: '2024-01-01T00:00:00.000000+00:00',
34
+ end: '2024-01-01T00:00:04.000000+00:00',
35
+ recordings: [{
36
+ uuid: '0394ad6f-5c72-4072-8503-e3ad9a41c0a0',
37
+ start_time: '2024-01-01T00:00:00.000000+00:00',
38
+ end_time: '2024-01-01T00:00:04.000000+00:00',
39
+ filename: '2024-01-01T00_00_04UTC-61886-0394ad6f-5c72-4072-8503-e3ad9a41c0a0.wav',
40
+ deleted: false,
41
+ }],
42
+ };
43
+ const CALL_LOG = CallLog.parse(CALL_LOG_RESPONSE);
44
+
45
+ const generateBobSession = (opts?: Partial<Session>): Session =>
46
+ new Session({
47
+ acl: [],
48
+ token: 'ref-12345',
49
+ uuid: BOB_UUID,
50
+ expiresAt: new Date(9999, 0, 1),
51
+ engineVersion: CALL_LOG_VALID_REQUESTED_VERSION,
52
+ profile: new Profile({
53
+ lines: [new Line({
54
+ id: 1,
55
+ extensions: [{
56
+ id: 1,
57
+ exten: BOB_EXTENSION,
58
+ context: 'internal',
31
59
  }],
32
- }],
33
- total: 233,
34
- };
35
- const logs = CallLog.parseMany(response as any);
36
- expect(logs).toEqual([new CallLog({
37
- answer: moment('2017-08-07T13:51:18.892002+00:00').toDate(),
38
- answered: true,
39
- callDirection: 'outbound',
40
- destination: {
41
- extension: '4182250459',
42
- name: '',
43
- uuid: '456',
44
- },
45
- source: {
46
- extension: '8020',
47
- name: 'Jonathan Lessard',
48
- uuid: '123',
49
- },
50
- id: 215,
51
- duration: 4000,
52
- start: moment('2017-08-06T13:50:55.819057+00:00').toDate(),
53
- end: moment('2017-08-08T13:51:23.822529+00:00').toDate(),
54
- recordings: [new Recording({
55
- deleted: false,
56
- end: moment('2021-08-11T13:22:50.519733+00:00').toDate(),
57
- fileName: '2021-08-11T13_22_45UTC-61886-xxxx-5c72-4072-8503-e3ad9a41c0a0.wav',
58
- start: moment('2021-08-11T13:22:45.161954+00:00').toDate(),
59
- uuid: '0394ad6f-5c72-4072-8503-e3ad9a41c0a0',
60
60
  })],
61
- })]);
61
+ } as any),
62
+ ...(opts || {}),
63
+ });
64
+
65
+ const BOB_SESSION = generateBobSession();
66
+
67
+ describe('CallLog Domain', () => {
68
+ describe('parseMany', () => {
69
+ it('can parse a plain call log to domain', () => {
70
+ const response: Response = {
71
+ filtered: 6,
72
+ items: [CALL_LOG_RESPONSE],
73
+ total: 233,
74
+ };
75
+
76
+ const logs = CallLog.parseMany(response);
77
+ expect(logs).toEqual([new CallLog({
78
+ id: 1,
79
+ answer: moment(CALL_LOG_RESPONSE.answer).toDate(),
80
+ answered: true,
81
+ callDirection: 'internal',
82
+ source: {
83
+ uuid: ALICE_UUID,
84
+ name: 'Alice',
85
+ extension: ALICE_EXTENSION,
86
+ },
87
+ requested: {
88
+ uuid: BOB_UUID,
89
+ name: 'Bob',
90
+ extension: BOB_EXTENSION,
91
+ },
92
+ destination: {
93
+ uuid: CHARLIE_UUID,
94
+ name: 'Bob',
95
+ extension: BOB_EXTENSION,
96
+ plainExtension: CHARLIE_EXTENSION,
97
+ plainName: 'Charlie',
98
+ },
99
+ duration: 4000,
100
+ start: moment(CALL_LOG_RESPONSE.start).toDate(),
101
+ end: moment(CALL_LOG_RESPONSE.end).toDate(),
102
+ recordings: [new Recording({
103
+ uuid: CALL_LOG_RESPONSE.recordings[0].uuid,
104
+ start: moment(CALL_LOG_RESPONSE.recordings[0].start_time).toDate(),
105
+ end: moment(CALL_LOG_RESPONSE.recordings[0].end_time).toDate(),
106
+ fileName: CALL_LOG_RESPONSE.recordings[0].filename,
107
+ deleted: false,
108
+ })],
109
+ })]);
110
+ });
111
+ });
112
+
113
+ describe('isIconming', () => {
114
+ it('should be TRUE', () => {
115
+ // When requested is set to the same user session extension
116
+ expect(CALL_LOG.isIncomingAndForwarded(BOB_SESSION)).toBe(true);
117
+
118
+ // When destination is set to the same user session extension
119
+ const destinationCallLog = CallLog.parse({
120
+ ...CALL_LOG_RESPONSE,
121
+ destination_extension: CALL_LOG_RESPONSE.requested_extension,
122
+ destination_name: CALL_LOG_RESPONSE.requested_name,
123
+ destination_user_uuid: CALL_LOG_RESPONSE.requested_user_uuid,
124
+ requested_extension: CALL_LOG_RESPONSE.destination_extension,
125
+ requested_name: CALL_LOG_RESPONSE.destination_name,
126
+ requested_user_uuid: CALL_LOG_RESPONSE.destination_user_uuid,
127
+ });
128
+ expect(destinationCallLog.isIncomingAndForwarded(BOB_SESSION)).toBe(true);
129
+
130
+ // When call direction is inbound
131
+ const inboundCallLog = CallLog.parse({ ...CALL_LOG_RESPONSE, call_direction: 'inbound' });
132
+ expect(inboundCallLog.isIncomingAndForwarded(BOB_SESSION)).toBe(true);
133
+
134
+ });
135
+
136
+ it('should be FALSE', () => {
137
+ // When call direction is outbound
138
+ const outboundCallLog = CallLog.parse({ ...CALL_LOG_RESPONSE, call_direction: 'outbound' });
139
+ expect(outboundCallLog.isIncomingAndForwarded(BOB_SESSION)).toBe(false);
140
+ });
141
+ });
142
+
143
+ describe('isIncomingAndForwarded', () => {
144
+ it('should be TRUE when requested is current user extension and destination is another extesnion', () => {
145
+ // Internal call (requested contact)
146
+ expect(CALL_LOG.isIncomingAndForwarded(BOB_SESSION)).toBe(true);
147
+
148
+ // Inbound call (requested contact)
149
+ const inboundCallLog = CallLog.parse({
150
+ ...CALL_LOG_RESPONSE,
151
+ call_direction: 'inbound',
152
+ source_extension: '18004444444',
153
+ source_name: '',
154
+ source_user_uuid: null,
155
+ });
156
+ expect(inboundCallLog.isIncomingAndForwarded(BOB_SESSION)).toBe(true);
157
+
158
+ // Current user is the final destination
159
+ const destinationCallLog = CallLog.parse({
160
+ ...CALL_LOG_RESPONSE,
161
+ destination_extension: CALL_LOG_RESPONSE.requested_extension,
162
+ destination_name: CALL_LOG_RESPONSE.requested_name,
163
+ destination_user_uuid: CALL_LOG_RESPONSE.requested_user_uuid,
164
+ requested_extension: CALL_LOG_RESPONSE.destination_extension,
165
+ requested_name: CALL_LOG_RESPONSE.destination_name,
166
+ requested_user_uuid: CALL_LOG_RESPONSE.destination_user_uuid,
167
+ });
168
+ expect(destinationCallLog.isIncomingAndForwarded(BOB_SESSION)).toBe(true);
169
+ });
170
+
171
+ it('should be FALSE', () => {
172
+ // Requested and destination are same
173
+ const directCallLog = CallLog.parse({
174
+ ...CALL_LOG_RESPONSE,
175
+ requested_extension: CALL_LOG_RESPONSE.destination_extension,
176
+ requested_name: CALL_LOG_RESPONSE.destination_name,
177
+ requested_user_uuid: CALL_LOG_RESPONSE.destination_user_uuid,
178
+ });
179
+
180
+ expect(directCallLog.isIncomingAndForwarded(BOB_SESSION)).toBe(false);
181
+
182
+ // Not incoming call
183
+ const outboundCallLog = CallLog.parse({ ...CALL_LOG_RESPONSE, call_direction: 'outbound' });
184
+ expect(outboundCallLog.isIncomingAndForwarded(BOB_SESSION)).toBe(false);
185
+
186
+ // Stack version
187
+ const oldStackSession = generateBobSession({ engineVersion: CALL_LOG_VALID_REQUESTED_VERSION.replace('14', '10') });
188
+ expect(CALL_LOG.isIncomingAndForwarded(oldStackSession)).toBe(false);
189
+ });
62
190
  });
63
191
  });
@@ -3,6 +3,8 @@ import Contact from '../Contact';
3
3
  const genericContactResponse = {
4
4
  column_types: [
5
5
  'name',
6
+ 'firstname',
7
+ 'lastname',
6
8
  'number',
7
9
  'callable',
8
10
  'voicemail',
@@ -13,6 +15,8 @@ const genericContactResponse = {
13
15
  term: 'a',
14
16
  column_headers: [
15
17
  'Nom',
18
+ 'Pr\u00e9nom',
19
+ 'Nom de famille',
16
20
  'Num\u00e9ro',
17
21
  'Mobile',
18
22
  'Bo\u00eete vocale',
@@ -27,6 +31,8 @@ const contact1 = {
27
31
  source: 'internal',
28
32
  column_values: [
29
33
  'Jonathan Lessard',
34
+ 'Jonathan',
35
+ 'Lessard',
30
36
  '8020',
31
37
  '06800880',
32
38
  null,
@@ -49,6 +55,8 @@ const contact2 = {
49
55
  source: 'internal',
50
56
  column_values: [
51
57
  'John Doe',
58
+ 'John',
59
+ 'Doe',
52
60
  '8021',
53
61
  '06800881',
54
62
  null,
@@ -69,6 +77,8 @@ const contact2 = {
69
77
 
70
78
  const parsedContact1 = new Contact({
71
79
  name: 'Jonathan Lessard',
80
+ firstName: 'Jonathan',
81
+ lastName: 'Lessard',
72
82
  number: '8020',
73
83
  numbers: [
74
84
  {
@@ -102,6 +112,8 @@ const parsedContact1 = new Contact({
102
112
 
103
113
  const parsedContact2 = new Contact({
104
114
  name: 'John Doe',
115
+ firstName: 'John',
116
+ lastName: 'Doe',
105
117
  number: '8021',
106
118
  numbers: [
107
119
  {
@@ -2025,9 +2025,6 @@ export default class WebRTCClient extends Emitter {
2025
2025
  authorizationPassword: this.config.password,
2026
2026
  displayName: this.config.displayName,
2027
2027
  hackIpInContact: true,
2028
- contactParams: {
2029
- transport: 'wss',
2030
- },
2031
2028
  logBuiltinEnabled: this.config.log ? this.config.log.builtinEnabled : null,
2032
2029
  logLevel: this.config.log ? this.config.log.logLevel : null,
2033
2030
  logConnector: this.config.log ? this.config.log.connector : null,