@2bad/bitrix 2.5.0 → 3.0.0-beta.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.
Files changed (242) hide show
  1. package/README.md +10 -9
  2. package/build/bitrix.d.ts +65 -0
  3. package/build/bitrix.js +55 -0
  4. package/build/client/hooks/addAccessToken.js +9 -0
  5. package/build/{module/client → client}/index.d.ts +3 -3
  6. package/build/{module/client → client}/index.js +21 -16
  7. package/build/{module/client → client}/methods/batch.d.ts +6 -6
  8. package/build/client/methods/batch.js +75 -0
  9. package/build/{module/client → client}/methods/call.d.ts +4 -4
  10. package/build/{module/client → client}/methods/call.js +8 -9
  11. package/build/{module/client → client}/methods/list.d.ts +10 -10
  12. package/build/client/methods/list.js +58 -0
  13. package/build/{module/commands.d.ts → commands.d.ts} +3 -3
  14. package/build/commands.js +1 -0
  15. package/build/{module/methods.d.ts → methods.d.ts} +19 -19
  16. package/build/{module/methods.js → methods.js} +5 -5
  17. package/build/{main/payloads.d.ts → payloads.d.ts} +5 -5
  18. package/build/payloads.js +1 -0
  19. package/build/{main/services → services}/common.d.ts +7 -7
  20. package/build/services/common.js +2 -0
  21. package/build/{main/services → services}/companies/entities.d.ts +2 -2
  22. package/build/services/companies/entities.js +1 -0
  23. package/build/services/companies/index.d.ts +15 -0
  24. package/build/services/companies/index.js +17 -0
  25. package/build/{module/services → services}/companies/methods.d.ts +5 -5
  26. package/build/services/companies/methods.js +1 -0
  27. package/build/{module/services → services}/contacts/entities.d.ts +2 -2
  28. package/build/services/contacts/entities.js +1 -0
  29. package/build/services/contacts/index.d.ts +15 -0
  30. package/build/services/contacts/index.js +17 -0
  31. package/build/{module/services → services}/contacts/methods.d.ts +5 -5
  32. package/build/services/contacts/methods.js +1 -0
  33. package/build/{module/services → services}/currencies/entities.d.ts +2 -2
  34. package/build/services/currencies/entities.js +1 -0
  35. package/build/{module/services → services}/deals/entities.d.ts +2 -2
  36. package/build/services/deals/entities.js +1 -0
  37. package/build/services/deals/index.d.ts +15 -0
  38. package/build/services/deals/index.js +17 -0
  39. package/build/{main/services → services}/deals/methods.d.ts +5 -5
  40. package/build/services/deals/methods.js +1 -0
  41. package/build/{module/services → services}/leads/entities.d.ts +2 -2
  42. package/build/services/leads/entities.js +1 -0
  43. package/build/services/leads/index.d.ts +15 -0
  44. package/build/services/leads/index.js +17 -0
  45. package/build/{main/services → services}/leads/methods.d.ts +5 -5
  46. package/build/services/leads/methods.js +1 -0
  47. package/build/{main/services → services}/statuses/entities.d.ts +3 -3
  48. package/build/services/statuses/entities.js +1 -0
  49. package/build/services/statuses/index.d.ts +14 -0
  50. package/build/services/statuses/index.js +19 -0
  51. package/build/{main/services → services}/statuses/methods.d.ts +5 -5
  52. package/build/services/statuses/methods.js +1 -0
  53. package/build/{module/services → services}/users/entities.d.ts +2 -2
  54. package/build/services/users/entities.js +1 -0
  55. package/build/services/users/index.d.ts +9 -0
  56. package/build/services/users/index.js +7 -0
  57. package/build/{main/services → services}/users/methods.d.ts +4 -4
  58. package/build/services/users/methods.js +1 -0
  59. package/build/utils/Diff.d.ts +1 -0
  60. package/build/utils/Diff.js +7 -0
  61. package/build/{module/utils → utils}/ExtractValue.d.ts +1 -1
  62. package/build/{main/utils/ExtractValue.d.ts → utils/ExtractValue.js} +1 -2
  63. package/build/utils/isArray.d.ts +2 -0
  64. package/build/{module/utils → utils}/isArray.js +1 -1
  65. package/package.json +43 -49
  66. package/build/main/bitrix.d.ts +0 -114
  67. package/build/main/bitrix.integration.test.d.ts +0 -0
  68. package/build/main/bitrix.integration.test.js +0 -31
  69. package/build/main/bitrix.js +0 -58
  70. package/build/main/bitrix.unit.test.d.ts +0 -1
  71. package/build/main/bitrix.unit.test.js +0 -44
  72. package/build/main/client/client.unit.test.d.ts +0 -1
  73. package/build/main/client/client.unit.test.js +0 -70
  74. package/build/main/client/hooks/addAccessToken.js +0 -13
  75. package/build/main/client/hooks/addAccessToken.unit.test.d.ts +0 -1
  76. package/build/main/client/hooks/addAccessToken.unit.test.js +0 -31
  77. package/build/main/client/index.d.ts +0 -15
  78. package/build/main/client/index.js +0 -53
  79. package/build/main/client/methods/batch.d.ts +0 -40
  80. package/build/main/client/methods/batch.js +0 -85
  81. package/build/main/client/methods/batch.unit.test.d.ts +0 -1
  82. package/build/main/client/methods/batch.unit.test.js +0 -494
  83. package/build/main/client/methods/call.d.ts +0 -17
  84. package/build/main/client/methods/call.js +0 -36
  85. package/build/main/client/methods/call.unit.test.d.ts +0 -1
  86. package/build/main/client/methods/call.unit.test.js +0 -183
  87. package/build/main/client/methods/list.d.ts +0 -30
  88. package/build/main/client/methods/list.js +0 -66
  89. package/build/main/client/methods/list.unit.test.d.ts +0 -1
  90. package/build/main/client/methods/list.unit.test.js +0 -277
  91. package/build/main/commands.d.ts +0 -10
  92. package/build/main/commands.js +0 -2
  93. package/build/main/methods.d.ts +0 -92
  94. package/build/main/methods.js +0 -41
  95. package/build/main/payloads.js +0 -2
  96. package/build/main/services/common.js +0 -2
  97. package/build/main/services/companies/entities.js +0 -2
  98. package/build/main/services/companies/index.d.ts +0 -26
  99. package/build/main/services/companies/index.integration.test.d.ts +0 -1
  100. package/build/main/services/companies/index.integration.test.js +0 -19
  101. package/build/main/services/companies/index.js +0 -10
  102. package/build/main/services/companies/index.unit.test.d.ts +0 -1
  103. package/build/main/services/companies/index.unit.test.js +0 -72
  104. package/build/main/services/companies/methods.d.ts +0 -44
  105. package/build/main/services/companies/methods.js +0 -3
  106. package/build/main/services/contacts/entities.d.ts +0 -45
  107. package/build/main/services/contacts/entities.js +0 -2
  108. package/build/main/services/contacts/index.d.ts +0 -26
  109. package/build/main/services/contacts/index.integration.test.d.ts +0 -1
  110. package/build/main/services/contacts/index.integration.test.js +0 -19
  111. package/build/main/services/contacts/index.js +0 -10
  112. package/build/main/services/contacts/index.unit.test.d.ts +0 -1
  113. package/build/main/services/contacts/index.unit.test.js +0 -72
  114. package/build/main/services/contacts/methods.d.ts +0 -44
  115. package/build/main/services/contacts/methods.js +0 -3
  116. package/build/main/services/currencies/entities.d.ts +0 -15
  117. package/build/main/services/currencies/entities.js +0 -2
  118. package/build/main/services/deals/entities.d.ts +0 -43
  119. package/build/main/services/deals/entities.js +0 -2
  120. package/build/main/services/deals/index.d.ts +0 -26
  121. package/build/main/services/deals/index.integration.test.d.ts +0 -1
  122. package/build/main/services/deals/index.integration.test.js +0 -19
  123. package/build/main/services/deals/index.js +0 -10
  124. package/build/main/services/deals/index.unit.test.d.ts +0 -1
  125. package/build/main/services/deals/index.unit.test.js +0 -72
  126. package/build/main/services/deals/methods.js +0 -3
  127. package/build/main/services/leads/entities.d.ts +0 -49
  128. package/build/main/services/leads/entities.js +0 -2
  129. package/build/main/services/leads/index.d.ts +0 -26
  130. package/build/main/services/leads/index.integration.test.d.ts +0 -1
  131. package/build/main/services/leads/index.integration.test.js +0 -19
  132. package/build/main/services/leads/index.js +0 -10
  133. package/build/main/services/leads/index.unit.test.d.ts +0 -1
  134. package/build/main/services/leads/index.unit.test.js +0 -72
  135. package/build/main/services/leads/methods.js +0 -3
  136. package/build/main/services/statuses/entities.js +0 -2
  137. package/build/main/services/statuses/index.d.ts +0 -14
  138. package/build/main/services/statuses/index.integration.test.d.ts +0 -1
  139. package/build/main/services/statuses/index.integration.test.js +0 -90
  140. package/build/main/services/statuses/index.js +0 -11
  141. package/build/main/services/statuses/index.unit.test.d.ts +0 -1
  142. package/build/main/services/statuses/index.unit.test.js +0 -60
  143. package/build/main/services/statuses/methods.js +0 -3
  144. package/build/main/services/users/entities.d.ts +0 -40
  145. package/build/main/services/users/entities.js +0 -2
  146. package/build/main/services/users/index.d.ts +0 -9
  147. package/build/main/services/users/index.integration.test.d.ts +0 -1
  148. package/build/main/services/users/index.integration.test.js +0 -33
  149. package/build/main/services/users/index.js +0 -7
  150. package/build/main/services/users/index.unit.test.d.ts +0 -1
  151. package/build/main/services/users/index.unit.test.js +0 -25
  152. package/build/main/services/users/methods.js +0 -3
  153. package/build/main/utils/Diff.d.ts +0 -1
  154. package/build/main/utils/Diff.js +0 -2
  155. package/build/main/utils/ExtractValue.js +0 -2
  156. package/build/main/utils/isArray.d.ts +0 -2
  157. package/build/main/utils/isArray.js +0 -4
  158. package/build/module/bitrix.d.ts +0 -114
  159. package/build/module/bitrix.integration.test.d.ts +0 -0
  160. package/build/module/bitrix.integration.test.js +0 -31
  161. package/build/module/bitrix.js +0 -39
  162. package/build/module/bitrix.unit.test.d.ts +0 -1
  163. package/build/module/bitrix.unit.test.js +0 -16
  164. package/build/module/client/client.unit.test.d.ts +0 -1
  165. package/build/module/client/client.unit.test.js +0 -65
  166. package/build/module/client/hooks/addAccessToken.d.ts +0 -6
  167. package/build/module/client/hooks/addAccessToken.js +0 -11
  168. package/build/module/client/hooks/addAccessToken.unit.test.d.ts +0 -1
  169. package/build/module/client/hooks/addAccessToken.unit.test.js +0 -26
  170. package/build/module/client/methods/batch.js +0 -76
  171. package/build/module/client/methods/batch.unit.test.d.ts +0 -1
  172. package/build/module/client/methods/batch.unit.test.js +0 -466
  173. package/build/module/client/methods/call.unit.test.d.ts +0 -1
  174. package/build/module/client/methods/call.unit.test.js +0 -155
  175. package/build/module/client/methods/list.js +0 -55
  176. package/build/module/client/methods/list.unit.test.d.ts +0 -1
  177. package/build/module/client/methods/list.unit.test.js +0 -252
  178. package/build/module/commands.js +0 -1
  179. package/build/module/payloads.d.ts +0 -40
  180. package/build/module/payloads.js +0 -1
  181. package/build/module/services/common.d.ts +0 -22
  182. package/build/module/services/common.js +0 -1
  183. package/build/module/services/companies/entities.d.ts +0 -54
  184. package/build/module/services/companies/entities.js +0 -1
  185. package/build/module/services/companies/index.d.ts +0 -26
  186. package/build/module/services/companies/index.integration.test.d.ts +0 -1
  187. package/build/module/services/companies/index.integration.test.js +0 -14
  188. package/build/module/services/companies/index.js +0 -8
  189. package/build/module/services/companies/index.unit.test.d.ts +0 -1
  190. package/build/module/services/companies/index.unit.test.js +0 -67
  191. package/build/module/services/companies/methods.js +0 -1
  192. package/build/module/services/contacts/entities.js +0 -1
  193. package/build/module/services/contacts/index.d.ts +0 -26
  194. package/build/module/services/contacts/index.integration.test.d.ts +0 -1
  195. package/build/module/services/contacts/index.integration.test.js +0 -14
  196. package/build/module/services/contacts/index.js +0 -8
  197. package/build/module/services/contacts/index.unit.test.d.ts +0 -1
  198. package/build/module/services/contacts/index.unit.test.js +0 -67
  199. package/build/module/services/contacts/methods.js +0 -1
  200. package/build/module/services/currencies/entities.js +0 -1
  201. package/build/module/services/deals/entities.js +0 -1
  202. package/build/module/services/deals/index.d.ts +0 -26
  203. package/build/module/services/deals/index.integration.test.d.ts +0 -1
  204. package/build/module/services/deals/index.integration.test.js +0 -14
  205. package/build/module/services/deals/index.js +0 -8
  206. package/build/module/services/deals/index.unit.test.d.ts +0 -1
  207. package/build/module/services/deals/index.unit.test.js +0 -67
  208. package/build/module/services/deals/methods.d.ts +0 -44
  209. package/build/module/services/deals/methods.js +0 -1
  210. package/build/module/services/leads/entities.js +0 -1
  211. package/build/module/services/leads/index.d.ts +0 -26
  212. package/build/module/services/leads/index.integration.test.d.ts +0 -1
  213. package/build/module/services/leads/index.integration.test.js +0 -14
  214. package/build/module/services/leads/index.js +0 -8
  215. package/build/module/services/leads/index.unit.test.d.ts +0 -1
  216. package/build/module/services/leads/index.unit.test.js +0 -67
  217. package/build/module/services/leads/methods.d.ts +0 -44
  218. package/build/module/services/leads/methods.js +0 -1
  219. package/build/module/services/statuses/entities.d.ts +0 -16
  220. package/build/module/services/statuses/entities.js +0 -1
  221. package/build/module/services/statuses/index.d.ts +0 -14
  222. package/build/module/services/statuses/index.integration.test.d.ts +0 -1
  223. package/build/module/services/statuses/index.integration.test.js +0 -85
  224. package/build/module/services/statuses/index.js +0 -9
  225. package/build/module/services/statuses/index.unit.test.d.ts +0 -1
  226. package/build/module/services/statuses/index.unit.test.js +0 -55
  227. package/build/module/services/statuses/methods.d.ts +0 -51
  228. package/build/module/services/statuses/methods.js +0 -1
  229. package/build/module/services/users/entities.js +0 -1
  230. package/build/module/services/users/index.d.ts +0 -9
  231. package/build/module/services/users/index.integration.test.d.ts +0 -1
  232. package/build/module/services/users/index.integration.test.js +0 -28
  233. package/build/module/services/users/index.js +0 -5
  234. package/build/module/services/users/index.unit.test.d.ts +0 -1
  235. package/build/module/services/users/index.unit.test.js +0 -20
  236. package/build/module/services/users/methods.d.ts +0 -17
  237. package/build/module/services/users/methods.js +0 -1
  238. package/build/module/utils/Diff.d.ts +0 -1
  239. package/build/module/utils/Diff.js +0 -1
  240. package/build/module/utils/ExtractValue.js +0 -1
  241. package/build/module/utils/isArray.d.ts +0 -2
  242. /package/build/{main/client → client}/hooks/addAccessToken.d.ts +0 -0
@@ -1,252 +0,0 @@
1
- import { Method } from '../../methods';
2
- import List, { batchToListPayload, fillWithCommands, highest } from './list';
3
- describe('Client `fillWithCommands` method', () => {
4
- it('should fill array with required amount of commands to process all entries', () => {
5
- const command = { method: Method.CRM_DEAL_LIST, params: { select: ['*'] } };
6
- const start = 0;
7
- const toProcess = 7;
8
- const entriesPerCommand = 2;
9
- expect(fillWithCommands(command, start, toProcess, entriesPerCommand)).toMatchSnapshot();
10
- });
11
- it('should properly take into account start', () => {
12
- const command = { method: Method.CRM_DEAL_LIST, params: { select: ['*'] } };
13
- const start = 2;
14
- const toProcess = 7;
15
- const entriesPerCommand = 2;
16
- expect(fillWithCommands(command, start, toProcess, entriesPerCommand)).toMatchSnapshot();
17
- });
18
- it('should override `params.start`', () => {
19
- const wrongStart = 99;
20
- const command = { method: Method.CRM_DEAL_LIST, params: { start: wrongStart } };
21
- const start = 0;
22
- const toProcess = 2;
23
- const entriesPerCommand = 1;
24
- const commands = fillWithCommands(command, start, toProcess, entriesPerCommand);
25
- expect(Object.values(commands).map((c) => c.params)).toMatchSnapshot();
26
- });
27
- });
28
- describe('Client `highest` method', () => {
29
- it('should get highest value from object', () => {
30
- expect(highest({ a: undefined })).toBe(undefined);
31
- expect(highest({ a: undefined, b: undefined })).toBe(undefined);
32
- expect(highest({ a: 1, b: undefined })).toBe(1);
33
- expect(highest({ a: undefined, b: 1 })).toBe(1);
34
- expect(highest({ a: 1, b: 2 })).toBe(2);
35
- expect(highest({ a: 2, b: 1 })).toBe(2);
36
- });
37
- it('should get highest value from array', () => {
38
- expect(highest([undefined])).toBe(undefined);
39
- expect(highest([undefined, undefined])).toBe(undefined);
40
- expect(highest([1, undefined])).toBe(1);
41
- expect(highest([undefined, 1])).toBe(1);
42
- expect(highest([1, 2])).toBe(2);
43
- expect(highest([2, 1])).toBe(2);
44
- });
45
- });
46
- describe('Client `batchToListPayload` method', () => {
47
- it('should convert batch with named payloads to a list payload', () => {
48
- const payload = {
49
- result: {
50
- result: {
51
- a: [{ ID: '1' }, { ID: '2' }],
52
- b: [{ ID: '3' }, { ID: '4' }]
53
- },
54
- result_error: { a: 'Expected error A', b: 'Expected error B' },
55
- result_total: { a: 4, b: 4 },
56
- result_next: { a: 2, b: 4 },
57
- result_time: {
58
- a: {
59
- start: 1567196891.008149,
60
- finish: 1567196891.022234,
61
- duration: 0.014085054397583008,
62
- processing: 0.013998985290527344,
63
- date_start: '2019-08-30T23:28:11+03:00',
64
- date_finish: '2019-08-30T23:28:11+03:00'
65
- },
66
- b: {
67
- start: 1567196891.022316,
68
- finish: 1567196891.03225,
69
- duration: 0.009933948516845703,
70
- processing: 0.009846210479736328,
71
- date_start: '2019-08-30T23:28:11+03:00',
72
- date_finish: '2019-08-30T23:28:11+03:00'
73
- }
74
- }
75
- },
76
- time: {
77
- start: 1567196890.959017,
78
- finish: 1567196891.223739,
79
- duration: 0.2647218704223633,
80
- processing: 0.21567082405090332,
81
- date_start: '2019-08-30T23:28:10+03:00',
82
- date_finish: '2019-08-30T23:28:11+03:00'
83
- }
84
- };
85
- expect(batchToListPayload(payload)).toMatchSnapshot();
86
- });
87
- it('should convert batch with payload of arrays to a list payload', () => {
88
- const payload = {
89
- result: {
90
- result: [
91
- [{ ID: '1' }, { ID: '2' }],
92
- [{ ID: '3' }, { ID: '4' }]
93
- ],
94
- result_error: ['Expected error 1', 'Expected error 2'],
95
- result_total: [4, 4],
96
- result_next: [2, 4],
97
- result_time: [{
98
- start: 1567196891.008149,
99
- finish: 1567196891.022234,
100
- duration: 0.014085054397583008,
101
- processing: 0.013998985290527344,
102
- date_start: '2019-08-30T23:28:11+03:00',
103
- date_finish: '2019-08-30T23:28:11+03:00'
104
- }, {
105
- start: 1567196891.022316,
106
- finish: 1567196891.03225,
107
- duration: 0.009933948516845703,
108
- processing: 0.009846210479736328,
109
- date_start: '2019-08-30T23:28:11+03:00',
110
- date_finish: '2019-08-30T23:28:11+03:00'
111
- }]
112
- },
113
- time: {
114
- start: 1567196890.959017,
115
- finish: 1567196891.223739,
116
- duration: 0.2647218704223633,
117
- processing: 0.21567082405090332,
118
- date_start: '2019-08-30T23:28:10+03:00',
119
- date_finish: '2019-08-30T23:28:11+03:00'
120
- }
121
- };
122
- expect(batchToListPayload(payload)).toMatchSnapshot();
123
- });
124
- it('should handle undefined in `result`', () => {
125
- const payload = {
126
- result: {
127
- result: [undefined, [{ ID: '1' }], undefined],
128
- result_error: [],
129
- result_total: [],
130
- result_next: [],
131
- result_time: [{
132
- start: 1567196891.008149,
133
- finish: 1567196891.022234,
134
- duration: 0.014085054397583008,
135
- processing: 0.013998985290527344,
136
- date_start: '2019-08-30T23:28:11+03:00',
137
- date_finish: '2019-08-30T23:28:11+03:00'
138
- }, {
139
- start: 1567196891.022316,
140
- finish: 1567196891.03225,
141
- duration: 0.009933948516845703,
142
- processing: 0.009846210479736328,
143
- date_start: '2019-08-30T23:28:11+03:00',
144
- date_finish: '2019-08-30T23:28:11+03:00'
145
- }]
146
- },
147
- time: {
148
- start: 1567196890.959017,
149
- finish: 1567196891.223739,
150
- duration: 0.2647218704223633,
151
- processing: 0.21567082405090332,
152
- date_start: '2019-08-30T23:28:10+03:00',
153
- date_finish: '2019-08-30T23:28:11+03:00'
154
- }
155
- };
156
- expect(batchToListPayload(payload)).toMatchSnapshot();
157
- });
158
- });
159
- describe('Client `list` method', () => {
160
- it('should make one request when entries can be fetched in one go', async () => {
161
- const callMock = jest.fn(() => Promise.resolve({ next: false }));
162
- const batchMock = jest.fn(() => Promise.resolve({}));
163
- const list = List({ call: callMock, batch: batchMock });
164
- await list(Method.CRM_DEAL_LIST, {});
165
- expect(callMock.mock.calls).toMatchSnapshot();
166
- expect(batchMock).not.toBeCalled();
167
- });
168
- it('should make multiple requests when entries can not be fetched in one go', async () => {
169
- const callMock = jest.fn(() => Promise.resolve({ next: 2, total: 120 }));
170
- const batchMock = jest.fn(() => Promise.resolve({
171
- result: {
172
- result: ['done'],
173
- result_error: [],
174
- result_next: [],
175
- result_time: [],
176
- result_total: []
177
- },
178
- time: {}
179
- }));
180
- const list = List({ call: callMock, batch: batchMock });
181
- await list(Method.CRM_DEAL_LIST, {});
182
- expect(callMock.mock.calls).toMatchSnapshot();
183
- expect(batchMock.mock.calls).toMatchSnapshot();
184
- });
185
- it('should return a first request payload when entities can be fetched in a single request', async () => {
186
- const mockPayload = { next: false, result: 'test' };
187
- const callMock = jest.fn(() => Promise.resolve(mockPayload));
188
- const batchMock = jest.fn(() => Promise.resolve({}));
189
- const list = List({ call: callMock, batch: batchMock });
190
- const payload = await list(Method.CRM_DEAL_LIST, {});
191
- expect(payload).toEqual(mockPayload);
192
- });
193
- it('should return a flatten payload when entities can not be fetched in a single request', async () => {
194
- const mockPayload = {
195
- result: {
196
- result: {
197
- a: [{ ID: '1' }, { ID: '2' }],
198
- b: [{ ID: '3' }, { ID: '4' }]
199
- },
200
- result_error: { a: 'Expected error A', b: 'Expected error B' },
201
- result_total: { a: 4, b: 4 },
202
- result_next: { a: 2, b: 4 },
203
- result_time: {
204
- a: { start: 1567196891.008149 },
205
- b: { start: 1567196891.022316 }
206
- }
207
- },
208
- time: { start: 1567196890.959017 }
209
- };
210
- const callMock = jest.fn(() => Promise.resolve({ next: 2 }));
211
- const batchMock = jest.fn(() => Promise.resolve(mockPayload));
212
- const list = List({ call: callMock, batch: batchMock });
213
- const payload = await list(Method.CRM_DEAL_LIST, {});
214
- expect(payload).toMatchSnapshot();
215
- });
216
- it('should default start to 0', async () => {
217
- const callMock = jest.fn(() => Promise.resolve({ next: 2, total: 20 }));
218
- const batchMock = jest.fn(() => Promise.resolve({
219
- result: {
220
- result: ['done'],
221
- result_error: [],
222
- result_next: [],
223
- result_time: [],
224
- result_total: []
225
- },
226
- time: {}
227
- }));
228
- const list = List({ call: callMock, batch: batchMock });
229
- await list(Method.CRM_DEAL_LIST, {});
230
- expect(callMock.mock.calls[0]).toMatchSnapshot();
231
- expect(batchMock.mock.calls[0]).toMatchSnapshot();
232
- });
233
- it('should properly take into account start', async () => {
234
- const callMock = jest.fn(() => Promise.resolve({ next: 2, total: 120 }));
235
- const batchMock = jest.fn(() => Promise.resolve({
236
- result: {
237
- result: ['done'],
238
- result_error: [],
239
- result_next: [],
240
- result_time: [],
241
- result_total: []
242
- },
243
- time: {}
244
- }));
245
- const list = List({ call: callMock, batch: batchMock });
246
- await list(Method.CRM_DEAL_LIST, { start: 27 });
247
- expect(callMock.mock.calls).toMatchSnapshot();
248
- expect(batchMock.mock.calls).toMatchSnapshot();
249
- });
250
- it.todo('should cast first request payload to the <P>');
251
- it.todo('should cast payload results to the <P>');
252
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,40 +0,0 @@
1
- export declare type PayloadTime = {
2
- readonly start: number;
3
- readonly finish: number;
4
- readonly duration: number;
5
- readonly processing: number;
6
- readonly date_start: string;
7
- readonly date_finish: string;
8
- };
9
- export declare type GetPayload<P> = {
10
- readonly result: P;
11
- readonly time: PayloadTime;
12
- };
13
- export declare type ListPayload<P> = {
14
- readonly result: readonly P[];
15
- readonly error?: string;
16
- readonly total: number;
17
- readonly next?: number;
18
- readonly time: PayloadTime;
19
- };
20
- export declare type BatchPayload<C> = {
21
- readonly result: {
22
- readonly result: {
23
- readonly [P in keyof C]?: C[P];
24
- } | ReadonlyArray<C[keyof C]>;
25
- readonly result_error: {
26
- readonly [P in keyof C]?: string;
27
- } | readonly string[];
28
- readonly result_total: {
29
- readonly [P in keyof C]?: number;
30
- } | readonly number[];
31
- readonly result_next: {
32
- readonly [P in keyof C]?: number;
33
- } | readonly number[];
34
- readonly result_time: {
35
- readonly [P in keyof C]?: PayloadTime;
36
- } | readonly PayloadTime[];
37
- };
38
- readonly time: PayloadTime;
39
- };
40
- export declare type Payload<P> = GetPayload<P> | ListPayload<P> | BatchPayload<P>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,22 +0,0 @@
1
- export declare type NumberString = string;
2
- export declare type ISODate = string;
3
- export declare type BoolString = 'Y' | 'N';
4
- export declare type GenderString = 'M' | 'F' | '';
5
- export declare type Fields = {
6
- readonly [key: string]: {
7
- readonly type: string;
8
- readonly isRequired: boolean;
9
- readonly isReadOnly: boolean;
10
- readonly isImmutable: boolean;
11
- readonly isMultiple: boolean;
12
- readonly isDynamic: boolean;
13
- readonly title: string;
14
- };
15
- };
16
- export declare type MultiField = {
17
- readonly ID: NumberString;
18
- readonly VALUE_TYPE: string;
19
- readonly VALUE: string;
20
- readonly TYPE_ID: string;
21
- };
22
- export declare type MultiFieldArray = ReadonlyArray<Pick<MultiField, 'VALUE' | 'VALUE_TYPE'>>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,54 +0,0 @@
1
- import { BoolString, ISODate, MultiField, NumberString } from '../common';
2
- export declare type Company = {
3
- readonly [key: string]: string | boolean | null | readonly MultiField[];
4
- readonly ID: NumberString;
5
- readonly COMPANY_TYPE: string | null;
6
- readonly TITLE: string | null;
7
- readonly LOGO: string | null;
8
- readonly LEAD_ID: NumberString;
9
- readonly HAS_PHONE: BoolString;
10
- readonly HAS_EMAIL: BoolString;
11
- readonly HAS_IMOL: BoolString;
12
- readonly PHONE: readonly MultiField[];
13
- readonly EMAIL: readonly MultiField[];
14
- readonly WEB: readonly MultiField[];
15
- readonly IM: readonly MultiField[];
16
- readonly ASSIGNED_BY_ID: NumberString;
17
- readonly CREATED_BY_ID: NumberString;
18
- readonly MODIFY_BY_ID: NumberString;
19
- readonly BANKING_DETAILS: string | null;
20
- readonly INDUSTRY: string | null;
21
- readonly REVENUE: string | null;
22
- readonly CURRENCY_ID: string | null;
23
- readonly EMPLOYEES: string | null;
24
- readonly COMMENTS: string | null;
25
- readonly DATE_CREATE: ISODate;
26
- readonly DATE_MODIFY: ISODate;
27
- readonly OPENED: BoolString;
28
- readonly IS_MY_COMPANY: BoolString;
29
- readonly ORIGINATOR_ID: string | null;
30
- readonly ORIGIN_ID: NumberString;
31
- readonly ORIGIN_VERSION: string | null;
32
- readonly ADDRESS: string | null;
33
- readonly ADDRESS_2: string | null;
34
- readonly ADDRESS_CITY: string | null;
35
- readonly ADDRESS_POSTAL_CODE: string | null;
36
- readonly ADDRESS_REGION: string | null;
37
- readonly ADDRESS_PROVINCE: string | null;
38
- readonly ADDRESS_COUNTRY: string | null;
39
- readonly ADDRESS_COUNTRY_CODE: string | null;
40
- readonly ADDRESS_LEGAL: string | null;
41
- readonly REG_ADDRESS: string | null;
42
- readonly REG_ADDRESS_2: string | null;
43
- readonly REG_ADDRESS_CITY: string | null;
44
- readonly REG_ADDRESS_POSTAL_CODE: string | null;
45
- readonly REG_ADDRESS_REGION: string | null;
46
- readonly REG_ADDRESS_PROVINCE: string | null;
47
- readonly REG_ADDRESS_COUNTRY: string | null;
48
- readonly REG_ADDRESS_COUNTRY_CODE: string | null;
49
- readonly UTM_SOURCE: string | null;
50
- readonly UTM_MEDIUM: string | null;
51
- readonly UTM_CAMPAIGN: string | null;
52
- readonly UTM_CONTENT: string | null;
53
- readonly UTM_TERM: string | null;
54
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,26 +0,0 @@
1
- import { Call } from '../../client/methods/call';
2
- import { List } from '../../client/methods/list';
3
- import { Method, MethodParams } from '../../methods';
4
- declare type Dependencies = {
5
- readonly call: Call;
6
- readonly list: List;
7
- };
8
- declare const _default: ({ call, list }: Dependencies) => {
9
- fields: () => Promise<import("../../payloads").GetPayload<import("../common").Fields>>;
10
- create: <D extends {
11
- readonly fields: Partial<import("./entities").Company>;
12
- readonly params?: {
13
- readonly REGISTER_SONET_EVENT: "Y" | "N";
14
- } | undefined;
15
- }>(fields: D["fields"], params?: D["params"] | undefined) => Promise<import("../../payloads").GetPayload<number>>;
16
- get: (id: string) => Promise<import("../../payloads").GetPayload<import("./entities").Company>>;
17
- list: (params?: MethodParams<Method.CRM_COMPANY_LIST>) => Promise<import("../../payloads").ListPayload<import("./entities").Company>>;
18
- update: <D_1 extends {
19
- readonly id: string;
20
- readonly fields: Record<string, unknown>;
21
- readonly params?: {
22
- readonly REGISTER_SONET_EVENT: "Y" | "N";
23
- } | undefined;
24
- }>(id: string, fields: D_1["fields"], params?: D_1["params"] | undefined) => Promise<import("../../payloads").GetPayload<boolean>>;
25
- };
26
- export default _default;
@@ -1,14 +0,0 @@
1
- import Bitrix from './../../bitrix';
2
- const WEBHOOK_URL = process.env['WEBHOOK_URL'];
3
- if (!WEBHOOK_URL) {
4
- throw Error('Integration tests require environmental variable `WEBHOOK_URL` to be set');
5
- }
6
- const { companies } = Bitrix(WEBHOOK_URL);
7
- describe('Companies', () => {
8
- describe('fields', () => {
9
- it('should get all fields', async () => {
10
- const { result } = await companies.fields();
11
- expect(result).toMatchSnapshot();
12
- });
13
- });
14
- });
@@ -1,8 +0,0 @@
1
- import { Method } from '../../methods';
2
- export default ({ call, list }) => ({
3
- fields: () => call(Method.CRM_COMPANY_FIELDS, {}),
4
- create: (fields, params) => call(Method.CRM_COMPANY_ADD, { fields, params }),
5
- get: (id) => call(Method.CRM_COMPANY_GET, { id }),
6
- list: (params = {}) => list(Method.CRM_COMPANY_LIST, params),
7
- update: (id, fields, params) => call(Method.CRM_COMPANY_UPDATE, { id, fields, params })
8
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,67 +0,0 @@
1
- import Companies from '.';
2
- const mockCall = jest.fn(() => Promise.resolve());
3
- const mockList = jest.fn(() => Promise.resolve());
4
- const companies = Companies({ call: mockCall, list: mockList });
5
- const ID = '77';
6
- describe('Companies', () => {
7
- beforeEach(() => {
8
- mockCall.mockClear();
9
- mockList.mockClear();
10
- });
11
- it('should expose API methods', () => {
12
- expect(companies).toMatchSnapshot();
13
- });
14
- describe('`create`', () => {
15
- it('should invoke `call`', async () => {
16
- await companies.create({
17
- COMMENTS: 'Some comment'
18
- }, {
19
- REGISTER_SONET_EVENT: 'Y'
20
- });
21
- expect(mockCall.mock.calls).toMatchSnapshot();
22
- });
23
- it('should work without optional params', async () => {
24
- await companies.create({
25
- COMMENTS: 'Some comment'
26
- });
27
- expect(mockCall.mock.calls).toMatchSnapshot();
28
- });
29
- });
30
- describe('`get`', () => {
31
- it('should invoke `call`', async () => {
32
- await companies.get(ID);
33
- expect(mockCall.mock.calls).toMatchSnapshot();
34
- });
35
- });
36
- describe('`list`', () => {
37
- it('should invoke `list`', async () => {
38
- await companies.list({
39
- start: 0,
40
- order: { COMMENTS: 'ASC' },
41
- filter: { '>PROBABILITY': 50 },
42
- select: ['*', 'UF_*']
43
- });
44
- expect(mockList.mock.calls).toMatchSnapshot();
45
- });
46
- it('should work without optional params', async () => {
47
- await companies.list();
48
- expect(mockList.mock.calls).toMatchSnapshot();
49
- });
50
- });
51
- describe('`update`', () => {
52
- it('should invoke `call`', async () => {
53
- await companies.update(ID, {
54
- COMMENTS: 'Some comment'
55
- }, {
56
- REGISTER_SONET_EVENT: 'Y'
57
- });
58
- expect(mockCall.mock.calls).toMatchSnapshot();
59
- });
60
- it('should work without optional params', async () => {
61
- await companies.update(ID, {
62
- COMMENTS: 'Some comment'
63
- });
64
- expect(mockCall.mock.calls).toMatchSnapshot();
65
- });
66
- });
67
- });
@@ -1 +0,0 @@
1
- import { Method } from '../../methods';
@@ -1 +0,0 @@
1
- export {};
@@ -1,26 +0,0 @@
1
- import { Call } from '../../client/methods/call';
2
- import { List } from '../../client/methods/list';
3
- import { Method, MethodParams } from '../../methods';
4
- declare type Dependencies = {
5
- readonly call: Call;
6
- readonly list: List;
7
- };
8
- declare const _default: ({ call, list }: Dependencies) => {
9
- fields: () => Promise<import("../../payloads").GetPayload<import("../common").Fields>>;
10
- create: <D extends {
11
- readonly fields: Partial<import("./entities").Contact>;
12
- readonly params?: {
13
- readonly REGISTER_SONET_EVENT: "Y" | "N";
14
- } | undefined;
15
- }>(fields: D["fields"], params?: D["params"] | undefined) => Promise<import("../../payloads").GetPayload<number>>;
16
- get: (id: string) => Promise<import("../../payloads").GetPayload<import("./entities").Contact>>;
17
- list: (params?: MethodParams<Method.CRM_CONTACT_LIST>) => Promise<import("../../payloads").ListPayload<import("./entities").Contact>>;
18
- update: <D_1 extends {
19
- readonly id: string;
20
- readonly fields: Record<string, unknown>;
21
- readonly params?: {
22
- readonly REGISTER_SONET_EVENT: "Y" | "N";
23
- } | undefined;
24
- }>(id: string, fields: D_1["fields"], params?: D_1["params"] | undefined) => Promise<import("../../payloads").GetPayload<boolean>>;
25
- };
26
- export default _default;
@@ -1,14 +0,0 @@
1
- import Bitrix from './../../bitrix';
2
- const WEBHOOK_URL = process.env['WEBHOOK_URL'];
3
- if (!WEBHOOK_URL) {
4
- throw Error('Integration tests require environmental variable `WEBHOOK_URL` to be set');
5
- }
6
- const { contacts } = Bitrix(WEBHOOK_URL);
7
- describe('Contacts', () => {
8
- describe('fields', () => {
9
- it('should get all fields', async () => {
10
- const { result } = await contacts.fields();
11
- expect(result).toMatchSnapshot();
12
- });
13
- });
14
- });
@@ -1,8 +0,0 @@
1
- import { Method } from '../../methods';
2
- export default ({ call, list }) => ({
3
- fields: () => call(Method.CRM_CONTACT_FIELDS, {}),
4
- create: (fields, params) => call(Method.CRM_CONTACT_ADD, { fields, params }),
5
- get: (id) => call(Method.CRM_CONTACT_GET, { id }),
6
- list: (params = {}) => list(Method.CRM_CONTACT_LIST, params),
7
- update: (id, fields, params) => call(Method.CRM_CONTACT_UPDATE, { id, fields, params })
8
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,67 +0,0 @@
1
- import Contacts from '.';
2
- const mockCall = jest.fn(() => Promise.resolve());
3
- const mockList = jest.fn(() => Promise.resolve());
4
- const contacts = Contacts({ call: mockCall, list: mockList });
5
- const ID = '77';
6
- describe('Contacts', () => {
7
- beforeEach(() => {
8
- mockCall.mockClear();
9
- mockList.mockClear();
10
- });
11
- it('should expose API methods', () => {
12
- expect(contacts).toMatchSnapshot();
13
- });
14
- describe('`create`', () => {
15
- it('should invoke `call`', async () => {
16
- await contacts.create({
17
- COMMENTS: 'Some comment'
18
- }, {
19
- REGISTER_SONET_EVENT: 'Y'
20
- });
21
- expect(mockCall.mock.calls).toMatchSnapshot();
22
- });
23
- it('should work without optional params', async () => {
24
- await contacts.create({
25
- COMMENTS: 'Some comment'
26
- });
27
- expect(mockCall.mock.calls).toMatchSnapshot();
28
- });
29
- });
30
- describe('`get`', () => {
31
- it('should invoke `call`', async () => {
32
- await contacts.get(ID);
33
- expect(mockCall.mock.calls).toMatchSnapshot();
34
- });
35
- });
36
- describe('`list`', () => {
37
- it('should invoke `list`', async () => {
38
- await contacts.list({
39
- start: 0,
40
- order: { COMMENTS: 'ASC' },
41
- filter: { '>PROBABILITY': 50 },
42
- select: ['*', 'UF_*']
43
- });
44
- expect(mockList.mock.calls).toMatchSnapshot();
45
- });
46
- it('should work without optional params', async () => {
47
- await contacts.list();
48
- expect(mockList.mock.calls).toMatchSnapshot();
49
- });
50
- });
51
- describe('`update`', () => {
52
- it('should invoke `call`', async () => {
53
- await contacts.update(ID, {
54
- COMMENTS: 'Some comment'
55
- }, {
56
- REGISTER_SONET_EVENT: 'Y'
57
- });
58
- expect(mockCall.mock.calls).toMatchSnapshot();
59
- });
60
- it('should work without optional params', async () => {
61
- await contacts.update(ID, {
62
- COMMENTS: 'Some comment'
63
- });
64
- expect(mockCall.mock.calls).toMatchSnapshot();
65
- });
66
- });
67
- });
@@ -1 +0,0 @@
1
- import { Method } from '../../methods';
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};