@chift/chift-nodejs 1.0.17 → 1.0.18

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 (114) hide show
  1. package/package.json +5 -2
  2. package/.eslintignore +0 -1
  3. package/.eslintrc.json +0 -25
  4. package/.github/workflows/ci.yml +0 -75
  5. package/.husky/pre-commit +0 -4
  6. package/.prettierignore +0 -1
  7. package/.prettierrc.json +0 -7
  8. package/CHANGELOG.md +0 -108
  9. package/dist/src/helpers/openapi.d.ts +0 -3
  10. package/dist/src/helpers/openapi.js +0 -18
  11. package/dist/src/helpers/settings.d.ts +0 -4
  12. package/dist/src/helpers/settings.js +0 -5
  13. package/dist/src/index.d.ts +0 -1
  14. package/dist/src/modules/accounting.d.ts +0 -68
  15. package/dist/src/modules/accounting.js +0 -326
  16. package/dist/src/modules/api.d.ts +0 -18351
  17. package/dist/src/modules/api.js +0 -36
  18. package/dist/src/modules/consumer.d.ts +0 -3622
  19. package/dist/src/modules/consumer.js +0 -142
  20. package/dist/src/modules/consumers.d.ts +0 -18237
  21. package/dist/src/modules/consumers.js +0 -51
  22. package/dist/src/modules/custom.d.ts +0 -8
  23. package/dist/src/modules/custom.js +0 -36
  24. package/dist/src/modules/datastores.d.ts +0 -18
  25. package/dist/src/modules/datastores.js +0 -23
  26. package/dist/src/modules/ecommerce.d.ts +0 -24
  27. package/dist/src/modules/ecommerce.js +0 -97
  28. package/dist/src/modules/flow.d.ts +0 -15
  29. package/dist/src/modules/flow.js +0 -156
  30. package/dist/src/modules/integrations.d.ts +0 -23
  31. package/dist/src/modules/integrations.js +0 -23
  32. package/dist/src/modules/internalApi.d.ts +0 -24
  33. package/dist/src/modules/internalApi.js +0 -175
  34. package/dist/src/modules/invoicing.d.ts +0 -20
  35. package/dist/src/modules/invoicing.js +0 -90
  36. package/dist/src/modules/payment.d.ts +0 -14
  37. package/dist/src/modules/payment.js +0 -41
  38. package/dist/src/modules/pms.d.ts +0 -15
  39. package/dist/src/modules/pms.js +0 -47
  40. package/dist/src/modules/pos.d.ts +0 -26
  41. package/dist/src/modules/pos.js +0 -101
  42. package/dist/src/modules/sync.d.ts +0 -14654
  43. package/dist/src/modules/sync.js +0 -73
  44. package/dist/src/modules/syncs.d.ts +0 -11
  45. package/dist/src/modules/syncs.js +0 -39
  46. package/dist/src/modules/webhooks.d.ts +0 -58
  47. package/dist/src/modules/webhooks.js +0 -53
  48. package/dist/src/types/api.d.ts +0 -29
  49. package/dist/src/types/api.js +0 -2
  50. package/dist/src/types/consumers.d.ts +0 -8
  51. package/dist/src/types/consumers.js +0 -2
  52. package/dist/src/types/public-api/mappings.d.ts +0 -21
  53. package/dist/src/types/public-api/mappings.js +0 -2
  54. package/dist/src/types/sync.d.ts +0 -37
  55. package/dist/src/types/sync.js +0 -2
  56. package/dist/test/modules/accounting.test.d.ts +0 -1
  57. package/dist/test/modules/accounting.test.js +0 -590
  58. package/dist/test/modules/consumer.test.d.ts +0 -1
  59. package/dist/test/modules/consumer.test.js +0 -89
  60. package/dist/test/modules/consumers.test.d.ts +0 -1
  61. package/dist/test/modules/consumers.test.js +0 -109
  62. package/dist/test/modules/ecommerce.test.d.ts +0 -1
  63. package/dist/test/modules/ecommerce.test.js +0 -224
  64. package/dist/test/modules/integrations.test.d.ts +0 -1
  65. package/dist/test/modules/integrations.test.js +0 -54
  66. package/dist/test/modules/invoicing.test.d.ts +0 -1
  67. package/dist/test/modules/invoicing.test.js +0 -115
  68. package/dist/test/modules/payment.test.d.ts +0 -1
  69. package/dist/test/modules/payment.test.js +0 -88
  70. package/dist/test/modules/pms.test.d.ts +0 -1
  71. package/dist/test/modules/pms.test.js +0 -90
  72. package/dist/test/modules/pos.test.d.ts +0 -1
  73. package/dist/test/modules/pos.test.js +0 -179
  74. package/dist/test/modules/sync.test.d.ts +0 -1
  75. package/dist/test/modules/sync.test.js +0 -93
  76. package/dist/test/modules/syncs.test.d.ts +0 -1
  77. package/dist/test/modules/syncs.test.js +0 -53
  78. package/dist/test/modules/webhooks.test.d.ts +0 -1
  79. package/dist/test/modules/webhooks.test.js +0 -120
  80. package/jest.config.ts +0 -195
  81. package/src/helpers/openapi.ts +0 -22
  82. package/src/helpers/settings.ts +0 -3
  83. package/src/index.ts +0 -1
  84. package/src/modules/accounting.ts +0 -510
  85. package/src/modules/api.ts +0 -35
  86. package/src/modules/consumer.ts +0 -216
  87. package/src/modules/consumers.ts +0 -82
  88. package/src/modules/custom.ts +0 -36
  89. package/src/modules/datastores.ts +0 -19
  90. package/src/modules/ecommerce.ts +0 -129
  91. package/src/modules/flow.ts +0 -168
  92. package/src/modules/integrations.ts +0 -24
  93. package/src/modules/internalApi.ts +0 -182
  94. package/src/modules/invoicing.ts +0 -118
  95. package/src/modules/payment.ts +0 -59
  96. package/src/modules/pms.ts +0 -67
  97. package/src/modules/pos.ts +0 -144
  98. package/src/modules/sync.ts +0 -77
  99. package/src/modules/syncs.ts +0 -59
  100. package/src/modules/webhooks.ts +0 -86
  101. package/test/data/accounting_invoice.pdf +0 -0
  102. package/test/modules/accounting.test.ts +0 -647
  103. package/test/modules/consumer.test.ts +0 -68
  104. package/test/modules/consumers.test.ts +0 -85
  105. package/test/modules/ecommerce.test.ts +0 -213
  106. package/test/modules/integrations.test.ts +0 -22
  107. package/test/modules/invoicing.test.ts +0 -98
  108. package/test/modules/payment.test.ts +0 -65
  109. package/test/modules/pms.test.ts +0 -69
  110. package/test/modules/pos.test.ts +0 -164
  111. package/test/modules/sync.test.ts +0 -74
  112. package/test/modules/syncs.test.ts +0 -23
  113. package/test/modules/webhooks.test.ts +0 -92
  114. package/tsconfig.json +0 -107
@@ -1,647 +0,0 @@
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_BACKBONE_API,
11
- clientId: process.env.CHIFT_TESTING_CLIENTID as string,
12
- clientSecret: process.env.CHIFT_TESTING_CLIENTSECRET as string,
13
- accountId: process.env.CHIFT_TESTING_ACCOUNTID as string,
14
- });
15
-
16
- const consumerId = process.env.CHIFT_ACCOUNTING_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
- let vatCodes: components['schemas']['backbone_api__app__routers__accounting__VatCode'][];
44
- test('getVatCodes', async () => {
45
- vatCodes = await consumer.accounting.getVatCodes();
46
- expect(vatCodes).toBeInstanceOf(Array);
47
- expect(vatCodes.length).toBeGreaterThan(0);
48
- expect(vatCodes[0]).toHaveProperty('id', expect.any(String));
49
- expect(vatCodes[0]).toHaveProperty('code');
50
- expect(vatCodes[0]).toHaveProperty('label', expect.any(String));
51
- expect(vatCodes[0]).toHaveProperty('scope', expect.any(String));
52
- expect(vatCodes[0]).toHaveProperty('rate', expect.any(Number));
53
- expect(vatCodes[0]).toHaveProperty('type', expect.any(String));
54
- });
55
-
56
- test('createClient', async () => {
57
- const body: components['schemas']['ClientItemIn'] = {
58
- external_reference: 'sdk test',
59
- name: 'John Doe',
60
- currency: 'EUR',
61
- active: false,
62
- is_company: true,
63
- addresses: [
64
- {
65
- address_type: 'main',
66
- street: 'Main Street',
67
- city: 'Brussels',
68
- postal_code: '1000',
69
- country: 'BE',
70
- },
71
- ],
72
- };
73
- const client = await consumer.accounting.createClient(body);
74
- expect(client).toBeTruthy();
75
- expect(client).toHaveProperty('name', 'John Doe');
76
- });
77
-
78
- let clients: components['schemas']['ClientItemOut'][];
79
- test('getClients', async () => {
80
- clients = await consumer.accounting.getClients();
81
- expect(clients).toBeInstanceOf(Array);
82
- expect(clients.length).toBeGreaterThan(0);
83
- expect(clients[0]).toHaveProperty('id', expect.any(String));
84
- });
85
-
86
- test('getClient', async () => {
87
- const client = await consumer.accounting.getClient(clients[0].id);
88
- expect(client).toBeTruthy();
89
- expect(client).toHaveProperty('external_reference');
90
- expect(client).toHaveProperty('first_name');
91
- expect(client).toHaveProperty('last_name');
92
- expect(client).toHaveProperty('name');
93
- expect(client).toHaveProperty('function');
94
- expect(client).toHaveProperty('is_company');
95
- expect(client).toHaveProperty('company_id');
96
- expect(client).toHaveProperty('phone');
97
- expect(client).toHaveProperty('mobile');
98
- expect(client).toHaveProperty('email');
99
- expect(client).toHaveProperty('language');
100
- expect(client).toHaveProperty('internal_notes');
101
- expect(client).toHaveProperty('website');
102
- expect(client).toHaveProperty('vat');
103
- expect(client).toHaveProperty('iban');
104
- expect(client).toHaveProperty('bank_account');
105
- expect(client).toHaveProperty('currency');
106
- expect(client).toHaveProperty('active', expect.any(Boolean));
107
- expect(client).toHaveProperty('addresses', expect.any(Array));
108
- });
109
-
110
- test.skip('updateClient', async () => {
111
- const client = clients.find((client) => client.external_reference === 'sdk test');
112
- const updatedClient = await consumer.accounting.updateClient(client?.id, {
113
- website: 'https://test.com',
114
- });
115
- expect(updatedClient).toBeTruthy();
116
- expect(updatedClient).toHaveProperty('website', 'https://test.com');
117
- });
118
-
119
- test('createSupplier', async () => {
120
- const body: components['schemas']['SupplierItemIn'] = {
121
- external_reference: 'sdk test',
122
- name: 'Jane Doe',
123
- currency: 'EUR',
124
- active: false,
125
- is_company: true,
126
- addresses: [
127
- {
128
- address_type: 'main',
129
- street: 'Main Street',
130
- city: 'Brussels',
131
- postal_code: '1000',
132
- country: 'BE',
133
- },
134
- ],
135
- };
136
- const supplier = await consumer.accounting.createSupplier(body);
137
- expect(supplier).toBeTruthy();
138
- expect(supplier).toHaveProperty('name', 'Jane Doe');
139
- });
140
-
141
- let suppliers: components['schemas']['SupplierItemOut'][];
142
- test('getSuppliers', async () => {
143
- suppliers = await consumer.accounting.getSuppliers();
144
- expect(suppliers).toBeInstanceOf(Array);
145
- expect(suppliers.length).toBeGreaterThan(0);
146
- });
147
-
148
- test('getSupplier', async () => {
149
- const supplier = await consumer.accounting.getSupplier(suppliers[0].id);
150
- expect(supplier).toBeTruthy();
151
- expect(supplier).toHaveProperty('external_reference');
152
- expect(supplier).toHaveProperty('first_name');
153
- expect(supplier).toHaveProperty('last_name');
154
- expect(supplier).toHaveProperty('name');
155
- expect(supplier).toHaveProperty('function');
156
- expect(supplier).toHaveProperty('is_company');
157
- expect(supplier).toHaveProperty('company_id');
158
- expect(supplier).toHaveProperty('phone');
159
- expect(supplier).toHaveProperty('mobile');
160
- expect(supplier).toHaveProperty('email');
161
- expect(supplier).toHaveProperty('language');
162
- expect(supplier).toHaveProperty('internal_notes');
163
- expect(supplier).toHaveProperty('website');
164
- expect(supplier).toHaveProperty('vat');
165
- expect(supplier).toHaveProperty('iban');
166
- expect(supplier).toHaveProperty('bank_account');
167
- expect(supplier).toHaveProperty('currency');
168
- expect(supplier).toHaveProperty('active', expect.any(Boolean));
169
- expect(supplier).toHaveProperty('addresses', expect.any(Array));
170
- });
171
-
172
- test.skip('updateSupplier', async () => {
173
- const supplier = suppliers.find((supplier) => supplier.external_reference === 'sdk test');
174
- const updatedSupplier = await consumer.accounting.updateSupplier(supplier?.id, {
175
- name: 'Jane Updated Doe',
176
- });
177
- expect(updatedSupplier).toBeTruthy();
178
- expect(updatedSupplier).toHaveProperty('name', 'Jane Updated Doe');
179
- });
180
-
181
- test('createInvoice', async () => {
182
- const journal = journals.find((journal) => journal.journal_type === 'customer_invoice');
183
- if (!journal) {
184
- throw new Error('No journal with type "customer_invoice" found to create invoice');
185
- }
186
-
187
- const vatCode = vatCodes.find((vatCode) => vatCode.type === 'sale' && vatCode.rate === 21);
188
- if (!vatCode?.id) {
189
- throw new Error('No vat code with type "sale" and rate 21 found to create invoice');
190
- }
191
-
192
- const body: components['schemas']['InvoiceItemInMonoAnalyticPlan'] = {
193
- invoice_type: 'customer_invoice',
194
- invoice_date: '2022-12-01',
195
- due_date: '2022-12-31',
196
- currency: 'EUR',
197
- untaxed_amount: 100,
198
- tax_amount: 21,
199
- total: 121,
200
- partner_id: clients[0]?.id as string,
201
- journal_id: journal.id,
202
- status: 'draft',
203
- currency_exchange_rate: 1,
204
- lines: [
205
- {
206
- description: 'Test',
207
- unit_price: 100,
208
- quantity: 1,
209
- untaxed_amount: 100,
210
- tax_rate: 21,
211
- tax_amount: 21,
212
- total: 121,
213
- account_number: '700000',
214
- tax_code: vatCode.id,
215
- line_number: 1,
216
- },
217
- ],
218
- };
219
- const invoice = await consumer.accounting.createInvoice(body);
220
- expect(invoice).toBeTruthy();
221
- expect(invoice).toHaveProperty('total', 121);
222
- });
223
-
224
- let invoices: components['schemas']['InvoiceItemOutMonoAnalyticPlan'][];
225
- test('getInvoicesByType', async () => {
226
- invoices = await consumer.accounting.getInvoicesByType('customer_invoice', {
227
- date_from: '2022-12-01',
228
- date_to: '2022-12-31',
229
- });
230
- expect(invoices).toBeInstanceOf(Array);
231
- expect(invoices.length).toBeGreaterThan(0);
232
- expect(invoices[0]).toHaveProperty('id', expect.any(String));
233
- });
234
-
235
- test('getInvoicesByTypeWithMultiplePlans', async () => {
236
- const invoicesWithMultiplePlans = await consumer.accounting.getInvoicesByTypeWithMultiplePlans(
237
- 'customer_invoice',
238
- {
239
- date_from: '2022-12-01',
240
- date_to: '2022-12-31',
241
- }
242
- );
243
- expect(invoicesWithMultiplePlans).toBeInstanceOf(Array);
244
- expect(invoicesWithMultiplePlans.length).toBeGreaterThan(0);
245
- expect(invoicesWithMultiplePlans[0]).toHaveProperty('id', expect.any(String));
246
- });
247
-
248
- test('getInvoice', async () => {
249
- const invoice = await consumer.accounting.getInvoice(invoices[0].id, {
250
- include_payments: true,
251
- });
252
- expect(invoice).toBeTruthy();
253
- expect(invoice).toHaveProperty('id', invoices[0].id);
254
- expect(invoices[0]).toHaveProperty('invoice_type', expect.any(String));
255
- expect(invoices[0]).toHaveProperty('invoice_number');
256
- expect(invoices[0]).toHaveProperty('partner_id', expect.any(String));
257
- expect(invoices[0]).toHaveProperty('invoice_date', expect.any(String));
258
- expect(invoices[0]).toHaveProperty('due_date', expect.any(String));
259
- expect(invoices[0]).toHaveProperty('currency', expect.any(String));
260
- expect(invoices[0]).toHaveProperty('untaxed_amount', expect.any(Number));
261
- expect(invoices[0]).toHaveProperty('tax_amount', expect.any(Number));
262
- expect(invoices[0]).toHaveProperty('total', expect.any(Number));
263
- expect(invoices[0]).toHaveProperty('reference');
264
- expect(invoices[0]).toHaveProperty('payment_communication');
265
- expect(invoices[0]).toHaveProperty('customer_memo');
266
- expect(invoices[0]).toHaveProperty('id');
267
- expect(invoices[0]).toHaveProperty('journal_id', expect.any(String));
268
- expect(invoices[0]).toHaveProperty('payments');
269
- expect(invoices[0]).toHaveProperty('status');
270
- expect(invoices[0]).toHaveProperty('lines', expect.any(Array));
271
- });
272
-
273
- test('createInvoiceWithMultiplePlans', async () => {
274
- const journal = journals.find((journal) => journal.journal_type === 'customer_invoice');
275
- if (!journal) {
276
- throw new Error(
277
- 'No journal with type customer_invoice found to create Invoice With Multiple Plans'
278
- );
279
- }
280
-
281
- const vatCode = vatCodes.find((vatCode) => vatCode.type === 'sale' && vatCode.rate === 21);
282
- if (!vatCode?.id) {
283
- throw new Error('No vat code with type "sale" and rate 21 found to create invoice');
284
- }
285
-
286
- const body: components['schemas']['InvoiceItemInMonoAnalyticPlan'] = {
287
- invoice_type: 'customer_invoice',
288
- invoice_date: '2022-12-01',
289
- due_date: '2022-12-31',
290
- currency: 'EUR',
291
- untaxed_amount: 100,
292
- tax_amount: 21,
293
- total: 121,
294
- partner_id: clients[0]?.id as string,
295
- journal_id: journal.id,
296
- status: 'draft',
297
- currency_exchange_rate: 1,
298
- lines: [
299
- {
300
- description: 'Test',
301
- unit_price: 100,
302
- quantity: 1,
303
- untaxed_amount: 100,
304
- tax_rate: 21,
305
- tax_amount: 21,
306
- total: 121,
307
- account_number: '700000',
308
- tax_code: vatCode.id,
309
- line_number: 1,
310
- },
311
- ],
312
- };
313
- const invoice = await consumer.accounting.createInvoiceWithMultiplePlans(body);
314
- expect(invoice).toBeTruthy();
315
- });
316
-
317
- test('getInvoiceWithMultiplePlans', async () => {
318
- const invoice = await consumer.accounting.getInvoiceWithMultiplePlans(invoices[0].id, {
319
- include_payments: true,
320
- });
321
- expect(invoice).toBeTruthy();
322
- });
323
-
324
- test('createAnalyticAccount', async () => {
325
- const body: components['schemas']['AnalyticAccountItemIn'] = {
326
- active: false,
327
- code: '4000',
328
- name: 'sdk test',
329
- currency: 'EUR',
330
- };
331
- const analyticAccount = await consumer.accounting.createAnalyticAccount(body);
332
- expect(analyticAccount).toBeTruthy();
333
- expect(analyticAccount).toHaveProperty('name', 'sdk test');
334
- });
335
-
336
- let analyticAccounts: components['schemas']['AnalyticAccountItemOut'][];
337
- test('getAnalyticAccounts', async () => {
338
- analyticAccounts = await consumer.accounting.getAnalyticAccounts();
339
- expect(analyticAccounts).toBeInstanceOf(Array);
340
- expect(analyticAccounts.length).toBeGreaterThan(0);
341
- expect(analyticAccounts[0]).toHaveProperty('id', expect.any(String));
342
- });
343
-
344
- test.skip('createAnalyticAccountWithMultiplePlans', async () => {
345
- if (analyticPlans.length === 0) {
346
- throw new Error('No analytic plans found to create analytic account with multiple plans');
347
- }
348
-
349
- const analyticAccount = await consumer.accounting.createAnalyticAccountWithMultiplePlans(
350
- analyticPlans[0].id,
351
- {
352
- code: '4000',
353
- name: 'sdk test',
354
- currency: 'EUR',
355
- }
356
- );
357
- expect(analyticAccount).toBeTruthy();
358
- });
359
-
360
- test('getAnalyticAccount', async () => {
361
- if (analyticAccounts.length === 0) {
362
- throw new Error('No analytic accounts found to get analytic account');
363
- }
364
-
365
- const analyticAccount = await consumer.accounting.getAnalyticAccount(analyticAccounts[0].id);
366
- expect(analyticAccount).toBeTruthy();
367
- });
368
-
369
- test.skip('updateAnalyticAccount', async () => {
370
- if (analyticAccounts.length === 0) {
371
- throw new Error('No analytic accounts found to update analytic account');
372
- }
373
-
374
- const testAnalyticAccount = analyticAccounts.find((account) => account.name === 'sdk test');
375
- const analyticAccount = await consumer.accounting.updateAnalyticAccount(
376
- testAnalyticAccount?.id,
377
- { name: 'test sdk update' }
378
- );
379
- expect(analyticAccount).toBeTruthy();
380
- expect(analyticAccount).toHaveProperty('name', 'test sdk update');
381
- });
382
-
383
- test.skip('getAnalyticAccountWithMultiplePlans', async () => {
384
- if (analyticPlans.length === 0) {
385
- throw new Error('No analytic plans found to get analytic account with multiple plans');
386
- }
387
-
388
- const analyticAccount = await consumer.accounting.getAnalyticAccountWithMultiplePlans(
389
- analyticAccounts[0].id,
390
- analyticPlans[0].id
391
- );
392
- expect(analyticAccount).toBeTruthy();
393
- });
394
-
395
- test.skip('updateAnalyticAccountWithMultiplePlans', async () => {
396
- if (!analyticAccounts.length) {
397
- throw new Error(
398
- 'No analytic accounts found to update analytic account with multiple plans'
399
- );
400
- }
401
-
402
- const testAnalyticAccount = analyticAccounts.find(
403
- (account) => account.name === 'test sdk update'
404
- );
405
-
406
- const analyticAccount = await consumer.accounting.updateAnalyticAccountWithMultiplePlans(
407
- testAnalyticAccount?.id,
408
- '1',
409
- { name: 'test sdk update 2' }
410
- );
411
- expect(analyticAccount).toBeTruthy();
412
- expect(analyticAccount).toHaveProperty('name', 'test sdk update 2');
413
- });
414
-
415
- test.skip('getAnalyticAccountsWithMultiplePlans', async () => {
416
- const analyticAccountsWithMultiplePlans =
417
- await consumer.accounting.getAnalyticAccountsWithMultiplePlans();
418
- expect(analyticAccountsWithMultiplePlans).toBeInstanceOf(Array);
419
- });
420
-
421
- test.skip('createJournalEntry', async () => {
422
- const journal = journals.find((journal) => journal.journal_type === 'customer_invoice');
423
- if (!journal) {
424
- throw new Error('No journal with type "customer_invoice" found to create journal entry');
425
- }
426
-
427
- if (!clients.length) {
428
- throw new Error('No clients found to create journal entry');
429
- }
430
-
431
- const journalEntry = await consumer.accounting.createJournalEntry({
432
- journal_id: journal.id,
433
- number: new Date().valueOf(),
434
- currency: 'EUR',
435
- date: '2022-01-01',
436
- items: [
437
- {
438
- account_type: 'customer_account',
439
- account: clients[0].id,
440
- credit: 0,
441
- debit: 10,
442
- currency: 'EUR',
443
- prioritise_thirdparty_account: false,
444
- analytic_distribution: [],
445
- },
446
- ],
447
- });
448
- expect(journalEntry).toBeTruthy();
449
- expect(journalEntry).toHaveProperty('journal_id', journal.id);
450
- });
451
-
452
- test('getJournalEntries', async () => {
453
- const journalEntries = await consumer.accounting.getJournalEntries({
454
- unposted_allowed: true,
455
- date_from: '2022-01-01',
456
- date_to: '2022-01-31',
457
- journal_id: journals[0].id,
458
- });
459
- expect(journalEntries).toBeInstanceOf(Array);
460
- });
461
-
462
- test('getJournalEntriesWithMultiplePlans', async () => {
463
- const journalEntries = await consumer.accounting.getJournalEntriesWithMultiplePlans({
464
- unposted_allowed: true,
465
- date_from: '2022-01-01',
466
- date_to: '2022-01-31',
467
- journal_id: journals[0].id,
468
- });
469
- expect(journalEntries).toBeInstanceOf(Array);
470
- });
471
-
472
- test('getPaymentsByInvoiceId', async () => {
473
- const payments = await consumer.accounting.getPaymentsByInvoiceId(invoices[0].id);
474
- expect(payments).toBeInstanceOf(Array);
475
- });
476
-
477
- let miscOperations: components['schemas']['MiscellaneousOperationOut'][];
478
- test('getMiscOperations', async () => {
479
- miscOperations = await consumer.accounting.getMiscOperations();
480
- expect(miscOperations).toBeInstanceOf(Array);
481
- expect(miscOperations.length).toBeGreaterThan(0);
482
- expect(miscOperations[0]).toHaveProperty('id', expect.any(String));
483
- });
484
-
485
- test('createMiscOperation', async () => {
486
- const data = {
487
- operation_date: '2023-04-29',
488
- currency: 'EUR',
489
- lines: [
490
- {
491
- line_number: 1,
492
- description: 'test line',
493
- amount: 0,
494
- type: 'general_account',
495
- account_number: '400000',
496
- },
497
- ],
498
- journal_id: journals?.find(
499
- (journal: components['schemas']['Journal']) =>
500
- journal.journal_type === 'miscellaneous_operation'
501
- )?.id,
502
- status: 'draft',
503
- };
504
-
505
- const miscOperation = await consumer.accounting.createMiscOperation(data);
506
- expect(miscOperation).toBeTruthy();
507
- });
508
-
509
- test('getMiscOperation', async () => {
510
- const miscOperation = await consumer.accounting.getMiscOperation(miscOperations[0].id);
511
- expect(miscOperation).toBeTruthy();
512
- expect(miscOperation).toHaveProperty('operation_number');
513
- expect(miscOperation).toHaveProperty('operation_date', expect.any(String));
514
- expect(miscOperation).toHaveProperty('currency', expect.any(String));
515
- expect(miscOperation).toHaveProperty('lines', expect.any(Array));
516
- expect(miscOperation).toHaveProperty('journal_id', expect.any(String));
517
- expect(miscOperation).toHaveProperty('status', expect.any(String));
518
- expect(miscOperation).toHaveProperty('id', expect.any(String));
519
- });
520
-
521
- test('attachPDF', async () => {
522
- const pdfData = fs.readFileSync('test/data/accounting_invoice.pdf');
523
- await consumer.accounting.attachPDF(
524
- invoices[0].id,
525
- { base64_string: pdfData.toString('base64') },
526
- { overwrite_existing: true }
527
- );
528
- });
529
-
530
- test('getChartOfAccounts', async () => {
531
- const chartOfAccounts = await consumer.accounting.getChartOfAccounts({
532
- classes: '6,7',
533
- });
534
- expect(chartOfAccounts).toBeTruthy();
535
- });
536
-
537
- test.skip('getBalanceOfAccounts', async () => {
538
- const balanceOfAccounts = await consumer.accounting.getBalanceOfAccounts({
539
- accounts: ['7'],
540
- start: '2022-01-01',
541
- end: '2022-12-31',
542
- });
543
- expect(balanceOfAccounts).toBeTruthy();
544
- expect(balanceOfAccounts).toHaveProperty('items');
545
- expect(balanceOfAccounts.items).toBeInstanceOf(Array);
546
- });
547
-
548
- test('getEmployees', async () => {
549
- const employees = await consumer.accounting.getEmployees();
550
- expect(employees).toBeTruthy();
551
- });
552
-
553
- test.skip('getOutstandings', async () => {
554
- const outstandings = await consumer.accounting.getOutstandings({
555
- type: 'client',
556
- unposted_allowed: false,
557
- });
558
- expect(outstandings).toBeTruthy();
559
- expect(outstandings.items).toBeInstanceOf(Array);
560
- });
561
-
562
- test('createFinancialEntry', async () => {
563
- const journal = journals.find((journal) => journal.journal_type === 'financial_operation');
564
- if (!journal) {
565
- throw new Error(
566
- 'No journal with type "financial_operation" found to create financial entry'
567
- );
568
- }
569
-
570
- if (!clients.length) {
571
- throw new Error('No clients found to create journal entry');
572
- }
573
-
574
- const financialEntry = await consumer.accounting.createFinancialEntry({
575
- date: '2022-01-01',
576
- journal_id: journal.id,
577
- currency: 'EUR',
578
- items: [
579
- {
580
- account_type: 'customer_account',
581
- account: clients[0].id,
582
- amount: 10,
583
- },
584
- ],
585
- });
586
- expect(financialEntry).toBeTruthy();
587
- expect(financialEntry).toHaveProperty('journal_id', journal.id);
588
- });
589
-
590
- /**
591
- * @deprecated replaced by createFinancialEntry
592
- */
593
- test('createFinancialEntryOld', async () => {
594
- const journal = journals.find((journal) => journal.journal_type === 'financial_operation');
595
- if (!journal) {
596
- throw new Error(
597
- 'No journal with type "financial_operation" found to create financial entry'
598
- );
599
- }
600
-
601
- const financialEntry = await consumer.accounting.createFinancialEntryOld({
602
- date: '2022-01-01',
603
- journal_id: journal.id,
604
- currency: 'EUR',
605
- items: [
606
- {
607
- type: 'customer_account',
608
- account_number: clients[0].account_number,
609
- partner_id: clients[0].id,
610
- amount: 10,
611
- },
612
- ],
613
- });
614
- expect(financialEntry).toBeTruthy();
615
- expect(financialEntry).toHaveProperty('journal_id', journal.id);
616
- });
617
-
618
- let folders: components['schemas']['FolderItem'][] = [];
619
- test('getFolders', async () => {
620
- folders = await consumer.accounting.getFolders();
621
- expect(folders).toBeInstanceOf(Array);
622
- expect(folders.length).toBeGreaterThan(0);
623
- expect(folders[0]).toHaveProperty('id', expect.any(String));
624
- expect(folders[0]).toHaveProperty('name', expect.any(String));
625
- });
626
-
627
- test.skip('getAttachments', async () => {
628
- const attachments = await consumer.accounting.getAttachments({
629
- // TODO: Add documentId from test account
630
- documentId: '',
631
- type: 'invoice',
632
- });
633
- expect(attachments).toBeInstanceOf(Array);
634
- expect(attachments.length).toBeGreaterThan(0);
635
- expect(attachments[0]).toHaveProperty('id', expect.any(String));
636
- expect(attachments[0]).toHaveProperty('base64_string', expect.any(String));
637
- });
638
-
639
- test.skip('matchEntries', async () => {
640
- const match = await consumer.accounting.matchEntries({
641
- // TODO: Change params with test account values
642
- entries: [],
643
- partner_id: '',
644
- });
645
- expect(match).toHaveProperty('matching_number', expect.any(String));
646
- expect(match).toHaveProperty('balance', expect.any(Number));
647
- });