@chift/chift-nodejs 1.0.1 → 1.0.3

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 (53) hide show
  1. package/CHANGELOG.md +15 -4
  2. package/dist/src/modules/accounting.d.ts +4 -1
  3. package/dist/src/modules/accounting.js +16 -1
  4. package/dist/src/modules/api.d.ts +1494 -262
  5. package/dist/src/modules/consumer.d.ts +95 -13
  6. package/dist/src/modules/consumers.d.ts +475 -65
  7. package/dist/src/modules/integrations.d.ts +2 -0
  8. package/dist/src/modules/sync.d.ts +380 -52
  9. package/dist/src/modules/sync.js +0 -2
  10. package/dist/src/modules/syncs.d.ts +956 -136
  11. package/dist/test/modules/accounting.test.js +104 -15
  12. package/dist/test/modules/consumers.test.js +1 -1
  13. package/dist/test/modules/pos.test.js +4 -4
  14. package/package.json +1 -1
  15. package/src/modules/accounting.ts +12 -1
  16. package/src/types/public-api/schema.d.ts +56 -2
  17. package/test/modules/accounting.test.ts +108 -21
  18. package/test/modules/consumers.test.ts +3 -1
  19. package/.eslintcache +0 -1
  20. package/coverage/clover.xml +0 -1645
  21. package/coverage/coverage-final.json +0 -19
  22. package/coverage/lcov-report/base.css +0 -224
  23. package/coverage/lcov-report/block-navigation.js +0 -87
  24. package/coverage/lcov-report/favicon.png +0 -0
  25. package/coverage/lcov-report/index.html +0 -146
  26. package/coverage/lcov-report/prettify.css +0 -1
  27. package/coverage/lcov-report/prettify.js +0 -2
  28. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  29. package/coverage/lcov-report/sorter.js +0 -196
  30. package/coverage/lcov-report/src/helpers/index.html +0 -131
  31. package/coverage/lcov-report/src/helpers/openapi.ts.html +0 -151
  32. package/coverage/lcov-report/src/helpers/settings.ts.html +0 -94
  33. package/coverage/lcov-report/src/index.html +0 -116
  34. package/coverage/lcov-report/src/index.ts.html +0 -88
  35. package/coverage/lcov-report/src/modules/accounting.ts.html +0 -1156
  36. package/coverage/lcov-report/src/modules/api.ts.html +0 -190
  37. package/coverage/lcov-report/src/modules/consumer.ts.html +0 -616
  38. package/coverage/lcov-report/src/modules/consumers.ts.html +0 -331
  39. package/coverage/lcov-report/src/modules/custom.ts.html +0 -193
  40. package/coverage/lcov-report/src/modules/datastores.ts.html +0 -142
  41. package/coverage/lcov-report/src/modules/ecommerce.ts.html +0 -331
  42. package/coverage/lcov-report/src/modules/flow.ts.html +0 -589
  43. package/coverage/lcov-report/src/modules/index.html +0 -326
  44. package/coverage/lcov-report/src/modules/integrations.ts.html +0 -151
  45. package/coverage/lcov-report/src/modules/internalApi.ts.html +0 -586
  46. package/coverage/lcov-report/src/modules/invoicing.ts.html +0 -391
  47. package/coverage/lcov-report/src/modules/pos.ts.html +0 -421
  48. package/coverage/lcov-report/src/modules/sync.ts.html +0 -316
  49. package/coverage/lcov-report/src/modules/syncs.ts.html +0 -169
  50. package/coverage/lcov-report/src/modules/webhooks.ts.html +0 -343
  51. package/coverage/lcov.info +0 -1976
  52. package/dist/test/modules/flow.test.d.ts +0 -1
  53. package/dist/test/modules/flow.test.js +0 -69
@@ -69,6 +69,18 @@ let journals;
69
69
  (0, globals_1.expect)(journals[0]).toHaveProperty('name', globals_1.expect.any(String));
70
70
  (0, globals_1.expect)(journals[0]).toHaveProperty('journal_type', globals_1.expect.any(String));
71
71
  }));
72
+ let vatCodes;
73
+ (0, globals_1.test)('getVatCodes', () => __awaiter(void 0, void 0, void 0, function* () {
74
+ vatCodes = yield consumer.accounting.getVatCodes();
75
+ (0, globals_1.expect)(vatCodes).toBeInstanceOf(Array);
76
+ (0, globals_1.expect)(vatCodes.length).toBeGreaterThan(0);
77
+ (0, globals_1.expect)(vatCodes[0]).toHaveProperty('id', globals_1.expect.any(String));
78
+ (0, globals_1.expect)(vatCodes[0]).toHaveProperty('code');
79
+ (0, globals_1.expect)(vatCodes[0]).toHaveProperty('label', globals_1.expect.any(String));
80
+ (0, globals_1.expect)(vatCodes[0]).toHaveProperty('scope', globals_1.expect.any(String));
81
+ (0, globals_1.expect)(vatCodes[0]).toHaveProperty('rate', globals_1.expect.any(Number));
82
+ (0, globals_1.expect)(vatCodes[0]).toHaveProperty('type', globals_1.expect.any(String));
83
+ }));
72
84
  (0, globals_1.test)('createClient', () => __awaiter(void 0, void 0, void 0, function* () {
73
85
  const body = {
74
86
  external_reference: 'sdk test',
@@ -186,6 +198,14 @@ let suppliers;
186
198
  }));
187
199
  (0, globals_1.test)('createInvoice', () => __awaiter(void 0, void 0, void 0, function* () {
188
200
  var _a;
201
+ const journal = journals.find((journal) => journal.journal_type === 'customer_invoice');
202
+ if (!journal) {
203
+ throw new Error('No journal with type "customer_invoice" found to create invoice');
204
+ }
205
+ const vatCode = vatCodes.find((vatCode) => vatCode.type === 'sale' && vatCode.rate === 21);
206
+ if (!(vatCode === null || vatCode === void 0 ? void 0 : vatCode.id)) {
207
+ throw new Error('No vat code with type "sale" and rate 21 found to create invoice');
208
+ }
189
209
  const body = {
190
210
  invoice_type: 'customer_invoice',
191
211
  invoice_date: '2022-12-01',
@@ -195,7 +215,7 @@ let suppliers;
195
215
  tax_amount: 21,
196
216
  total: 121,
197
217
  partner_id: (_a = clients[0]) === null || _a === void 0 ? void 0 : _a.id,
198
- journal_id: journals[0].id,
218
+ journal_id: journal.id,
199
219
  lines: [
200
220
  {
201
221
  description: 'Test',
@@ -206,7 +226,7 @@ let suppliers;
206
226
  tax_amount: 21,
207
227
  total: 121,
208
228
  account_number: '700000',
209
- tax_code: '1',
229
+ tax_code: vatCode.id,
210
230
  },
211
231
  ],
212
232
  };
@@ -259,6 +279,14 @@ let invoices;
259
279
  }));
260
280
  (0, globals_1.test)('createInvoiceWithMultiplePlans', () => __awaiter(void 0, void 0, void 0, function* () {
261
281
  var _b;
282
+ const journal = journals.find((journal) => journal.journal_type === 'customer_invoice');
283
+ if (!journal) {
284
+ throw new Error('No journal with type customer_invoice found to create Invoice With Multiple Plans');
285
+ }
286
+ const vatCode = vatCodes.find((vatCode) => vatCode.type === 'sale' && vatCode.rate === 21);
287
+ if (!(vatCode === null || vatCode === void 0 ? void 0 : vatCode.id)) {
288
+ throw new Error('No vat code with type "sale" and rate 21 found to create invoice');
289
+ }
262
290
  const body = {
263
291
  invoice_type: 'customer_invoice',
264
292
  invoice_date: '2022-12-01',
@@ -268,7 +296,7 @@ let invoices;
268
296
  tax_amount: 21,
269
297
  total: 121,
270
298
  partner_id: (_b = clients[0]) === null || _b === void 0 ? void 0 : _b.id,
271
- journal_id: journals[0].id,
299
+ journal_id: journal.id,
272
300
  lines: [
273
301
  {
274
302
  description: 'Test',
@@ -279,7 +307,7 @@ let invoices;
279
307
  tax_amount: 21,
280
308
  total: 121,
281
309
  account_number: '700000',
282
- tax_code: '1',
310
+ tax_code: vatCode.id,
283
311
  },
284
312
  ],
285
313
  };
@@ -360,6 +388,34 @@ let analyticAccounts;
360
388
  (0, globals_1.expect)(analyticLinesOfAccount[0]).toHaveProperty('id', globals_1.expect.any(String));
361
389
  }
362
390
  }));
391
+ (0, globals_1.test)('createJournalEntry', () => __awaiter(void 0, void 0, void 0, function* () {
392
+ const journal = journals.find((journal) => journal.journal_type === 'customer_invoice');
393
+ if (!journal) {
394
+ throw new Error('No journal with type "customer_invoice" found to create journal entry');
395
+ }
396
+ const journalEntry = yield consumer.accounting.createJournalEntry({
397
+ journal_id: journal.id,
398
+ name: Date.now().toString(),
399
+ date: '2022-01-01',
400
+ items: [
401
+ {
402
+ account_number: clients[0].account_number,
403
+ credit: 0,
404
+ debit: 10,
405
+ partner_id: clients[0].id,
406
+ currency: 'EUR',
407
+ },
408
+ {
409
+ account_number: '700000',
410
+ credit: 10,
411
+ debit: 0,
412
+ currency: 'EUR',
413
+ },
414
+ ],
415
+ });
416
+ (0, globals_1.expect)(journalEntry).toBeTruthy();
417
+ (0, globals_1.expect)(journalEntry).toHaveProperty('journal_id', journal.id);
418
+ }));
363
419
  (0, globals_1.test)('getJournalEntries', () => __awaiter(void 0, void 0, void 0, function* () {
364
420
  const journalEntries = yield consumer.accounting.getJournalEntries({
365
421
  unposted_allowed: true,
@@ -382,17 +438,6 @@ let analyticAccounts;
382
438
  const payments = yield consumer.accounting.getPaymentsByInvoiceId(invoices[0].id);
383
439
  (0, globals_1.expect)(payments).toBeInstanceOf(Array);
384
440
  }));
385
- (0, globals_1.test)('getVatCodes', () => __awaiter(void 0, void 0, void 0, function* () {
386
- const vatCodes = yield consumer.accounting.getVatCodes();
387
- (0, globals_1.expect)(vatCodes).toBeInstanceOf(Array);
388
- (0, globals_1.expect)(vatCodes.length).toBeGreaterThan(0);
389
- (0, globals_1.expect)(vatCodes[0]).toHaveProperty('id', globals_1.expect.any(String));
390
- (0, globals_1.expect)(vatCodes[0]).toHaveProperty('code');
391
- (0, globals_1.expect)(vatCodes[0]).toHaveProperty('label', globals_1.expect.any(String));
392
- (0, globals_1.expect)(vatCodes[0]).toHaveProperty('scope', globals_1.expect.any(String));
393
- (0, globals_1.expect)(vatCodes[0]).toHaveProperty('rate', globals_1.expect.any(Number));
394
- (0, globals_1.expect)(vatCodes[0]).toHaveProperty('type', globals_1.expect.any(String));
395
- }));
396
441
  let miscOperations;
397
442
  (0, globals_1.test)('getMiscOperations', () => __awaiter(void 0, void 0, void 0, function* () {
398
443
  miscOperations = yield consumer.accounting.getMiscOperations();
@@ -451,3 +496,47 @@ let miscOperations;
451
496
  (0, globals_1.expect)(balanceOfAccounts).toHaveProperty('items');
452
497
  (0, globals_1.expect)(balanceOfAccounts.items).toBeInstanceOf(Array);
453
498
  }));
499
+ (0, globals_1.test)('getEmployees', () => __awaiter(void 0, void 0, void 0, function* () {
500
+ const employees = yield consumer.accounting.getEmployees();
501
+ (0, globals_1.expect)(employees).toBeTruthy();
502
+ }));
503
+ (0, globals_1.test)('getOutstandings', () => __awaiter(void 0, void 0, void 0, function* () {
504
+ var _d;
505
+ globals_1.expect.assertions(1);
506
+ try {
507
+ const outstandings = yield consumer.accounting.getOutstandings({
508
+ type: 'client',
509
+ unposted_allowed: true,
510
+ });
511
+ (0, globals_1.expect)(outstandings).toBeTruthy();
512
+ (0, globals_1.expect)(outstandings.items).toBeInstanceOf(Array);
513
+ }
514
+ catch (e) {
515
+ if ((_d = e === null || e === void 0 ? void 0 : e.error) === null || _d === void 0 ? void 0 : _d.error_code) {
516
+ (0, globals_1.expect)(e.error.error_code).toMatch('ERROR_API_RESOURCE_NOT_FOUND');
517
+ return;
518
+ }
519
+ throw e;
520
+ }
521
+ }));
522
+ (0, globals_1.test)('createFinancialEntry', () => __awaiter(void 0, void 0, void 0, function* () {
523
+ const journal = journals.find((journal) => journal.journal_type === 'financial_operation');
524
+ if (!journal) {
525
+ throw new Error('No journal with type "financial_operation" found to create financial entry');
526
+ }
527
+ const financialEntry = yield consumer.accounting.createFinancialEntry({
528
+ date: '2022-01-01',
529
+ journal_id: journal.id,
530
+ currency: 'EUR',
531
+ items: [
532
+ {
533
+ type: 'customer_account',
534
+ account_number: clients[0].account_number,
535
+ partner_id: clients[0].id,
536
+ amount: 10,
537
+ },
538
+ ],
539
+ });
540
+ (0, globals_1.expect)(financialEntry).toBeTruthy();
541
+ (0, globals_1.expect)(financialEntry).toHaveProperty('journal_id', journal.id);
542
+ }));
@@ -80,7 +80,7 @@ let consumer;
80
80
  (0, globals_1.test)('getConsumersByName', () => __awaiter(void 0, void 0, void 0, function* () {
81
81
  const consumersWithName = yield client.Consumers.getConsumersByName(consumerName);
82
82
  (0, globals_1.expect)(consumersWithName).toBeInstanceOf(Array);
83
- (0, globals_1.expect)(consumersWithName[0]).toHaveProperty('name', consumerName);
83
+ (0, globals_1.expect)(consumersWithName.some((consumer) => consumer.name.includes(consumerName))).toBe(true);
84
84
  }));
85
85
  (0, globals_1.test)('getConsumerById', () => __awaiter(void 0, void 0, void 0, function* () {
86
86
  const consumerWithId = yield client.Consumers.getConsumerById(consumer.consumerId);
@@ -61,8 +61,8 @@ let lightspeedConsumer;
61
61
  let orders;
62
62
  (0, globals_1.test)('getOrders', () => __awaiter(void 0, void 0, void 0, function* () {
63
63
  orders = yield lightspeedConsumer.pos.getOrders({
64
- date_from: '2022-08-11',
65
- date_to: '2022-08-12',
64
+ date_from: '2023-01-11',
65
+ date_to: '2023-02-28',
66
66
  });
67
67
  (0, globals_1.expect)(orders).toBeInstanceOf(Array);
68
68
  (0, globals_1.expect)(orders.length).toBeGreaterThan(0);
@@ -142,8 +142,8 @@ globals_1.test.skip('getCustomer', () => __awaiter(void 0, void 0, void 0, funct
142
142
  }));
143
143
  (0, globals_1.test)('getPayments', () => __awaiter(void 0, void 0, void 0, function* () {
144
144
  const payments = yield lightspeedConsumer.pos.getPayments({
145
- date_from: '2022-08-11',
146
- date_to: '2022-08-12',
145
+ date_from: '2023-01-11',
146
+ date_to: '2023-02-28',
147
147
  });
148
148
  (0, globals_1.expect)(payments).toBeInstanceOf(Array);
149
149
  (0, globals_1.expect)(payments.length).toBeGreaterThan(0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chift/chift-nodejs",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "The Chift NodeJS library provides convenient access to the Chift API from applications written in the NodeJS language (Javascript/Typescript).",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -358,14 +358,25 @@ const accountingFactory = {
358
358
  };
359
359
  },
360
360
  createFinancialEntry(
361
- financial_entry: components['schemas']['FinancialEntryItemIn']
361
+ financial_entry: components['schemas']['FinancialEntryItemIn'],
362
+ params: operations['accounting_create_financial_entry']['parameters']['query']
362
363
  ): RequestData<components['schemas']['FinancialEntryItemOut']> {
363
364
  return {
365
+ params,
364
366
  method: 'post',
365
367
  url: '/consumers/{consumer_id}/accounting/financial-entry',
366
368
  body: financial_entry,
367
369
  };
368
370
  },
371
+ createJournalEntry(
372
+ journal_entry: components['schemas']['JournalEntryIn']
373
+ ): RequestData<components['schemas']['JournalEntryMultiAnalyticPlan']> {
374
+ return {
375
+ method: 'post',
376
+ url: '/consumers/{consumer_id}/accounting/journal/entries',
377
+ body: journal_entry,
378
+ };
379
+ },
369
380
  };
370
381
 
371
382
  export { accountingFactory };
@@ -64,6 +64,10 @@ export interface paths {
64
64
  */
65
65
  get: operations['integrations_get_integrations'];
66
66
  };
67
+ '/integrations/{integrationid}/{image_type}.json': {
68
+ /** Returns a logo/icon of an integration (as base64) */
69
+ get: operations['integrations_get_integration_logo_json'];
70
+ };
67
71
  '/webhooks/list': {
68
72
  /**
69
73
  * Get list of possible webhooks
@@ -1946,7 +1950,7 @@ export interface components {
1946
1950
  account_number: string;
1947
1951
  /**
1948
1952
  * Partner Id
1949
- * @description Must be filled in it is a 'customer_account' or 'supplier_account' line type.
1953
+ * @description Must be filled in it is a 'customer_account', 'supplier_account' or 'employee_account' line type.
1950
1954
  */
1951
1955
  partner_id?: string;
1952
1956
  /**
@@ -1964,7 +1968,7 @@ export interface components {
1964
1968
  account_number: string;
1965
1969
  /**
1966
1970
  * Partner Id
1967
- * @description Must be filled in it is a 'customer_account' or 'supplier_account' line type.
1971
+ * @description Must be filled in it is a 'customer_account', 'supplier_account' or 'employee_account' line type.
1968
1972
  */
1969
1973
  partner_id?: string;
1970
1974
  /**
@@ -2078,6 +2082,12 @@ export interface components {
2078
2082
  /** Url */
2079
2083
  url: string;
2080
2084
  };
2085
+ /**
2086
+ * ImageType
2087
+ * @description An enumeration.
2088
+ * @enum {unknown}
2089
+ */
2090
+ ImageType: 'icon' | 'logo';
2081
2091
  /** IntegrationItem */
2082
2092
  IntegrationItem: {
2083
2093
  /** Integrationid */
@@ -2086,6 +2096,10 @@ export interface components {
2086
2096
  name: string;
2087
2097
  status: components['schemas']['app__routers__integrations__Status'];
2088
2098
  api: components['schemas']['Api'];
2099
+ /** Logo Url */
2100
+ logo_url: string;
2101
+ /** Icon Url */
2102
+ icon_url: string;
2089
2103
  /**
2090
2104
  * Credentials
2091
2105
  * @description List of credentials that must be specified to create a connection. Can be used if you want to pass credentials on connection creation. Not compatible with oAuth2 routes.
@@ -3115,6 +3129,13 @@ export interface components {
3115
3129
  /** Url */
3116
3130
  url: string;
3117
3131
  };
3132
+ /** LogoImage */
3133
+ LogoImage: {
3134
+ /** Integrationid */
3135
+ integrationid: string;
3136
+ /** Data */
3137
+ data: string;
3138
+ };
3118
3139
  /** MappingItem */
3119
3140
  MappingItem: {
3120
3141
  /** Source Id */
@@ -5817,6 +5838,35 @@ export interface operations {
5817
5838
  };
5818
5839
  };
5819
5840
  };
5841
+ /** Returns a logo/icon of an integration (as base64) */
5842
+ integrations_get_integration_logo_json: {
5843
+ parameters: {
5844
+ path: {
5845
+ integrationid: number;
5846
+ image_type: components['schemas']['ImageType'];
5847
+ };
5848
+ };
5849
+ responses: {
5850
+ /** @description Successful Response */
5851
+ 200: {
5852
+ content: {
5853
+ 'application/json': components['schemas']['LogoImage'];
5854
+ };
5855
+ };
5856
+ /** @description Not Found */
5857
+ 404: {
5858
+ content: {
5859
+ 'application/json': components['schemas']['ChiftError'];
5860
+ };
5861
+ };
5862
+ /** @description Validation Error */
5863
+ 422: {
5864
+ content: {
5865
+ 'application/json': components['schemas']['HTTPValidationError'];
5866
+ };
5867
+ };
5868
+ };
5869
+ };
5820
5870
  /**
5821
5871
  * Get list of possible webhooks
5822
5872
  * @description Returns a list of webhook that are available for your account
@@ -7944,6 +7994,10 @@ export interface operations {
7944
7994
  */
7945
7995
  accounting_create_financial_entry: {
7946
7996
  parameters: {
7997
+ query?: {
7998
+ /** @description Counterpart account number of the bank/cash journal. This will be retrieved from the accounting settings if left empty. */
7999
+ financial_counterpart_account?: string;
8000
+ };
7947
8001
  path: {
7948
8002
  consumer_id: string;
7949
8003
  };
@@ -40,6 +40,19 @@ test('getJournals', async () => {
40
40
  expect(journals[0]).toHaveProperty('journal_type', expect.any(String));
41
41
  });
42
42
 
43
+ let vatCodes: components['schemas']['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
+
43
56
  test('createClient', async () => {
44
57
  const body: components['schemas']['ClientItemIn'] = {
45
58
  external_reference: 'sdk test',
@@ -164,6 +177,16 @@ test('updateSupplier', async () => {
164
177
  });
165
178
 
166
179
  test('createInvoice', async () => {
180
+ const journal = journals.find((journal) => journal.journal_type === 'customer_invoice');
181
+ if (!journal) {
182
+ throw new Error('No journal with type "customer_invoice" found to create invoice');
183
+ }
184
+
185
+ const vatCode = vatCodes.find((vatCode) => vatCode.type === 'sale' && vatCode.rate === 21);
186
+ if (!vatCode?.id) {
187
+ throw new Error('No vat code with type "sale" and rate 21 found to create invoice');
188
+ }
189
+
167
190
  const body: components['schemas']['InvoiceItemInMonoAnalyticPlan'] = {
168
191
  invoice_type: 'customer_invoice',
169
192
  invoice_date: '2022-12-01',
@@ -173,7 +196,7 @@ test('createInvoice', async () => {
173
196
  tax_amount: 21,
174
197
  total: 121,
175
198
  partner_id: clients[0]?.id as string,
176
- journal_id: journals[0].id,
199
+ journal_id: journal.id,
177
200
  lines: [
178
201
  {
179
202
  description: 'Test',
@@ -184,7 +207,7 @@ test('createInvoice', async () => {
184
207
  tax_amount: 21,
185
208
  total: 121,
186
209
  account_number: '700000',
187
- tax_code: '1',
210
+ tax_code: vatCode.id,
188
211
  },
189
212
  ],
190
213
  };
@@ -243,6 +266,18 @@ test('getInvoice', async () => {
243
266
  });
244
267
 
245
268
  test('createInvoiceWithMultiplePlans', async () => {
269
+ const journal = journals.find((journal) => journal.journal_type === 'customer_invoice');
270
+ if (!journal) {
271
+ throw new Error(
272
+ 'No journal with type customer_invoice found to create Invoice With Multiple Plans'
273
+ );
274
+ }
275
+
276
+ const vatCode = vatCodes.find((vatCode) => vatCode.type === 'sale' && vatCode.rate === 21);
277
+ if (!vatCode?.id) {
278
+ throw new Error('No vat code with type "sale" and rate 21 found to create invoice');
279
+ }
280
+
246
281
  const body: components['schemas']['InvoiceItemInMonoAnalyticPlan'] = {
247
282
  invoice_type: 'customer_invoice',
248
283
  invoice_date: '2022-12-01',
@@ -252,7 +287,7 @@ test('createInvoiceWithMultiplePlans', async () => {
252
287
  tax_amount: 21,
253
288
  total: 121,
254
289
  partner_id: clients[0]?.id as string,
255
- journal_id: journals[0].id,
290
+ journal_id: journal.id,
256
291
  lines: [
257
292
  {
258
293
  description: 'Test',
@@ -263,7 +298,7 @@ test('createInvoiceWithMultiplePlans', async () => {
263
298
  tax_amount: 21,
264
299
  total: 121,
265
300
  account_number: '700000',
266
- tax_code: '1',
301
+ tax_code: vatCode.id,
267
302
  },
268
303
  ],
269
304
  };
@@ -374,6 +409,35 @@ test('getAnalyticLinesOfAccount', async () => {
374
409
  }
375
410
  });
376
411
 
412
+ test('createJournalEntry', async () => {
413
+ const journal = journals.find((journal) => journal.journal_type === 'customer_invoice');
414
+ if (!journal) {
415
+ throw new Error('No journal with type "customer_invoice" found to create journal entry');
416
+ }
417
+ const journalEntry = await consumer.accounting.createJournalEntry({
418
+ journal_id: journal.id,
419
+ name: Date.now().toString(),
420
+ date: '2022-01-01',
421
+ items: [
422
+ {
423
+ account_number: clients[0].account_number,
424
+ credit: 0,
425
+ debit: 10,
426
+ partner_id: clients[0].id,
427
+ currency: 'EUR',
428
+ },
429
+ {
430
+ account_number: '700000',
431
+ credit: 10,
432
+ debit: 0,
433
+ currency: 'EUR',
434
+ },
435
+ ],
436
+ });
437
+ expect(journalEntry).toBeTruthy();
438
+ expect(journalEntry).toHaveProperty('journal_id', journal.id);
439
+ });
440
+
377
441
  test('getJournalEntries', async () => {
378
442
  const journalEntries = await consumer.accounting.getJournalEntries({
379
443
  unposted_allowed: true,
@@ -399,18 +463,6 @@ test('getPaymentsByInvoiceId', async () => {
399
463
  expect(payments).toBeInstanceOf(Array);
400
464
  });
401
465
 
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
466
  let miscOperations: components['schemas']['MiscellaneousOperationOut'][];
415
467
  test('getMiscOperations', async () => {
416
468
  miscOperations = await consumer.accounting.getMiscOperations();
@@ -485,13 +537,48 @@ test('getBalanceOfAccounts', async () => {
485
537
  test('getEmployees', async () => {
486
538
  const employees = await consumer.accounting.getEmployees();
487
539
  expect(employees).toBeTruthy();
488
- expect(employees.items).toBeInstanceOf(Array);
489
540
  });
490
541
 
491
542
  test('getOutstandings', async () => {
492
- const outstandings = await consumer.accounting.getOutstandings({
493
- type: 'client',
543
+ expect.assertions(1);
544
+ try {
545
+ const outstandings = await consumer.accounting.getOutstandings({
546
+ type: 'client',
547
+ unposted_allowed: true,
548
+ });
549
+ expect(outstandings).toBeTruthy();
550
+ expect(outstandings.items).toBeInstanceOf(Array);
551
+ } catch (e: any) {
552
+ if (e?.error?.error_code) {
553
+ expect(e.error.error_code).toMatch('ERROR_API_RESOURCE_NOT_FOUND');
554
+ return;
555
+ }
556
+
557
+ throw e;
558
+ }
559
+ });
560
+
561
+ test('createFinancialEntry', async () => {
562
+ const journal = journals.find((journal) => journal.journal_type === 'financial_operation');
563
+ if (!journal) {
564
+ throw new Error(
565
+ 'No journal with type "financial_operation" found to create financial entry'
566
+ );
567
+ }
568
+
569
+ const financialEntry = await consumer.accounting.createFinancialEntry({
570
+ date: '2022-01-01',
571
+ journal_id: journal.id,
572
+ currency: 'EUR',
573
+ items: [
574
+ {
575
+ type: 'customer_account',
576
+ account_number: clients[0].account_number,
577
+ partner_id: clients[0].id,
578
+ amount: 10,
579
+ },
580
+ ],
494
581
  });
495
- expect(outstandings).toBeTruthy();
496
- expect(outstandings.items).toBeInstanceOf(Array);
582
+ expect(financialEntry).toBeTruthy();
583
+ expect(financialEntry).toHaveProperty('journal_id', journal.id);
497
584
  });
@@ -51,7 +51,9 @@ test('getConsumers', async () => {
51
51
  test('getConsumersByName', async () => {
52
52
  const consumersWithName = await client.Consumers.getConsumersByName(consumerName);
53
53
  expect(consumersWithName).toBeInstanceOf(Array);
54
- expect(consumersWithName[0]).toHaveProperty('name', consumerName);
54
+ expect(consumersWithName.some((consumer: any) => consumer.name.includes(consumerName))).toBe(
55
+ true
56
+ );
55
57
  });
56
58
 
57
59
  test('getConsumerById', async () => {