forked from XeroAPI/xero-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
attachments.integration.tests.ts
63 lines (51 loc) · 1.82 KB
/
attachments.integration.tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import * as fs from 'fs';
import * as path from 'path';
import { AccountingAPIClient } from '../AccountingAPIClient';
import { getOrCreateInvoiceId } from './helpers/entityId.helpers';
import { getPrivateConfig, setJestTimeout } from './helpers/integration.helpers';
describe('attachments', () => {
let xero: AccountingAPIClient;
let entityId: string;
const attachmentPath = path.resolve(__dirname, 'helpers', 'image.jpg');
const tempAttachmentPath = path.resolve(__dirname, 'temp-image.jpg');
beforeAll(async () => {
setJestTimeout();
const config = getPrivateConfig('1');
xero = new AccountingAPIClient(config);
entityId = await getOrCreateInvoiceId(xero);
});
it('can add an attachment', async () => {
await xero.invoices.attachments.uploadAttachment({
entityId: entityId,
mimeType: 'image/jpg',
fileName: 'anUploadedImage.jpg',
pathToUpload: attachmentPath
});
});
it('can download the same attachment', async () => {
await xero.invoices.attachments.downloadAttachment({
entityId: entityId,
mimeType: 'image/jpg',
fileName: 'anUploadedImage.jpg',
pathToSave: tempAttachmentPath
});
const tempFile = fs.statSync(tempAttachmentPath);
const realFile = fs.statSync(attachmentPath);
expect(tempFile.size).toBe(realFile.size);
});
it('get the attachment details', async () => {
const response = await xero.invoices.attachments.get({
entityId: entityId
});
expect(response.Attachments.length).toBeGreaterThan(0);
expect(response.Attachments.map((attachment) => attachment.FileName)).toContainEqual('anUploadedImage.jpg');
});
it('errors like this', async () => {
// TODO: This test
// TODO: Also make upload return a response
});
afterAll(async () => {
// delete the file
fs.unlinkSync(tempAttachmentPath);
});
});