Skip to content

Commit b467156

Browse files
committed
Tests splitted
1 parent cd35a5b commit b467156

File tree

9 files changed

+559
-480
lines changed

9 files changed

+559
-480
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules
22
package-lock.json
33
dist
44
.vscode
5-
.idea
5+
.idea
6+
.nyc_output

test/ai-test.ts

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import * as requests from '../src/model/requests/requests';
2+
import uuidv4 from 'uuid/v4';
3+
import * as models from '../src/model/model';
4+
import fs from 'fs';
5+
import 'mocha';
6+
import {expect} from 'chai';
7+
import {suiteBase} from "./suite-base";
8+
9+
10+
describe('AI tests', function () {
11+
let td = suiteBase(this);
12+
13+
it('Name gender detection #pipeline', async () => {
14+
const result = await td.api().aiNameGenderize(new requests.AiNameGenderizeRequest('John Cane'));
15+
expect(result.body.value.length).to.be.at.least(1);
16+
expect(result.body.value[0].gender).to.be.equal('Male');
17+
});
18+
19+
it('Name formatting #pipeline', async () => {
20+
const result = await td.api().aiNameFormat(new requests.AiNameFormatRequest(
21+
'Mr. John Michael Cane', undefined, undefined, undefined, undefined, '%t%L%f%m'));
22+
expect(result.body.name).to.be.equal('Mr. Cane J. M.');
23+
});
24+
25+
it('Name match #pipeline', async function () {
26+
const first = 'John Michael Cane';
27+
const second = 'Cane J.';
28+
const result = await td.api().aiNameMatch(new requests.AiNameMatchRequest(
29+
first, second));
30+
expect(result.body.similarity).to.be.at.least(0.5);
31+
});
32+
33+
it('Name expand #pipeline', async function () {
34+
const result = await td.api().aiNameExpand(new requests.AiNameExpandRequest(
35+
'Smith Bobby'));
36+
const names = result.body.names
37+
.map(weighted => weighted.name);
38+
expect(names).to.contain('Mr. Smith');
39+
expect(names).to.contain('B. Smith');
40+
});
41+
42+
it('Name complete #pipeline', async function () {
43+
const prefix = 'Dav';
44+
const result = await td.api().aiNameComplete(new requests.AiNameCompleteRequest(
45+
prefix));
46+
const names = result.body.names
47+
.map(weighted => prefix + weighted.name);
48+
expect(names).to.contain('David');
49+
expect(names).to.contain('Davis');
50+
expect(names).to.contain('Dave');
51+
});
52+
53+
it('Parse name from email address #pipeline', async function () {
54+
const result = await td.api().aiNameParseEmailAddress(new requests.AiNameParseEmailAddressRequest(
55+
'john-cane@gmail.com'));
56+
const extractedValues = result.body.value
57+
.map(extracted => extracted.name)
58+
.reduce((accumulator, value) => accumulator.concat(value));
59+
const givenName = extractedValues.find(extracted => extracted.category == 'GivenName');
60+
const surname = extractedValues.find(extracted => extracted.category == 'Surname');
61+
expect(givenName.value).to.be.equal('John');
62+
expect(surname.value).to.be.equal('Cane');
63+
});
64+
65+
it('Parse business card images to VCard contact files #aiBcr', async function () {
66+
const imageData = fs.readFileSync('test/td/test_single_0001.png');
67+
const storageFileName = uuidv4() + '.png';
68+
// 1) Upload business card image to storage
69+
await td.api().uploadFile(
70+
new requests.UploadFileRequest(td.folder() + '/' + storageFileName, imageData, td.storage()));
71+
const outFolder = uuidv4();
72+
const outFolderPath = td.folder() + '/' + outFolder;
73+
await td.api().createFolder(new requests.CreateFolderRequest(outFolderPath, td.storage()));
74+
// 2) Call business card recognition action
75+
const result = await td.api().aiBcrParseStorage(
76+
new requests.AiBcrParseStorageRequest(new models.AiBcrParseStorageRq(
77+
null,
78+
[new models.AiBcrImageStorageFile(
79+
true,
80+
new models.StorageFileLocation(td.storage(), td.folder(), storageFileName))],
81+
new models.StorageFolderLocation(td.storage(), outFolderPath))));
82+
//Check that only one file produced
83+
expect(result.body.value.length).to.be.equal(1);
84+
// 3) Get file name from recognition result
85+
const contactFile = result.body.value[0];
86+
// 4) Download VCard file, produced by recognition method, check it contains text "Thomas"
87+
const contactBinary = await td.api().downloadFile(new requests.DownloadFileRequest(
88+
contactFile.folderPath + '/' + contactFile.fileName, td.storage()));
89+
expect(contactBinary.body.toString()).to.contain('Thomas');
90+
// 5) Get VCard object properties list, check that there are 3 properties or more
91+
const contactProperties = await td.api().getContactProperties(new requests.GetContactPropertiesRequest(
92+
'vcard', contactFile.fileName, contactFile.folderPath, contactFile.storage));
93+
expect(contactProperties.body.internalProperties.length).to.be.at.least(3);
94+
});
95+
96+
it('Business card recognition without storage #aiBcr', async function () {
97+
const imageData = fs.readFileSync('test/td/test_single_0001.png').toString('base64');
98+
const result = await td.api().aiBcrParse(new requests.AiBcrParseRequest(
99+
new models.AiBcrBase64Rq(undefined, [new models.AiBcrBase64Image(true, imageData)])));
100+
expect(result.body.value.length).to.be.equal(1);
101+
const displayName = result.body.value[0].internalProperties
102+
.find(property => property.name == 'DISPLAYNAME') as models.PrimitiveObject;
103+
expect(displayName.value).to.contain("Thomas");
104+
});
105+
106+
it('Parse contact model from image #aiBcr', async function () {
107+
const imageData = fs.readFileSync('test/data/test_single_0001.png').toString('base64');
108+
const result = await td.api().aiBcrParseModel(new requests.AiBcrParseModelRequest(
109+
new models.AiBcrBase64Rq(undefined, [new models.AiBcrBase64Image(true, imageData)])));
110+
expect(result.body.value.length).to.be.equal(1);
111+
expect(result.body.value[0].displayName).to.contain("Thomas");
112+
});
113+
});

0 commit comments

Comments
 (0)