@@ -2,6 +2,7 @@ import { EmailApi } from '../src/api'
22import * as requests from '../src/model/requests/requests' ;
33import uuidv4 from 'uuid/v4' ;
44import * as models from '../src/model/model' ;
5+ import fs from 'fs' ;
56
67jasmine . 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 ;
0 commit comments