Skip to content

Commit ecbf2ad

Browse files
committed
File upload corrected. AiBcrParseStorage test implemented
1 parent 877896c commit ecbf2ad

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

src/api.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3656,7 +3656,12 @@ export class EmailApi {
36563656
let useFormData = false;
36573657

36583658
if (requestObj.file !== undefined) {
3659-
formParams.File = requestObj.file;
3659+
formParams.File = {
3660+
value: requestObj.file,
3661+
options: {
3662+
filename: 'File'
3663+
}
3664+
};
36603665
}
36613666
useFormData = true;
36623667

src/internal/object-serializer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export class ObjectSerializer {
4444
* Serilize object to json string.
4545
*/
4646
public static serialize(data: any, type: string) {
47-
if (data === undefined) {
48-
return data;
47+
if (data == null) {
48+
return undefined;
4949
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
5050
return data;
5151
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6

src/model/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ export class EmailAccountRequest {
12291229
public login: string;
12301230

12311231
/**
1232-
* Enum, available values: None, SSLExplicit, SSLImplicit, SSLAuto, Auto
1232+
* Security mode for a mail client Enum, available values: None, SSLExplicit, SSLImplicit, SSLAuto, Auto
12331233
*/
12341234
public securityOptions: string;
12351235

tests/api-test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { EmailApi } from '../src/api'
22
import * as requests from '../src/model/requests/requests';
33
import uuidv4 from 'uuid/v4';
44
import * as models from '../src/model/model';
5+
import fs from 'fs';
56

67
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
78

@@ -46,6 +47,8 @@ describe('EmailApi', function() {
4647
var downloaded = await api.downloadFile(new requests.DownloadFileRequest(path, storage));
4748
var calendarRaw = downloaded.body.toString()
4849
expect(calendarRaw).toContain('Organizer')
50+
calendarFile = uuidv4() + '.ics'
51+
path = folder + '/' + calendarFile;
4952
await api.uploadFile(new requests.UploadFileRequest(path, downloaded.body, storage));
5053
var exist = await api.objectExists(new requests.ObjectExistsRequest(path, storage));
5154
expect(exist.body.exists).toBeTrue();
@@ -90,6 +93,36 @@ describe('EmailApi', function() {
9093
expect(factStartDate).toEqual(startDate);
9194
});
9295

96+
it('Parse business card images to VCard contact files #wip', async function() {
97+
var imageData = fs.readFileSync('tests/data/test_single_0001.png');
98+
var storageFileName = uuidv4() + '.png';
99+
// 1) Upload business card image to storage
100+
await api.uploadFile(new requests.UploadFileRequest(folder + '/' + storageFileName, imageData, storage));
101+
var outFolder = uuidv4();
102+
var outFolderPath = folder + '/' + outFolder;
103+
await api.createFolder(new requests.CreateFolderRequest(outFolderPath, storage));
104+
// 2) Call business card recognition action
105+
var result = await api.aiBcrParseStorage(
106+
new requests.AiBcrParseStorageRequest(new models.AiBcrParseStorageRq(
107+
null,
108+
[new models.AiBcrImageStorageFile(
109+
true,
110+
new models.StorageFileLocation(storage, folder, storageFileName))],
111+
new models.StorageFolderLocation(storage, outFolder))));
112+
//Check that only one file produced
113+
expect(result.body.value.length).toBe(1);
114+
// 3) Get file name from recognition result
115+
var contactFile = result.body.value[0];
116+
// 4) Download VCard file, produced by recognition method, check it contains text "Thomas"
117+
var contactBinary = await api.downloadFile(new requests.DownloadFileRequest(
118+
contactFile.folderPath + '/' + contactFile.fileName, storage));
119+
expect(contactBinary.body.toString()).toContain('Thomas');
120+
// 5) Get VCard object properties list, check that there are 3 properties or more
121+
var contactProperties = await api.getContactProperties(new requests.GetContactPropertiesRequest(
122+
'vcard', contactFile.fileName, contactFile.folderPath, contactFile.storage));
123+
expect(contactProperties.body.internalProperties.length).toBeGreaterThanOrEqual(3);
124+
});
125+
93126
async function createCalendar(startDate? : Date) :Promise<string> {
94127
var fileName = uuidv4() + '.ics';
95128
startDate = (startDate == null) ? getDate(undefined, 1) : startDate;

tests/data/test_single_0001.png

163 KB
Loading

0 commit comments

Comments
 (0)