@chift/chift-nodejs 0.0.1

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 (146) hide show
  1. package/.eslintcache +1 -0
  2. package/.eslintignore +1 -0
  3. package/.eslintrc.json +25 -0
  4. package/.github/workflows/ci.yml +73 -0
  5. package/.husky/pre-commit +4 -0
  6. package/.prettierignore +1 -0
  7. package/.prettierrc.json +7 -0
  8. package/CHANGELOG.md +4 -0
  9. package/LICENSE +201 -0
  10. package/README.md +48 -0
  11. package/coverage/clover.xml +1645 -0
  12. package/coverage/coverage-final.json +19 -0
  13. package/coverage/lcov-report/base.css +224 -0
  14. package/coverage/lcov-report/block-navigation.js +87 -0
  15. package/coverage/lcov-report/favicon.png +0 -0
  16. package/coverage/lcov-report/index.html +146 -0
  17. package/coverage/lcov-report/prettify.css +1 -0
  18. package/coverage/lcov-report/prettify.js +2 -0
  19. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  20. package/coverage/lcov-report/sorter.js +196 -0
  21. package/coverage/lcov-report/src/helpers/index.html +131 -0
  22. package/coverage/lcov-report/src/helpers/openapi.ts.html +151 -0
  23. package/coverage/lcov-report/src/helpers/settings.ts.html +94 -0
  24. package/coverage/lcov-report/src/index.html +116 -0
  25. package/coverage/lcov-report/src/index.ts.html +88 -0
  26. package/coverage/lcov-report/src/modules/accounting.ts.html +1156 -0
  27. package/coverage/lcov-report/src/modules/api.ts.html +190 -0
  28. package/coverage/lcov-report/src/modules/consumer.ts.html +616 -0
  29. package/coverage/lcov-report/src/modules/consumers.ts.html +331 -0
  30. package/coverage/lcov-report/src/modules/custom.ts.html +193 -0
  31. package/coverage/lcov-report/src/modules/datastores.ts.html +142 -0
  32. package/coverage/lcov-report/src/modules/ecommerce.ts.html +331 -0
  33. package/coverage/lcov-report/src/modules/flow.ts.html +589 -0
  34. package/coverage/lcov-report/src/modules/index.html +326 -0
  35. package/coverage/lcov-report/src/modules/integrations.ts.html +151 -0
  36. package/coverage/lcov-report/src/modules/internalApi.ts.html +586 -0
  37. package/coverage/lcov-report/src/modules/invoicing.ts.html +391 -0
  38. package/coverage/lcov-report/src/modules/pos.ts.html +421 -0
  39. package/coverage/lcov-report/src/modules/sync.ts.html +316 -0
  40. package/coverage/lcov-report/src/modules/syncs.ts.html +169 -0
  41. package/coverage/lcov-report/src/modules/webhooks.ts.html +343 -0
  42. package/coverage/lcov.info +1976 -0
  43. package/dist/src/helpers/openapi.d.ts +3 -0
  44. package/dist/src/helpers/openapi.js +18 -0
  45. package/dist/src/helpers/settings.d.ts +4 -0
  46. package/dist/src/helpers/settings.js +5 -0
  47. package/dist/src/index.d.ts +1 -0
  48. package/dist/src/index.js +17 -0
  49. package/dist/src/modules/accounting.d.ts +48 -0
  50. package/dist/src/modules/accounting.js +255 -0
  51. package/dist/src/modules/api.d.ts +39333 -0
  52. package/dist/src/modules/api.js +36 -0
  53. package/dist/src/modules/consumer.d.ts +2588 -0
  54. package/dist/src/modules/consumer.js +118 -0
  55. package/dist/src/modules/consumers.d.ts +13034 -0
  56. package/dist/src/modules/consumers.js +51 -0
  57. package/dist/src/modules/custom.d.ts +8 -0
  58. package/dist/src/modules/custom.js +36 -0
  59. package/dist/src/modules/datastores.d.ts +18 -0
  60. package/dist/src/modules/datastores.js +23 -0
  61. package/dist/src/modules/ecommerce.d.ts +16 -0
  62. package/dist/src/modules/ecommerce.js +69 -0
  63. package/dist/src/modules/flow.d.ts +15 -0
  64. package/dist/src/modules/flow.js +156 -0
  65. package/dist/src/modules/integrations.d.ts +14 -0
  66. package/dist/src/modules/integrations.js +23 -0
  67. package/dist/src/modules/internalApi.d.ts +22 -0
  68. package/dist/src/modules/internalApi.js +160 -0
  69. package/dist/src/modules/invoicing.d.ts +18 -0
  70. package/dist/src/modules/invoicing.js +90 -0
  71. package/dist/src/modules/pos.d.ts +20 -0
  72. package/dist/src/modules/pos.js +80 -0
  73. package/dist/src/modules/sync.d.ts +10494 -0
  74. package/dist/src/modules/sync.js +75 -0
  75. package/dist/src/modules/syncs.d.ts +26200 -0
  76. package/dist/src/modules/syncs.js +29 -0
  77. package/dist/src/modules/webhooks.d.ts +55 -0
  78. package/dist/src/modules/webhooks.js +53 -0
  79. package/dist/src/types/api.d.ts +28 -0
  80. package/dist/src/types/api.js +2 -0
  81. package/dist/src/types/consumers.d.ts +8 -0
  82. package/dist/src/types/consumers.js +2 -0
  83. package/dist/src/types/public-api/mappings.d.ts +21 -0
  84. package/dist/src/types/public-api/mappings.js +2 -0
  85. package/dist/src/types/sync.d.ts +20 -0
  86. package/dist/src/types/sync.js +2 -0
  87. package/dist/test/modules/accounting.test.d.ts +1 -0
  88. package/dist/test/modules/accounting.test.js +453 -0
  89. package/dist/test/modules/consumer.test.d.ts +1 -0
  90. package/dist/test/modules/consumer.test.js +89 -0
  91. package/dist/test/modules/consumers.test.d.ts +1 -0
  92. package/dist/test/modules/consumers.test.js +109 -0
  93. package/dist/test/modules/ecommerce.test.d.ts +1 -0
  94. package/dist/test/modules/ecommerce.test.js +193 -0
  95. package/dist/test/modules/flow.test.d.ts +1 -0
  96. package/dist/test/modules/flow.test.js +69 -0
  97. package/dist/test/modules/integrations.test.d.ts +1 -0
  98. package/dist/test/modules/integrations.test.js +54 -0
  99. package/dist/test/modules/invoicing.test.d.ts +1 -0
  100. package/dist/test/modules/invoicing.test.js +108 -0
  101. package/dist/test/modules/pos.test.d.ts +1 -0
  102. package/dist/test/modules/pos.test.js +164 -0
  103. package/dist/test/modules/sync.test.d.ts +1 -0
  104. package/dist/test/modules/sync.test.js +81 -0
  105. package/dist/test/modules/syncs.test.d.ts +1 -0
  106. package/dist/test/modules/syncs.test.js +53 -0
  107. package/dist/test/modules/webhooks.test.d.ts +1 -0
  108. package/dist/test/modules/webhooks.test.js +120 -0
  109. package/jest.config.ts +195 -0
  110. package/package.json +47 -0
  111. package/src/helpers/openapi.ts +22 -0
  112. package/src/helpers/settings.ts +3 -0
  113. package/src/index.ts +1 -0
  114. package/src/modules/accounting.ts +357 -0
  115. package/src/modules/api.ts +35 -0
  116. package/src/modules/consumer.ts +177 -0
  117. package/src/modules/consumers.ts +82 -0
  118. package/src/modules/custom.ts +36 -0
  119. package/src/modules/datastores.ts +19 -0
  120. package/src/modules/ecommerce.ts +82 -0
  121. package/src/modules/flow.ts +168 -0
  122. package/src/modules/integrations.ts +22 -0
  123. package/src/modules/internalApi.ts +162 -0
  124. package/src/modules/invoicing.ts +106 -0
  125. package/src/modules/pos.ts +112 -0
  126. package/src/modules/sync.ts +77 -0
  127. package/src/modules/syncs.ts +28 -0
  128. package/src/modules/webhooks.ts +86 -0
  129. package/src/types/api.ts +35 -0
  130. package/src/types/consumers.ts +9 -0
  131. package/src/types/public-api/mappings.ts +21 -0
  132. package/src/types/public-api/schema.d.ts +9436 -0
  133. package/src/types/sync.ts +23 -0
  134. package/test/data/accounting_invoice.pdf +0 -0
  135. package/test/modules/accounting.test.ts +483 -0
  136. package/test/modules/consumer.test.ts +68 -0
  137. package/test/modules/consumers.test.ts +83 -0
  138. package/test/modules/ecommerce.test.ts +177 -0
  139. package/test/modules/integrations.test.ts +22 -0
  140. package/test/modules/invoicing.test.ts +88 -0
  141. package/test/modules/pos.test.ts +145 -0
  142. package/test/modules/sync.test.ts +60 -0
  143. package/test/modules/syncs.test.ts +23 -0
  144. package/test/modules/webhooks.test.ts +92 -0
  145. package/test/set_envs.sh +14 -0
  146. package/tsconfig.json +107 -0
@@ -0,0 +1,23 @@
1
+ export interface TriggerType {
2
+ type: 'timer' | 'event';
3
+ data?: any;
4
+ }
5
+
6
+ export interface ExecutionType {
7
+ type: 'code' | 'module';
8
+ data?: any;
9
+ }
10
+
11
+ export interface ContextType {
12
+ name: string;
13
+ description?: string;
14
+ trigger: TriggerType;
15
+ execution: ExecutionType;
16
+ config?: any;
17
+ }
18
+
19
+ export interface SimpleResponseModel {
20
+ status: string;
21
+ message: string;
22
+ data?: any;
23
+ }
Binary file
@@ -0,0 +1,483 @@
1
+ import { beforeAll, expect, test } from '@jest/globals';
2
+ import * as chift from '../../src/index';
3
+ import * as dotenv from 'dotenv';
4
+ import { components } from '../../src/types/public-api/schema';
5
+ import fs from 'fs';
6
+
7
+ dotenv.config();
8
+
9
+ const client = new chift.API({
10
+ baseUrl: process.env.CHIFT_BASE_URL,
11
+ clientId: process.env.CHIFT_CLIENT_ID as string,
12
+ clientSecret: process.env.CHIFT_CLIENT_SECRET as string,
13
+ accountId: process.env.CHIFT_ACCOUNT_ID as string,
14
+ });
15
+
16
+ const consumerId = process.env.CHIFT_ODOO_CONSUMER_ID as string;
17
+
18
+ let consumer: any;
19
+ beforeAll(async () => {
20
+ consumer = await client.Consumers.getConsumerById(consumerId);
21
+ });
22
+
23
+ let analyticPlans: components['schemas']['AnalyticPlanItem'][];
24
+ test('getAnalyticPlans', async () => {
25
+ analyticPlans = await consumer.accounting.getAnalyticPlans();
26
+ expect(analyticPlans).toBeInstanceOf(Array);
27
+ expect(analyticPlans.length).toBeGreaterThan(0);
28
+ expect(analyticPlans[0]).toHaveProperty('id', expect.any(String));
29
+ expect(analyticPlans[0]).toHaveProperty('name', expect.any(String));
30
+ expect(analyticPlans[0]).toHaveProperty('active', expect.any(Boolean));
31
+ });
32
+
33
+ let journals: components['schemas']['Journal'][];
34
+ test('getJournals', async () => {
35
+ journals = await consumer.accounting.getJournals();
36
+ expect(journals).toBeInstanceOf(Array);
37
+ expect(journals.length).toBeGreaterThan(0);
38
+ expect(journals[0]).toHaveProperty('id', expect.any(String));
39
+ expect(journals[0]).toHaveProperty('name', expect.any(String));
40
+ expect(journals[0]).toHaveProperty('journal_type', expect.any(String));
41
+ });
42
+
43
+ test('createClient', async () => {
44
+ const body: components['schemas']['ClientItemIn'] = {
45
+ external_reference: 'sdk test',
46
+ name: 'John Doe',
47
+ currency: 'EUR',
48
+ active: false,
49
+ addresses: [
50
+ {
51
+ address_type: 'main',
52
+ street: 'Main Street',
53
+ city: 'Brussels',
54
+ postal_code: '1000',
55
+ country: 'BE',
56
+ },
57
+ ],
58
+ };
59
+ const client = await consumer.accounting.createClient(body);
60
+ expect(client).toBeTruthy();
61
+ expect(client).toHaveProperty('name', 'John Doe');
62
+ });
63
+
64
+ let clients: components['schemas']['ClientItemOut'][];
65
+ test('getClients', async () => {
66
+ clients = await consumer.accounting.getClients();
67
+ expect(clients).toBeInstanceOf(Array);
68
+ expect(clients.length).toBeGreaterThan(0);
69
+ expect(clients[0]).toHaveProperty('id', expect.any(String));
70
+ });
71
+
72
+ test('getClient', async () => {
73
+ const client = await consumer.accounting.getClient(clients[0].id);
74
+ expect(client).toBeTruthy();
75
+ expect(client).toHaveProperty('external_reference');
76
+ expect(client).toHaveProperty('first_name');
77
+ expect(client).toHaveProperty('last_name');
78
+ expect(client).toHaveProperty('name');
79
+ expect(client).toHaveProperty('function');
80
+ expect(client).toHaveProperty('is_company');
81
+ expect(client).toHaveProperty('company_id');
82
+ expect(client).toHaveProperty('phone');
83
+ expect(client).toHaveProperty('mobile');
84
+ expect(client).toHaveProperty('email');
85
+ expect(client).toHaveProperty('language');
86
+ expect(client).toHaveProperty('internal_notes');
87
+ expect(client).toHaveProperty('website');
88
+ expect(client).toHaveProperty('vat');
89
+ expect(client).toHaveProperty('iban');
90
+ expect(client).toHaveProperty('bank_account');
91
+ expect(client).toHaveProperty('currency');
92
+ expect(client).toHaveProperty('active', expect.any(Boolean));
93
+ expect(client).toHaveProperty('addresses', expect.any(Array));
94
+ });
95
+
96
+ test('updateClient', async () => {
97
+ const client = clients.find((client) => client.external_reference === 'sdk test');
98
+ const updatedClient = await consumer.accounting.updateClient(client?.id, {
99
+ name: 'John Updated Doe',
100
+ });
101
+ expect(updatedClient).toBeTruthy();
102
+ expect(updatedClient).toHaveProperty('name', 'John Updated Doe');
103
+ });
104
+
105
+ test('createSupplier', async () => {
106
+ const body: components['schemas']['SupplierItemIn'] = {
107
+ external_reference: 'sdk test',
108
+ name: 'Jane Doe',
109
+ currency: 'EUR',
110
+ active: false,
111
+ addresses: [
112
+ {
113
+ address_type: 'main',
114
+ street: 'Main Street',
115
+ city: 'Brussels',
116
+ postal_code: '1000',
117
+ country: 'BE',
118
+ },
119
+ ],
120
+ };
121
+ const supplier = await consumer.accounting.createSupplier(body);
122
+ expect(supplier).toBeTruthy();
123
+ expect(supplier).toHaveProperty('name', 'Jane Doe');
124
+ });
125
+
126
+ let suppliers: components['schemas']['SupplierItemOut'][];
127
+ test('getSuppliers', async () => {
128
+ suppliers = await consumer.accounting.getSuppliers();
129
+ expect(suppliers).toBeInstanceOf(Array);
130
+ expect(suppliers.length).toBeGreaterThan(0);
131
+ });
132
+
133
+ test('getSupplier', async () => {
134
+ const supplier = await consumer.accounting.getSupplier(suppliers[0].id);
135
+ expect(supplier).toBeTruthy();
136
+ expect(supplier).toHaveProperty('external_reference');
137
+ expect(supplier).toHaveProperty('first_name');
138
+ expect(supplier).toHaveProperty('last_name');
139
+ expect(supplier).toHaveProperty('name');
140
+ expect(supplier).toHaveProperty('function');
141
+ expect(supplier).toHaveProperty('is_company');
142
+ expect(supplier).toHaveProperty('company_id');
143
+ expect(supplier).toHaveProperty('phone');
144
+ expect(supplier).toHaveProperty('mobile');
145
+ expect(supplier).toHaveProperty('email');
146
+ expect(supplier).toHaveProperty('language');
147
+ expect(supplier).toHaveProperty('internal_notes');
148
+ expect(supplier).toHaveProperty('website');
149
+ expect(supplier).toHaveProperty('vat');
150
+ expect(supplier).toHaveProperty('iban');
151
+ expect(supplier).toHaveProperty('bank_account');
152
+ expect(supplier).toHaveProperty('currency');
153
+ expect(supplier).toHaveProperty('active', expect.any(Boolean));
154
+ expect(supplier).toHaveProperty('addresses', expect.any(Array));
155
+ });
156
+
157
+ test('updateSupplier', async () => {
158
+ const supplier = suppliers.find((supplier) => supplier.external_reference === 'sdk test');
159
+ const updatedSupplier = await consumer.accounting.updateSupplier(supplier?.id, {
160
+ name: 'Jane Updated Doe',
161
+ });
162
+ expect(updatedSupplier).toBeTruthy();
163
+ expect(updatedSupplier).toHaveProperty('name', 'Jane Updated Doe');
164
+ });
165
+
166
+ test('createInvoice', async () => {
167
+ const body: components['schemas']['InvoiceItemInMonoAnalyticPlan'] = {
168
+ invoice_type: 'customer_invoice',
169
+ invoice_date: '2022-12-01',
170
+ due_date: '2022-12-31',
171
+ currency: 'EUR',
172
+ untaxed_amount: 100,
173
+ tax_amount: 21,
174
+ total: 121,
175
+ partner_id: clients[0]?.id as string,
176
+ journal_id: journals[0].id,
177
+ lines: [
178
+ {
179
+ description: 'Test',
180
+ unit_price: 100,
181
+ quantity: 1,
182
+ untaxed_amount: 100,
183
+ tax_rate: 21,
184
+ tax_amount: 21,
185
+ total: 121,
186
+ account_number: '700000',
187
+ tax_code: '1',
188
+ },
189
+ ],
190
+ };
191
+ const invoice = await consumer.accounting.createInvoice(body);
192
+ expect(invoice).toBeTruthy();
193
+ expect(invoice).toHaveProperty('total', 121);
194
+ });
195
+
196
+ let invoices: components['schemas']['InvoiceItemOutMonoAnalyticPlan'][];
197
+ test('getInvoicesByType', async () => {
198
+ invoices = await consumer.accounting.getInvoicesByType('customer_invoice', {
199
+ date_from: '2022-12-01',
200
+ date_to: '2022-12-31',
201
+ });
202
+ expect(invoices).toBeInstanceOf(Array);
203
+ expect(invoices.length).toBeGreaterThan(0);
204
+ expect(invoices[0]).toHaveProperty('id', expect.any(String));
205
+ });
206
+
207
+ test('getInvoicesByTypeWithMultiplePlans', async () => {
208
+ const invoicesWithMultiplePlans = await consumer.accounting.getInvoicesByTypeWithMultiplePlans(
209
+ 'customer_invoice',
210
+ {
211
+ date_from: '2022-12-01',
212
+ date_to: '2022-12-31',
213
+ }
214
+ );
215
+ expect(invoicesWithMultiplePlans).toBeInstanceOf(Array);
216
+ expect(invoicesWithMultiplePlans.length).toBeGreaterThan(0);
217
+ expect(invoicesWithMultiplePlans[0]).toHaveProperty('id', expect.any(String));
218
+ });
219
+
220
+ test('getInvoice', async () => {
221
+ const invoice = await consumer.accounting.getInvoice(invoices[0].id, {
222
+ include_payments: true,
223
+ });
224
+ expect(invoice).toBeTruthy();
225
+ expect(invoice).toHaveProperty('id', invoices[0].id);
226
+ expect(invoices[0]).toHaveProperty('invoice_type', expect.any(String));
227
+ expect(invoices[0]).toHaveProperty('invoice_number');
228
+ expect(invoices[0]).toHaveProperty('partner_id', expect.any(String));
229
+ expect(invoices[0]).toHaveProperty('invoice_date', expect.any(String));
230
+ expect(invoices[0]).toHaveProperty('due_date', expect.any(String));
231
+ expect(invoices[0]).toHaveProperty('currency', expect.any(String));
232
+ expect(invoices[0]).toHaveProperty('untaxed_amount', expect.any(Number));
233
+ expect(invoices[0]).toHaveProperty('tax_amount', expect.any(Number));
234
+ expect(invoices[0]).toHaveProperty('total', expect.any(Number));
235
+ expect(invoices[0]).toHaveProperty('reference');
236
+ expect(invoices[0]).toHaveProperty('payment_communication');
237
+ expect(invoices[0]).toHaveProperty('customer_memo');
238
+ expect(invoices[0]).toHaveProperty('id');
239
+ expect(invoices[0]).toHaveProperty('journal_id', expect.any(String));
240
+ expect(invoices[0]).toHaveProperty('payments');
241
+ expect(invoices[0]).toHaveProperty('status');
242
+ expect(invoices[0]).toHaveProperty('lines', expect.any(Array));
243
+ });
244
+
245
+ test('createInvoiceWithMultiplePlans', async () => {
246
+ const body: components['schemas']['InvoiceItemInMonoAnalyticPlan'] = {
247
+ invoice_type: 'customer_invoice',
248
+ invoice_date: '2022-12-01',
249
+ due_date: '2022-12-31',
250
+ currency: 'EUR',
251
+ untaxed_amount: 100,
252
+ tax_amount: 21,
253
+ total: 121,
254
+ partner_id: clients[0]?.id as string,
255
+ journal_id: journals[0].id,
256
+ lines: [
257
+ {
258
+ description: 'Test',
259
+ unit_price: 100,
260
+ quantity: 1,
261
+ untaxed_amount: 100,
262
+ tax_rate: 21,
263
+ tax_amount: 21,
264
+ total: 121,
265
+ account_number: '700000',
266
+ tax_code: '1',
267
+ },
268
+ ],
269
+ };
270
+ const invoice = await consumer.accounting.createInvoiceWithMultiplePlans(body);
271
+ expect(invoice).toBeTruthy();
272
+ });
273
+
274
+ test('getInvoiceWithMultiplePlans', async () => {
275
+ const invoice = await consumer.accounting.getInvoiceWithMultiplePlans(invoices[0].id, {
276
+ include_payments: true,
277
+ });
278
+ expect(invoice).toBeTruthy();
279
+ });
280
+
281
+ test('createAnalyticAccount', async () => {
282
+ const body: components['schemas']['AnalyticAccountItemIn'] = {
283
+ active: false,
284
+ code: '4000',
285
+ name: 'sdk test',
286
+ currency: 'EUR',
287
+ };
288
+ const analyticAccount = await consumer.accounting.createAnalyticAccount(body);
289
+ expect(analyticAccount).toBeTruthy();
290
+ expect(analyticAccount).toHaveProperty('name', 'sdk test');
291
+ });
292
+
293
+ let analyticAccounts: components['schemas']['AnalyticAccountItemOut'][];
294
+ test('getAnalyticAccounts', async () => {
295
+ analyticAccounts = await consumer.accounting.getAnalyticAccounts();
296
+ expect(analyticAccounts).toBeInstanceOf(Array);
297
+ expect(analyticAccounts.length).toBeGreaterThan(0);
298
+ expect(analyticAccounts[0]).toHaveProperty('active', expect.any(Boolean));
299
+ expect(analyticAccounts[0]).toHaveProperty('code', expect.any(String));
300
+ expect(analyticAccounts[0]).toHaveProperty('name', expect.any(String));
301
+ expect(analyticAccounts[0]).toHaveProperty('currency', expect.any(String));
302
+ expect(analyticAccounts[0]).toHaveProperty('id', expect.any(String));
303
+ expect(analyticAccounts[0]).toHaveProperty('balance', expect.any(Number));
304
+ expect(analyticAccounts[0]).toHaveProperty('debit', expect.any(Number));
305
+ expect(analyticAccounts[0]).toHaveProperty('credit', expect.any(Number));
306
+ });
307
+
308
+ test('createAnalyticAccountWithMultiplePlans', async () => {
309
+ const analyticAccount = await consumer.accounting.createAnalyticAccountWithMultiplePlans(
310
+ analyticPlans[0].id,
311
+ {
312
+ code: '4000',
313
+ name: 'sdk test',
314
+ currency: 'EUR',
315
+ }
316
+ );
317
+ expect(analyticAccount).toBeTruthy();
318
+ });
319
+
320
+ test('getAnalyticAccount', async () => {
321
+ const analyticAccount = await consumer.accounting.getAnalyticAccount(analyticAccounts[0].id);
322
+ expect(analyticAccount).toBeTruthy();
323
+ });
324
+
325
+ test('updateAnalyticAccount', async () => {
326
+ const testAnalyticAccount = analyticAccounts.find((account) => account.name === 'sdk test');
327
+ const analyticAccount = await consumer.accounting.updateAnalyticAccount(
328
+ testAnalyticAccount?.id,
329
+ { name: 'test sdk update' }
330
+ );
331
+ expect(analyticAccount).toBeTruthy();
332
+ expect(analyticAccount).toHaveProperty('name', 'test sdk update');
333
+ });
334
+
335
+ test('getAnalyticAccountWithMultiplePlans', async () => {
336
+ const analyticAccount = await consumer.accounting.getAnalyticAccountWithMultiplePlans(
337
+ analyticAccounts[0].id,
338
+ analyticPlans[0].id
339
+ );
340
+ expect(analyticAccount).toBeTruthy();
341
+ });
342
+
343
+ test('updateAnalyticAccountWithMultiplePlans', async () => {
344
+ const testAnalyticAccount = analyticAccounts.find(
345
+ (account) => account.name === 'test sdk update'
346
+ );
347
+
348
+ const analyticAccount = await consumer.accounting.updateAnalyticAccountWithMultiplePlans(
349
+ testAnalyticAccount?.id,
350
+ '1',
351
+ { name: 'test sdk update 2' }
352
+ );
353
+ expect(analyticAccount).toBeTruthy();
354
+ expect(analyticAccount).toHaveProperty('name', 'test sdk update 2');
355
+ });
356
+
357
+ test('getAnalyticAccountsWithMultiplePlans', async () => {
358
+ const analyticAccountsWithMultiplePlans =
359
+ await consumer.accounting.getAnalyticAccountsWithMultiplePlans();
360
+ expect(analyticAccountsWithMultiplePlans).toBeInstanceOf(Array);
361
+ });
362
+
363
+ test('getAnalyticLinesOfAccount', async () => {
364
+ const analyticLinesOfAccount = await consumer.accounting.getAnalyticLinesOfAccount(
365
+ analyticAccounts[0].id
366
+ );
367
+ expect(analyticLinesOfAccount).toBeInstanceOf(Array);
368
+ if (analyticLinesOfAccount.length > 0) {
369
+ expect(analyticLinesOfAccount[0]).toHaveProperty('account_id', analyticAccounts[0].id);
370
+ expect(analyticLinesOfAccount[0]).toHaveProperty('description', expect.any(String));
371
+ expect(analyticLinesOfAccount[0]).toHaveProperty('amount', expect.any(Number));
372
+ expect(analyticLinesOfAccount[0]).toHaveProperty('date', expect.any(String));
373
+ expect(analyticLinesOfAccount[0]).toHaveProperty('id', expect.any(String));
374
+ }
375
+ });
376
+
377
+ test('getJournalEntries', async () => {
378
+ const journalEntries = await consumer.accounting.getJournalEntries({
379
+ unposted_allowed: true,
380
+ date_from: '2022-01-01',
381
+ date_to: '2022-01-31',
382
+ journal_id: journals[0].id,
383
+ });
384
+ expect(journalEntries).toBeInstanceOf(Array);
385
+ });
386
+
387
+ test('getJournalEntriesWithMultiplePlans', async () => {
388
+ const journalEntries = await consumer.accounting.getJournalEntriesWithMultiplePlans({
389
+ unposted_allowed: true,
390
+ date_from: '2022-01-01',
391
+ date_to: '2022-01-31',
392
+ journal_id: journals[0].id,
393
+ });
394
+ expect(journalEntries).toBeInstanceOf(Array);
395
+ });
396
+
397
+ test('getPaymentsByInvoiceId', async () => {
398
+ const payments = await consumer.accounting.getPaymentsByInvoiceId(invoices[0].id);
399
+ expect(payments).toBeInstanceOf(Array);
400
+ });
401
+
402
+ test('getVatCodes', async () => {
403
+ const vatCodes = await consumer.accounting.getVatCodes();
404
+ expect(vatCodes).toBeInstanceOf(Array);
405
+ expect(vatCodes.length).toBeGreaterThan(0);
406
+ expect(vatCodes[0]).toHaveProperty('id', expect.any(String));
407
+ expect(vatCodes[0]).toHaveProperty('code');
408
+ expect(vatCodes[0]).toHaveProperty('label', expect.any(String));
409
+ expect(vatCodes[0]).toHaveProperty('scope', expect.any(String));
410
+ expect(vatCodes[0]).toHaveProperty('rate', expect.any(Number));
411
+ expect(vatCodes[0]).toHaveProperty('type', expect.any(String));
412
+ });
413
+
414
+ let miscOperations: components['schemas']['MiscellaneousOperationOut'][];
415
+ test('getMiscOperations', async () => {
416
+ miscOperations = await consumer.accounting.getMiscOperations();
417
+ expect(miscOperations).toBeInstanceOf(Array);
418
+ expect(miscOperations.length).toBeGreaterThan(0);
419
+ expect(miscOperations[0]).toHaveProperty('id', expect.any(String));
420
+ });
421
+
422
+ test('createMiscOperation', async () => {
423
+ const data = {
424
+ operation_date: '2023-04-29',
425
+ currency: 'EUR',
426
+ lines: [
427
+ {
428
+ line_number: 1,
429
+ description: 'test line',
430
+ amount: 0,
431
+ type: 'general_account',
432
+ account_number: '400000',
433
+ },
434
+ ],
435
+ journal_id: journals?.find(
436
+ (journal: components['schemas']['Journal']) =>
437
+ journal.journal_type === 'miscellaneous_operation'
438
+ )?.id,
439
+ status: 'draft',
440
+ };
441
+
442
+ const miscOperation = await consumer.accounting.createMiscOperation(data);
443
+ expect(miscOperation).toBeTruthy();
444
+ });
445
+
446
+ test('getMiscOperation', async () => {
447
+ const miscOperation = await consumer.accounting.getMiscOperation(miscOperations[0].id);
448
+ expect(miscOperation).toBeTruthy();
449
+ expect(miscOperation).toHaveProperty('operation_number');
450
+ expect(miscOperation).toHaveProperty('operation_date', expect.any(String));
451
+ expect(miscOperation).toHaveProperty('currency', expect.any(String));
452
+ expect(miscOperation).toHaveProperty('lines', expect.any(Array));
453
+ expect(miscOperation).toHaveProperty('journal_id', expect.any(String));
454
+ expect(miscOperation).toHaveProperty('status', expect.any(String));
455
+ expect(miscOperation).toHaveProperty('id', expect.any(String));
456
+ });
457
+
458
+ test('attachPDF', async () => {
459
+ const pdfData = fs.readFileSync('test/data/accounting_invoice.pdf');
460
+ await consumer.accounting.attachPDF(
461
+ invoices[0].id,
462
+ { base64_string: pdfData.toString('base64') },
463
+ { overwrite_existing: true }
464
+ );
465
+ });
466
+
467
+ test('getChartOfAccounts', async () => {
468
+ const chartOfAccounts = await consumer.accounting.getChartOfAccounts({
469
+ classes: '6,7',
470
+ });
471
+ expect(chartOfAccounts).toBeTruthy();
472
+ });
473
+
474
+ test('getBalanceOfAccounts', async () => {
475
+ const balanceOfAccounts = await consumer.accounting.getBalanceOfAccounts({
476
+ accounts: ['7'],
477
+ start: '2022-01-01',
478
+ end: '2022-12-31',
479
+ });
480
+ expect(balanceOfAccounts).toBeTruthy();
481
+ expect(balanceOfAccounts).toHaveProperty('items');
482
+ expect(balanceOfAccounts.items).toBeInstanceOf(Array);
483
+ });
@@ -0,0 +1,68 @@
1
+ import { beforeAll, expect, test } from '@jest/globals';
2
+ import * as chift from '../../src/index';
3
+ import * as dotenv from 'dotenv';
4
+ import { components } from '../../src/types/public-api/schema';
5
+ dotenv.config();
6
+
7
+ const client = new chift.API({
8
+ baseUrl: process.env.CHIFT_BASE_URL,
9
+ clientId: process.env.CHIFT_CLIENT_ID as string,
10
+ clientSecret: process.env.CHIFT_CLIENT_SECRET as string,
11
+ accountId: process.env.CHIFT_ACCOUNT_ID as string,
12
+ });
13
+
14
+ const consumerName = 'test consumer 2';
15
+ const email = 'support@chift.eu';
16
+ const redirect_url = 'https://chift.eu';
17
+
18
+ let syncConsumer: any;
19
+ let consumer: any;
20
+ let connection: any;
21
+
22
+ beforeAll(async () => {
23
+ consumer = await client.Consumers.createConsumer({
24
+ email,
25
+ redirect_url,
26
+ name: consumerName,
27
+ });
28
+ syncConsumer = await client.Consumers.getConsumerById(
29
+ process.env.CHIFT_SYNC_CONSUMER_ID as string
30
+ );
31
+ });
32
+
33
+ test('createConnection', async () => {
34
+ const body = { integrationid: 1000, name: 'odoo test sdk' };
35
+ const result = await consumer.createConnection(body);
36
+ expect(result).toHaveProperty('url', expect.any(String));
37
+ });
38
+
39
+ let connections: components['schemas']['ConnectionItem'][];
40
+
41
+ test('getConnections', async () => {
42
+ connections = await syncConsumer.getConnections();
43
+ expect(connections).toBeInstanceOf(Array);
44
+ });
45
+
46
+ test.skip('updateConnection', async () => {
47
+ const updatedConnection = await syncConsumer.updateConnection(connections[0]?.connectionid, {
48
+ name: 'updated connection name',
49
+ });
50
+ expect(updatedConnection).toHaveProperty('name', 'updated connection name');
51
+ });
52
+
53
+ test.skip('deleteConnection', async () => {
54
+ await consumer.deleteConnection(connection.connectionId);
55
+ });
56
+
57
+ test('getSyncUrl', async () => {
58
+ const result = await syncConsumer.getSyncUrl({
59
+ syncid: process.env.CHIFT_TEST_SYNC_ID as string,
60
+ integrationids: [],
61
+ });
62
+ expect(result).toHaveProperty('url', expect.any(String));
63
+ });
64
+
65
+ test('getSyncData', async () => {
66
+ const syncData = await syncConsumer.getSyncData(process.env.CHIFT_TEST_SYNC_ID as string);
67
+ expect(syncData).toBeTruthy();
68
+ });
@@ -0,0 +1,83 @@
1
+ import { beforeAll, expect, test } from '@jest/globals';
2
+ import * as chift from '../../src/index';
3
+ import axios from 'axios';
4
+ import * as dotenv from 'dotenv';
5
+
6
+ dotenv.config();
7
+
8
+ const client = new chift.API({
9
+ baseUrl: process.env.CHIFT_BASE_URL,
10
+ clientId: process.env.CHIFT_CLIENT_ID as string,
11
+ clientSecret: process.env.CHIFT_CLIENT_SECRET as string,
12
+ accountId: process.env.CHIFT_ACCOUNT_ID as string,
13
+ });
14
+
15
+ const consumerName = 'test consumer';
16
+ const email = 'support@chift.eu';
17
+ const redirect_url = 'https://chift.eu';
18
+
19
+ let consumer: any;
20
+
21
+ beforeAll(async () => {
22
+ consumer = await client.Consumers.createConsumer({
23
+ email,
24
+ redirect_url,
25
+ name: consumerName,
26
+ });
27
+ });
28
+
29
+ test('createConsumer', async () => {
30
+ expect(consumer).toHaveProperty('consumerId');
31
+ expect(consumer).toHaveProperty('getConnections');
32
+ expect(consumer).toHaveProperty('createConnection');
33
+ expect(consumer).toHaveProperty('updateConnection');
34
+ expect(consumer).toHaveProperty('deleteConnection');
35
+ expect(consumer).toHaveProperty('getSyncUrl');
36
+ expect(consumer).toHaveProperty('name', consumerName);
37
+ expect(consumer).toHaveProperty('redirect_url', redirect_url);
38
+ expect(consumer).toHaveProperty('email', email);
39
+ expect(consumer).toHaveProperty('pos');
40
+ expect(consumer).toHaveProperty('accounting');
41
+ expect(consumer).toHaveProperty('invoicing');
42
+ expect(consumer).toHaveProperty('ecommerce');
43
+ expect(consumer).toHaveProperty('custom');
44
+ });
45
+
46
+ test('getConsumers', async () => {
47
+ const consumers = await client.Consumers.getConsumers();
48
+ expect(consumers).toBeInstanceOf(Array);
49
+ });
50
+
51
+ test('getConsumersByName', async () => {
52
+ const consumersWithName = await client.Consumers.getConsumersByName(consumerName);
53
+ expect(consumersWithName).toBeInstanceOf(Array);
54
+ expect(consumersWithName[0]).toHaveProperty('name', consumerName);
55
+ });
56
+
57
+ test('getConsumerById', async () => {
58
+ const consumerWithId = await client.Consumers.getConsumerById(consumer.consumerId);
59
+ expect(consumerWithId).toHaveProperty('consumerId', consumer.consumerId);
60
+ });
61
+
62
+ test('updateConsumerById', async () => {
63
+ const updatedName = 'updated test consumer';
64
+ const updatedConsumer = await client.Consumers.updateConsumerById(consumer.consumerId, {
65
+ name: updatedName,
66
+ });
67
+ expect(updatedConsumer).toHaveProperty('name', updatedName);
68
+ });
69
+
70
+ test('deleteConsumerById', async () => {
71
+ expect.assertions(1);
72
+ try {
73
+ await client.Consumers.deleteConsumerById(consumer.consumerId);
74
+ await client.Consumers.getConsumerById(consumer.consumerId);
75
+ } catch (e: unknown) {
76
+ if (axios.isAxiosError(e)) {
77
+ expect(e.message).toMatch('Request failed with status code 404');
78
+ return;
79
+ }
80
+
81
+ throw e;
82
+ }
83
+ });