groupdocs-parser-cloud 25.9.0 → 26.2.0

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.
Files changed (48) hide show
  1. package/lib/{model.d.ts → src/model.d.ts} +37 -0
  2. package/lib/{model.js → src/model.js} +38 -2
  3. package/lib/{package_version.js → src/package_version.js} +1 -1
  4. package/lib/{parser_api.d.ts → src/parser_api.d.ts} +5 -0
  5. package/lib/{parser_api.js → src/parser_api.js} +27 -0
  6. package/lib/test/api/test_auth_api.d.ts +1 -0
  7. package/lib/test/api/test_auth_api.js +45 -0
  8. package/lib/test/api/test_barcode_api.d.ts +1 -0
  9. package/lib/test/api/test_barcode_api.js +64 -0
  10. package/lib/test/api/test_file_api.d.ts +1 -0
  11. package/lib/test/api/test_file_api.js +95 -0
  12. package/lib/test/api/test_folder_api.d.ts +1 -0
  13. package/lib/test/api/test_folder_api.js +84 -0
  14. package/lib/test/api/test_formats_api.d.ts +1 -0
  15. package/lib/test/api/test_formats_api.js +60 -0
  16. package/lib/test/api/test_parser_container_api.d.ts +1 -0
  17. package/lib/test/api/test_parser_container_api.js +134 -0
  18. package/lib/test/api/test_parser_image_api.d.ts +1 -0
  19. package/lib/test/api/test_parser_image_api.js +179 -0
  20. package/lib/test/api/test_parser_info_api.d.ts +1 -0
  21. package/lib/test/api/test_parser_info_api.js +112 -0
  22. package/lib/test/api/test_parser_parse_api.d.ts +1 -0
  23. package/lib/test/api/test_parser_parse_api.js +184 -0
  24. package/lib/test/api/test_parser_template_api.d.ts +1 -0
  25. package/lib/test/api/test_parser_template_api.js +168 -0
  26. package/lib/test/api/test_parser_text_api.d.ts +1 -0
  27. package/lib/test/api/test_parser_text_api.js +180 -0
  28. package/lib/test/api/test_storage_api.d.ts +1 -0
  29. package/lib/test/api/test_storage_api.js +76 -0
  30. package/lib/test/test_context.d.ts +30 -0
  31. package/lib/test/test_context.js +156 -0
  32. package/lib/test/test_coverage.d.ts +1 -0
  33. package/lib/test/test_coverage.js +77 -0
  34. package/lib/test/test_file.d.ts +50 -0
  35. package/lib/test/test_file.js +92 -0
  36. package/lib/tsconfig.tsbuildinfo +1 -1
  37. package/package.json +3 -3
  38. /package/lib/{api_client.d.ts → src/api_client.d.ts} +0 -0
  39. /package/lib/{api_client.js → src/api_client.js} +0 -0
  40. /package/lib/{api_error.d.ts → src/api_error.d.ts} +0 -0
  41. /package/lib/{api_error.js → src/api_error.js} +0 -0
  42. /package/lib/{auth.d.ts → src/auth.d.ts} +0 -0
  43. /package/lib/{auth.js → src/auth.js} +0 -0
  44. /package/lib/{configuration.d.ts → src/configuration.d.ts} +0 -0
  45. /package/lib/{configuration.js → src/configuration.js} +0 -0
  46. /package/lib/{package_version.d.ts → src/package_version.d.ts} +0 -0
  47. /package/lib/{serializer.d.ts → src/serializer.d.ts} +0 -0
  48. /package/lib/{serializer.js → src/serializer.js} +0 -0
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ // --------------------------------------------------------------------------------------------------------------------
3
+ // <copyright company="Aspose Pty Ltd">
4
+ // Copyright (c) Aspose Pty Ltd
5
+ // </copyright>
6
+ // <summary>
7
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ // of this software and associated documentation files (the "Software"), to deal
9
+ // in the Software without restriction, including without limitation the rights
10
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ // copies of the Software, and to permit persons to whom the Software is
12
+ // furnished to do so, subject to the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be included in all
15
+ // copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ // SOFTWARE.
24
+ // </summary>
25
+ // --------------------------------------------------------------------------------------------------------------------
26
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const chai_1 = require("chai");
37
+ require("mocha");
38
+ const model_1 = require("../../src/model");
39
+ const TestContext = require("../test_context");
40
+ const test_file_1 = require("../test_file");
41
+ describe("test_parser_container_api", () => {
42
+ before(() => __awaiter(void 0, void 0, void 0, function* () {
43
+ yield TestContext.uploadTestFiles();
44
+ }));
45
+ afterEach(function () {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ yield TestContext.cleanupTempFiles();
48
+ });
49
+ });
50
+ describe("TestInfoApi", () => {
51
+ it("TestGetContainerItemInfo", () => {
52
+ const containerOptions = new model_1.ContainerOptions();
53
+ containerOptions.fileInfo = test_file_1.TestFile.Zip.ToFileInfo();
54
+ const request = new model_1.ContainerRequest(containerOptions);
55
+ return TestContext.getInfoApi().container(request)
56
+ .then((result) => {
57
+ (0, chai_1.expect)(result).not.to.be.null;
58
+ (0, chai_1.expect)(result.containerItems).not.to.be.empty;
59
+ (0, chai_1.expect)(result.containerItems.length).equal(2);
60
+ var names = [
61
+ "one-page.docx", "four-pages.docx"
62
+ ];
63
+ result.containerItems.forEach((item) => {
64
+ (0, chai_1.expect)(names.some(x => item.name.includes(x))).to.be.true;
65
+ });
66
+ });
67
+ });
68
+ it("TestGetContainerItemInfo_rar", () => {
69
+ const containerOptions = new model_1.ContainerOptions();
70
+ containerOptions.fileInfo = test_file_1.TestFile.Rar.ToFileInfo();
71
+ const request = new model_1.ContainerRequest(containerOptions);
72
+ return TestContext.getInfoApi().container(request)
73
+ .then((result) => {
74
+ (0, chai_1.expect)(result).not.to.be.null;
75
+ (0, chai_1.expect)(result.containerItems).not.to.be.empty;
76
+ (0, chai_1.expect)(result.containerItems.length).equal(2);
77
+ var names = [
78
+ "sample.docx", "sample.pdf"
79
+ ];
80
+ result.containerItems.forEach((item) => {
81
+ (0, chai_1.expect)(names.some(x => item.name.includes(x))).to.be.true;
82
+ });
83
+ });
84
+ });
85
+ it("TestGetContainerItemInfo_tar", () => {
86
+ const containerOptions = new model_1.ContainerOptions();
87
+ containerOptions.fileInfo = test_file_1.TestFile.Tar.ToFileInfo();
88
+ const request = new model_1.ContainerRequest(containerOptions);
89
+ return TestContext.getInfoApi().container(request)
90
+ .then((result) => {
91
+ (0, chai_1.expect)(result).not.to.be.null;
92
+ (0, chai_1.expect)(result.containerItems).not.to.be.empty;
93
+ (0, chai_1.expect)(result.containerItems.length).equal(5);
94
+ var names = [
95
+ "sample.docx", "sample.pdf", "1200px-RedPandaFullBody.JPG", "images.pdf", "th.jpg"
96
+ ];
97
+ result.containerItems.forEach((item) => {
98
+ (0, chai_1.expect)(names.some(x => item.name.includes(x))).to.be.true;
99
+ });
100
+ });
101
+ });
102
+ it("TestGetContainerItemInfo_FileNotFoundResult", () => {
103
+ const containerOptions = new model_1.ContainerOptions();
104
+ containerOptions.fileInfo = test_file_1.TestFile.NotExist.ToFileInfo();
105
+ const request = new model_1.ContainerRequest(containerOptions);
106
+ try {
107
+ TestContext.getInfoApi().container(request);
108
+ }
109
+ catch (e) {
110
+ (0, chai_1.expect)(e.message).equal("Can\'t find file located at \'folder/file-not-exist.pdf\'.");
111
+ }
112
+ });
113
+ it("GetContainerItemsInfo_UnsupportedFileType", () => {
114
+ const containerOptions = new model_1.ContainerOptions();
115
+ containerOptions.fileInfo = test_file_1.TestFile.Video.ToFileInfo();
116
+ const request = new model_1.ContainerRequest(containerOptions);
117
+ try {
118
+ TestContext.getInfoApi().container(request);
119
+ }
120
+ catch (e) {
121
+ (0, chai_1.expect)(e.message).equal("Password provided for file \'video/avi/sample.avi\' is incorrect.");
122
+ }
123
+ });
124
+ it("GetContainerItemsInfo_WithoutOptions", () => {
125
+ const request = new model_1.ContainerRequest(null);
126
+ try {
127
+ TestContext.getInfoApi().container(request);
128
+ }
129
+ catch (e) {
130
+ (0, chai_1.expect)(e.message).equal('Required parameter "requestObj" was null or undefined when calling container.');
131
+ }
132
+ });
133
+ });
134
+ });
@@ -0,0 +1 @@
1
+ import "mocha";
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ // --------------------------------------------------------------------------------------------------------------------
3
+ // <copyright company="Aspose Pty Ltd">
4
+ // Copyright (c) Aspose Pty Ltd
5
+ // </copyright>
6
+ // <summary>
7
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ // of this software and associated documentation files (the "Software"), to deal
9
+ // in the Software without restriction, including without limitation the rights
10
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ // copies of the Software, and to permit persons to whom the Software is
12
+ // furnished to do so, subject to the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be included in all
15
+ // copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ // SOFTWARE.
24
+ // </summary>
25
+ // --------------------------------------------------------------------------------------------------------------------
26
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const chai_1 = require("chai");
37
+ require("mocha");
38
+ const model_1 = require("../../src/model");
39
+ const TestContext = require("../test_context");
40
+ const test_file_1 = require("../test_file");
41
+ describe("test_parser_image_api", () => {
42
+ before(() => __awaiter(void 0, void 0, void 0, function* () {
43
+ yield TestContext.uploadTestFiles();
44
+ }));
45
+ afterEach(function () {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ yield TestContext.cleanupTempFiles();
48
+ });
49
+ });
50
+ describe("TestImageApi", () => {
51
+ it("TestGetImage_Docx", () => {
52
+ const imageOptions = new model_1.ImagesOptions();
53
+ imageOptions.fileInfo = test_file_1.TestFile.PasswordProtected.ToFileInfo();
54
+ const request = new model_1.ImagesRequest(imageOptions);
55
+ return TestContext.getParseApi().images(request)
56
+ .then((result) => {
57
+ (0, chai_1.expect)(result).not.to.be.null;
58
+ result.images.forEach((image) => {
59
+ (0, chai_1.expect)(image.path).to.have.string("parser/images/words/docx/four-pages_docx/image_{i}.jpeg");
60
+ (0, chai_1.expect)(image.downloadUrl).not.to.be.null;
61
+ });
62
+ });
63
+ });
64
+ it("TestGetImage_Container", () => {
65
+ const imageOptions = new model_1.ImagesOptions();
66
+ imageOptions.fileInfo = test_file_1.TestFile.ZipWithEmailImagePdf.ToFileInfo();
67
+ const request = new model_1.ImagesRequest(imageOptions);
68
+ return TestContext.getParseApi().images(request)
69
+ .then((result) => {
70
+ (0, chai_1.expect)(result).not.to.be.null;
71
+ var paths = [
72
+ "containers/archive/zip-eml-jpg-pdf_zip/",
73
+ "containers/archive/zip-eml-jpg-pdf_zip/embedded-image-and-attachment_eml/",
74
+ "containers/archive/zip-eml-jpg-pdf_zip/template-document_pdf/"
75
+ ];
76
+ result.images.forEach((image) => {
77
+ (0, chai_1.expect)(paths.some(x => image.path.includes(x))).to.be.true;
78
+ (0, chai_1.expect)(image.downloadUrl).not.to.be.null;
79
+ });
80
+ });
81
+ });
82
+ it("TestGetImage_Email", () => {
83
+ const imageOptions = new model_1.ImagesOptions();
84
+ imageOptions.fileInfo = test_file_1.TestFile.ImageAndAttachment.ToFileInfo();
85
+ const request = new model_1.ImagesRequest(imageOptions);
86
+ return TestContext.getParseApi().images(request)
87
+ .then((result) => {
88
+ (0, chai_1.expect)(result).not.to.be.null;
89
+ var paths = [
90
+ "parser/images/email/eml/embedded-image-and-attachment_eml/"
91
+ ];
92
+ result.images.forEach((image) => {
93
+ (0, chai_1.expect)(paths.some(x => image.path.includes(x))).to.be.true;
94
+ (0, chai_1.expect)(image.downloadUrl).not.to.be.null;
95
+ });
96
+ });
97
+ });
98
+ it("TestGetImage_Pdf_FromPages", () => {
99
+ const imageOptions = new model_1.ImagesOptions();
100
+ imageOptions.fileInfo = test_file_1.TestFile.Pdf.ToFileInfo();
101
+ imageOptions.startPageNumber = 1;
102
+ imageOptions.countPagesToExtract = 2;
103
+ const request = new model_1.ImagesRequest(imageOptions);
104
+ return TestContext.getParseApi().images(request)
105
+ .then((result) => {
106
+ (0, chai_1.expect)(result).not.to.be.null;
107
+ (0, chai_1.expect)(result.pages).not.to.be.empty;
108
+ (0, chai_1.expect)(result.pages.length).equal(2);
109
+ (0, chai_1.expect)(result.pages[0].images[0].path).equal("parser/images/pdf/template-document_pdf/page_1/image_0.jpeg");
110
+ (0, chai_1.expect)(result.pages[1].images[0].path).equal("parser/images/pdf/template-document_pdf/page_2/image_0.jpeg");
111
+ });
112
+ });
113
+ it("ImageExtractTest_Pdf_ContainerItem_FromPages", () => {
114
+ const imageOptions = new model_1.ImagesOptions();
115
+ imageOptions.fileInfo = test_file_1.TestFile.PdfContainer.ToFileInfo();
116
+ imageOptions.startPageNumber = 1;
117
+ imageOptions.countPagesToExtract = 2;
118
+ imageOptions.containerItemInfo = new model_1.ContainerItemInfo({ relativePath: "template-document.pdf" });
119
+ const request = new model_1.ImagesRequest(imageOptions);
120
+ return TestContext.getParseApi().images(request)
121
+ .then((result) => {
122
+ (0, chai_1.expect)(result).not.to.be.null;
123
+ (0, chai_1.expect)(result.pages).not.to.be.empty;
124
+ (0, chai_1.expect)(result.pages.length).equal(2);
125
+ (0, chai_1.expect)(result.pages[0].images[0].path).equal("parser/images/template-document_pdf/page_1/image_0.jpeg");
126
+ (0, chai_1.expect)(result.pages[1].images[0].path).equal("parser/images/template-document_pdf/page_2/image_0.jpeg");
127
+ });
128
+ });
129
+ it("ImageExtractTest_Pdf_FromPages_OutOfThePageRange", () => {
130
+ const imageOptions = new model_1.ImagesOptions();
131
+ imageOptions.fileInfo = test_file_1.TestFile.Pdf.ToFileInfo();
132
+ imageOptions.startPageNumber = 3;
133
+ imageOptions.countPagesToExtract = 5;
134
+ const request = new model_1.ImagesRequest(imageOptions);
135
+ try {
136
+ TestContext.getParseApi().images(request);
137
+ }
138
+ catch (error) {
139
+ (0, chai_1.expect)(error.message).equal("Request parameters missing or have incorrect format");
140
+ }
141
+ });
142
+ it("ImageExtractTest_Pdf_Container_FromPages_Error", () => {
143
+ const imageOptions = new model_1.ImagesOptions();
144
+ imageOptions.fileInfo = test_file_1.TestFile.Zip.ToFileInfo();
145
+ imageOptions.startPageNumber = 3;
146
+ imageOptions.countPagesToExtract = 5;
147
+ const request = new model_1.ImagesRequest(imageOptions);
148
+ try {
149
+ TestContext.getParseApi().images(request);
150
+ }
151
+ catch (error) {
152
+ (0, chai_1.expect)(error.message).equal("The specified file \'containers/archive/docx.zip\' has type which is not currently supported.");
153
+ }
154
+ });
155
+ it("TestGetImage_FileNotFoundResult", () => {
156
+ const imageOptions = new model_1.ImagesOptions();
157
+ imageOptions.fileInfo = test_file_1.TestFile.NotExist.ToFileInfo();
158
+ const request = new model_1.ImagesRequest(imageOptions);
159
+ try {
160
+ TestContext.getParseApi().images(request);
161
+ }
162
+ catch (error) {
163
+ (0, chai_1.expect)(error.message).equal("Can\'t find file located at \'folder/file-not-exist.pdf\'.");
164
+ }
165
+ });
166
+ it("TestGetImage_IncorrectPassword", () => {
167
+ const imageOptions = new model_1.ImagesOptions();
168
+ imageOptions.fileInfo = test_file_1.TestFile.PasswordProtected.ToFileInfo();
169
+ imageOptions.fileInfo.password = "123";
170
+ const request = new model_1.ImagesRequest(imageOptions);
171
+ try {
172
+ TestContext.getParseApi().images(request);
173
+ }
174
+ catch (error) {
175
+ (0, chai_1.expect)(error.message).equal("Password provided for file \'words/docx/password-protected.docx\' is incorrect.");
176
+ }
177
+ });
178
+ });
179
+ });
@@ -0,0 +1 @@
1
+ import "mocha";
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ // --------------------------------------------------------------------------------------------------------------------
3
+ // <copyright company="Aspose Pty Ltd">
4
+ // Copyright (c) Aspose Pty Ltd
5
+ // </copyright>
6
+ // <summary>
7
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ // of this software and associated documentation files (the "Software"), to deal
9
+ // in the Software without restriction, including without limitation the rights
10
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ // copies of the Software, and to permit persons to whom the Software is
12
+ // furnished to do so, subject to the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be included in all
15
+ // copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ // SOFTWARE.
24
+ // </summary>
25
+ // --------------------------------------------------------------------------------------------------------------------
26
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const chai_1 = require("chai");
37
+ require("mocha");
38
+ const model_1 = require("../../src/model");
39
+ const TestContext = require("../test_context");
40
+ const test_file_1 = require("../test_file");
41
+ describe("test_parser_info_api", () => {
42
+ before(() => __awaiter(void 0, void 0, void 0, function* () {
43
+ yield TestContext.uploadTestFiles();
44
+ }));
45
+ afterEach(function () {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ yield TestContext.cleanupTempFiles();
48
+ });
49
+ });
50
+ describe("TestInfoApi", () => {
51
+ it("TestGetInfo_Txt", () => {
52
+ const infoOptions = new model_1.InfoOptions();
53
+ infoOptions.fileInfo = test_file_1.TestFile.EncodingDetection.ToFileInfo();
54
+ const request = new model_1.GetInfoRequest(infoOptions);
55
+ return TestContext.getInfoApi().getInfo(request)
56
+ .then((result) => {
57
+ (0, chai_1.expect)(result).not.to.be.null;
58
+ (0, chai_1.expect)(result.fileType.fileFormat.toUpperCase()).to.have.string("PLAIN TEXT FILE");
59
+ (0, chai_1.expect)(result.pageCount).equal(1);
60
+ });
61
+ });
62
+ it("TestGetInfo_Docx", () => {
63
+ const infoOptions = new model_1.InfoOptions();
64
+ infoOptions.fileInfo = test_file_1.TestFile.FourPages.ToFileInfo();
65
+ const request = new model_1.GetInfoRequest(infoOptions);
66
+ return TestContext.getInfoApi().getInfo(request)
67
+ .then((result) => {
68
+ (0, chai_1.expect)(result).not.to.be.null;
69
+ (0, chai_1.expect)(result.fileType.fileFormat.toUpperCase()).to.have.string("MICROSOFT WORD OPEN XML DOCUMENT"
70
+ .toUpperCase());
71
+ (0, chai_1.expect)(result.pageCount).equal(4);
72
+ });
73
+ });
74
+ it("TestGetInfo_ContainerItem", () => {
75
+ const infoOptions = new model_1.InfoOptions();
76
+ infoOptions.fileInfo = test_file_1.TestFile.Zip.ToFileInfo();
77
+ let containerItemInfo = new model_1.ContainerItemInfo();
78
+ containerItemInfo.relativePath = "one-page.docx";
79
+ infoOptions.containerItemInfo = containerItemInfo;
80
+ const request = new model_1.GetInfoRequest(infoOptions);
81
+ return TestContext.getInfoApi().getInfo(request)
82
+ .then((result) => {
83
+ (0, chai_1.expect)(result).not.to.be.null;
84
+ (0, chai_1.expect)(result.fileType.fileFormat.toUpperCase()).to.have.string("MICROSOFT WORD OPEN XML DOCUMENT");
85
+ (0, chai_1.expect)(result.pageCount).equal(1);
86
+ });
87
+ });
88
+ it("TestGetInfo_FileNotFoundResult", () => {
89
+ const infoOptions = new model_1.InfoOptions();
90
+ infoOptions.fileInfo = test_file_1.TestFile.NotExist.ToFileInfo();
91
+ const request = new model_1.GetInfoRequest(infoOptions);
92
+ try {
93
+ TestContext.getInfoApi().getInfo(request);
94
+ }
95
+ catch (error) {
96
+ (0, chai_1.expect)(error.message).equal("Can\'t find file located at \'folder/file-not-exist.pdf\'.");
97
+ }
98
+ });
99
+ it("TestGetInfo_IncorrectPassword", () => {
100
+ const infoOptions = new model_1.InfoOptions();
101
+ infoOptions.fileInfo = test_file_1.TestFile.PasswordProtected.ToFileInfo();
102
+ infoOptions.fileInfo.password = "123";
103
+ const request = new model_1.GetInfoRequest(infoOptions);
104
+ try {
105
+ TestContext.getInfoApi().getInfo(request);
106
+ }
107
+ catch (error) {
108
+ (0, chai_1.expect)(error.message).equal("Password provided for file \'words/docx/password-protected.docx\' is incorrect.");
109
+ }
110
+ });
111
+ });
112
+ });
@@ -0,0 +1 @@
1
+ import "mocha";
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ // --------------------------------------------------------------------------------------------------------------------
3
+ // <copyright company="Aspose Pty Ltd">
4
+ // Copyright (c) Aspose Pty Ltd
5
+ // </copyright>
6
+ // <summary>
7
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ // of this software and associated documentation files (the "Software"), to deal
9
+ // in the Software without restriction, including without limitation the rights
10
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ // copies of the Software, and to permit persons to whom the Software is
12
+ // furnished to do so, subject to the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be included in all
15
+ // copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ // SOFTWARE.
24
+ // </summary>
25
+ // --------------------------------------------------------------------------------------------------------------------
26
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const chai_1 = require("chai");
37
+ require("mocha");
38
+ const model_1 = require("../../src/model");
39
+ const TestContext = require("../test_context");
40
+ const test_file_1 = require("../test_file");
41
+ const model_2 = require("../../src/model");
42
+ describe("test_parser_parse_api", () => {
43
+ before(() => __awaiter(void 0, void 0, void 0, function* () {
44
+ yield TestContext.uploadTestFiles();
45
+ }));
46
+ afterEach(function () {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ yield TestContext.cleanupTempFiles();
49
+ });
50
+ });
51
+ describe("TestParseApi", () => {
52
+ it("TestParseDocument_SavedTemplate", () => __awaiter(void 0, void 0, void 0, function* () {
53
+ const templatePath = "templates/document-template.json";
54
+ const template = new model_1.CreateTemplateOptions();
55
+ template.template = Setup.getTemplate();
56
+ template.templatePath = templatePath;
57
+ const templateRequest = new model_1.CreateTemplateRequest(template);
58
+ var templateResult = yield TestContext.getTemplateApi().createTemplate(templateRequest);
59
+ (0, chai_1.expect)(templateResult).not.to.be.null;
60
+ const parseOptions = new model_1.ParseOptions();
61
+ parseOptions.fileInfo = test_file_1.TestFile.TemplateDocumentDocx.ToFileInfo();
62
+ parseOptions.templatePath = templatePath;
63
+ const request = new model_1.ParseRequest(parseOptions);
64
+ return TestContext.getParseApi().parse(request)
65
+ .then((result) => {
66
+ (0, chai_1.expect)(result).not.to.be.null;
67
+ (0, chai_1.expect)(result.fieldsData).not.to.be.empty;
68
+ (0, chai_1.expect)(result.count).equal(1);
69
+ });
70
+ }));
71
+ it("TestParseDocument_RawTemplate", () => __awaiter(void 0, void 0, void 0, function* () {
72
+ const parseOptions = new model_1.ParseOptions();
73
+ parseOptions.fileInfo = test_file_1.TestFile.TemplateDocumentDocx.ToFileInfo();
74
+ parseOptions.template = Setup.getTemplate();
75
+ const request = new model_1.ParseRequest(parseOptions);
76
+ return TestContext.getParseApi().parse(request)
77
+ .then((result) => {
78
+ (0, chai_1.expect)(result).not.to.be.null;
79
+ (0, chai_1.expect)(result.fieldsData).not.to.be.empty;
80
+ (0, chai_1.expect)(result.count).equal(1);
81
+ });
82
+ }));
83
+ it("TestParseDocument_FileNotFoundResult", () => {
84
+ const parseOptions = new model_1.ParseOptions();
85
+ parseOptions.fileInfo = test_file_1.TestFile.NotExist.ToFileInfo();
86
+ parseOptions.template = Setup.getTemplate();
87
+ const request = new model_1.ParseRequest(parseOptions);
88
+ try {
89
+ TestContext.getParseApi().parse(request);
90
+ }
91
+ catch (error) {
92
+ (0, chai_1.expect)(error.message).equal("Can\'t find file located at \'folder/file-not-exist.pdf\'.");
93
+ }
94
+ });
95
+ });
96
+ it("TestParseDocument_WithoutOptions", () => {
97
+ const parseOptions = new model_1.ParseOptions();
98
+ parseOptions.fileInfo = test_file_1.TestFile.JpegFile.ToFileInfo();
99
+ const request = new model_1.ParseRequest(parseOptions);
100
+ try {
101
+ TestContext.getParseApi().parse(request);
102
+ }
103
+ catch (error) {
104
+ (0, chai_1.expect)(error.message).equal("Request parameters missing or have incorrect format");
105
+ }
106
+ });
107
+ it("TestParseDocument_NotSupportedFile", () => {
108
+ const parseOptions = new model_1.ParseOptions();
109
+ parseOptions.fileInfo = test_file_1.TestFile.JpegFile.ToFileInfo();
110
+ parseOptions.templatePath = "templates/document-template.json";
111
+ parseOptions.template = Setup.getTemplate();
112
+ const request = new model_1.ParseRequest(parseOptions);
113
+ try {
114
+ TestContext.getParseApi().parse(request);
115
+ }
116
+ catch (error) {
117
+ (0, chai_1.expect)(error.message).equal("The specified file \'image/jpeg/document.jpeg\' has type which is not currently supported.");
118
+ }
119
+ });
120
+ it("TestParseDocument_IncorrectPassword", () => {
121
+ const parseOptions = new model_1.ParseOptions();
122
+ parseOptions.fileInfo = test_file_1.TestFile.PasswordProtected.ToFileInfo();
123
+ parseOptions.fileInfo.password = "123";
124
+ parseOptions.templatePath = "templates/document-template.json";
125
+ parseOptions.template = Setup.getTemplate();
126
+ const request = new model_1.ParseRequest(parseOptions);
127
+ try {
128
+ TestContext.getParseApi().parse(request);
129
+ }
130
+ catch (error) {
131
+ (0, chai_1.expect)(error.message).equal("Password provided for file \'words/docx/password-protected.docx\' is incorrect.");
132
+ }
133
+ });
134
+ });
135
+ it("TestAIParse", () => __awaiter(void 0, void 0, void 0, function* () {
136
+ const aiOptions = new model_1.AIParseOptions();
137
+ aiOptions.fileInfo = test_file_1.TestFile.Invoice.ToFileInfo();
138
+ aiOptions.template = {
139
+ InvoiceNum: "",
140
+ Date: "",
141
+ Email: ""
142
+ };
143
+ const request = new model_1.AIParseRequest(aiOptions);
144
+ const result = yield TestContext.getParseApi().aIParse(request);
145
+ (0, chai_1.expect)(result).to.not.be.null;
146
+ const invoiceNum = result["InvoiceNum"];
147
+ (0, chai_1.expect)(invoiceNum).to.not.be.undefined;
148
+ }));
149
+ class Setup {
150
+ static getTemplate() {
151
+ var options = new model_1.Template();
152
+ const field1 = new model_2.Field();
153
+ field1.fieldName = "Field1";
154
+ field1.pageIndex = 4;
155
+ field1.fieldPosition = new model_2.FieldPosition();
156
+ field1.fieldPosition.fieldPositionType = "Fixed";
157
+ field1.fieldPosition.rectangle = new model_2.Rectangle({ size: new model_1.Size({ height: 30, width: 140 }), position: new model_1.Point({ x: 0, y: 0 }) });
158
+ const field2 = new model_2.Field();
159
+ field2.fieldName = "RelatedField2";
160
+ field2.fieldPosition = new model_2.FieldPosition();
161
+ field2.fieldPosition.fieldPositionType = "Linked";
162
+ field2.fieldPosition.linkedFieldName = "Field1";
163
+ field2.fieldPosition.isBottomLinked = true;
164
+ field2.fieldPosition.isRightLinked = true;
165
+ field2.fieldPosition.searchArea = new model_1.Size({ height: 24, width: 209 });
166
+ field2.fieldPosition.autoScale = false;
167
+ const field3 = new model_2.Field();
168
+ field3.fieldName = "Regex";
169
+ field3.fieldPosition = new model_2.FieldPosition();
170
+ field3.fieldPosition.fieldPositionType = "Regex";
171
+ field3.fieldPosition.regex = "REGEX TEXT 123";
172
+ options.fields = new Array(field1, field2, field3);
173
+ let table = new model_2.Table({
174
+ tableName: "TableCells",
175
+ pageIndex: 5,
176
+ detectorParameters: new model_2.DetectorParameters({
177
+ rectangle: new model_2.Rectangle({ size: new model_1.Size({ height: 400, width: 600 }), position: new model_1.Point({ x: 0, y: 0 }) })
178
+ })
179
+ });
180
+ options.tables = new Array(table);
181
+ return options;
182
+ }
183
+ ;
184
+ }
@@ -0,0 +1 @@
1
+ import "mocha";