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