diff --git a/.github/workflows/_test-units.yml b/.github/workflows/_test-units.yml index 99e25d53e..621c6aad8 100644 --- a/.github/workflows/_test-units.yml +++ b/.github/workflows/_test-units.yml @@ -42,6 +42,7 @@ jobs: - name: Test code run: npm run test + run-tests-without-optional-dependencies: name: Run Tests Without Optional Dependencies strategy: diff --git a/package-lock.json b/package-lock.json index 94d38729c..b6f8b0d8e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mindee", - "version": "4.36.3", + "version": "5.0.0-alpha1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "mindee", - "version": "4.36.3", + "version": "5.0.0-alpha1", "license": "MIT", "dependencies": { "commander": "~9.4.1", @@ -20,19 +20,17 @@ "mindee": "bin/mindee.js" }, "devDependencies": { - "@types/chai": "^5.2.3", "@types/mocha": "^10.0.10", "@types/node": "^18.19.130", "@types/tmp": "^0.2.6", - "@typescript-eslint/eslint-plugin": "^8.52.0", - "@typescript-eslint/parser": "^8.52.0", - "chai": "^6.2.2", + "@typescript-eslint/eslint-plugin": "^8.55.0", + "@typescript-eslint/parser": "^8.55.0", "eslint": "^9.39.2", - "eslint-plugin-jsdoc": "^50.6.17", + "eslint-plugin-jsdoc": "^52.0.4", "mocha": "^11.7.5", "tsc-alias": "^1.8.16", "tsx": "^4.21.0", - "typedoc": "~0.28.15", + "typedoc": "~0.28.16", "typescript": "^5.9.3" }, "engines": { @@ -81,20 +79,20 @@ } }, "node_modules/@es-joy/jsdoccomment": { - "version": "0.50.2", - "resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.50.2.tgz", - "integrity": "sha512-YAdE/IJSpwbOTiaURNCKECdAwqrJuFiZhylmesBcIRawtYKnBR2wxPhoIewMg+Yu+QuYvHfJNReWpoxGBKOChA==", + "version": "0.52.0", + "resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.52.0.tgz", + "integrity": "sha512-BXuN7BII+8AyNtn57euU2Yxo9yA/KUDNzrpXyi3pfqKmBhhysR6ZWOebFh3vyPoqA3/j1SOvGgucElMGwlXing==", "dev": true, "license": "MIT", "dependencies": { - "@types/estree": "^1.0.6", - "@typescript-eslint/types": "^8.11.0", + "@types/estree": "^1.0.8", + "@typescript-eslint/types": "^8.34.1", "comment-parser": "1.4.1", "esquery": "^1.6.0", "jsdoc-type-pratt-parser": "~4.1.0" }, "engines": { - "node": ">=18" + "node": ">=20.11.0" } }, "node_modules/@esbuild/aix-ppc64": { @@ -1408,24 +1406,6 @@ "integrity": "sha512-OvjF+z51L3ov0OyAU0duzsYuvO01PH7x4t6DJx+guahgTnBHkhJdG7soQeTSFLWN3efnHyibZ4Z8l2EuWwJN3A==", "license": "MIT" }, - "node_modules/@types/chai": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", - "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/deep-eql": "*", - "assertion-error": "^2.0.1" - } - }, - "node_modules/@types/deep-eql": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", - "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/estree": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", @@ -1837,16 +1817,6 @@ "node": ">=8" } }, - "node_modules/assertion-error": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", - "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=12" - } - }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -1919,16 +1889,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/chai": { - "version": "6.2.2", - "resolved": "https://registry.npmjs.org/chai/-/chai-6.2.2.tgz", - "integrity": "sha512-NUPRluOfOiTKBKvWPtSD4PhFvWCqOi0BGStNWs57X9js7XGTprSmFoz5F0tWhR4WPjNeR9jXqdC7/UpSJTnlRg==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=18" - } - }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -2364,25 +2324,25 @@ } }, "node_modules/eslint-plugin-jsdoc": { - "version": "50.8.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-50.8.0.tgz", - "integrity": "sha512-UyGb5755LMFWPrZTEqqvTJ3urLz1iqj+bYOHFNag+sw3NvaMWP9K2z+uIn37XfNALmQLQyrBlJ5mkiVPL7ADEg==", + "version": "52.0.4", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-52.0.4.tgz", + "integrity": "sha512-be5OzGlLExvcK13Il3noU7/v7WmAQGenTmCaBKf1pwVtPOb6X+PGFVnJad0QhMj4KKf45XjE4hbsBxv25q1fTg==", "dev": true, "license": "BSD-3-Clause", "dependencies": { - "@es-joy/jsdoccomment": "~0.50.2", + "@es-joy/jsdoccomment": "~0.52.0", "are-docs-informative": "^0.0.2", "comment-parser": "1.4.1", "debug": "^4.4.1", "escape-string-regexp": "^4.0.0", - "espree": "^10.3.0", + "espree": "^10.4.0", "esquery": "^1.6.0", "parse-imports-exports": "^0.2.4", "semver": "^7.7.2", "spdx-expression-parse": "^4.0.0" }, "engines": { - "node": ">=18" + "node": ">=20.11.0" }, "peerDependencies": { "eslint": "^7.0.0 || ^8.0.0 || ^9.0.0" diff --git a/package.json b/package.json index e66a1df85..617a4cdb8 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,8 @@ "test-v1-light": "mocha --grep \"#includeOptionalDeps\" --invert \"tests/v1/**/*.spec.ts\"", "test-v2": "mocha --grep \"#omitOptionalDeps\" --invert \"tests/v2/**/*.spec.ts\"", "test-v2-light": "mocha --grep \"#includeOptionalDeps\" --invert \"tests/v2/**/*.spec.ts\"", - "lint": "tsc --noEmit && eslint './src/**/*.ts' --report-unused-disable-directives && echo 'Your .ts files look good.'", - "lint-fix": "eslint './src/**/*.ts' --fix", + "lint": "tsc --noEmit && eslint --report-unused-disable-directives './src/**/*.ts' './tests/**/*.ts'", + "lint-fix": "eslint --fix --report-unused-disable-directives './src/**/*.ts' './tests/**/*.ts'", "docs": "typedoc --out docs/_build ./src/index.ts", "docs-for-dist": "typedoc --out docs/_build ./src/index.ts && cp -r ./docs/code_samples ./docs/_build/" }, @@ -47,28 +47,26 @@ }, "homepage": "https://mindee.com/", "devDependencies": { - "@types/chai": "^5.2.3", "@types/mocha": "^10.0.10", "@types/node": "^18.19.130", "@types/tmp": "^0.2.6", - "@typescript-eslint/eslint-plugin": "^8.52.0", - "@typescript-eslint/parser": "^8.52.0", - "chai": "^6.2.2", + "@typescript-eslint/eslint-plugin": "^8.55.0", + "@typescript-eslint/parser": "^8.55.0", "eslint": "^9.39.2", - "eslint-plugin-jsdoc": "^50.6.17", + "eslint-plugin-jsdoc": "^52.0.4", "mocha": "^11.7.5", "tsc-alias": "^1.8.16", "tsx": "^4.21.0", - "typedoc": "~0.28.15", + "typedoc": "~0.28.16", "typescript": "^5.9.3" }, "dependencies": { "commander": "~9.4.1", "file-type": "^19.6.0", - "node-poppler": "^7.2.4", "tmp": "^0.2.3", "tslib": "^2.8.1", - "undici": "^6.23.0" + "undici": "^6.23.0", + "node-poppler": "^7.2.4" }, "optionalDependencies": { "sharp": "~0.34.5", diff --git a/tests/dependency/missingDependencies.integration.ts b/tests/dependency/missingDependencies.integration.ts index 9494d461c..2a1c12ab2 100644 --- a/tests/dependency/missingDependencies.integration.ts +++ b/tests/dependency/missingDependencies.integration.ts @@ -1,6 +1,6 @@ import * as mindee from "@/index.js"; import { InvoiceSplitterV1 } from "@/v1/product/index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import path from "path"; import { V1_PRODUCT_PATH } from "../index.js"; @@ -21,7 +21,7 @@ describe("Light Environment Sanity Check #omitOptionalDeps", function () { mindee.v1.product.InvoiceSplitterV1, sample ); const invoiceSplitterInference = response.document?.inference; - expect(invoiceSplitterInference).to.be.an.instanceof(InvoiceSplitterV1); + assert.ok(invoiceSplitterInference instanceof InvoiceSplitterV1); await mindee.v1.extraction.extractInvoices( sample, invoiceSplitterInference as InvoiceSplitterV1 diff --git a/tests/dependency/missingDependencies.spec.ts b/tests/dependency/missingDependencies.spec.ts index cfc135a20..1c46a908c 100644 --- a/tests/dependency/missingDependencies.spec.ts +++ b/tests/dependency/missingDependencies.spec.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import assert from "node:assert/strict"; describe("Light Environment Sanity Check #omitOptionalDeps", function () { @@ -6,7 +6,7 @@ describe("Light Environment Sanity Check #omitOptionalDeps", function () { try { const moduleName = "sharp"; await import(moduleName); - expect.fail("sharp should not be installed in this environment, but it was found!"); + assert.fail("sharp should not be installed in this environment, but it was found!"); } catch (error: any) { const isModuleNotFound = error.code === "ERR_MODULE_NOT_FOUND"; const isSharpBinaryMissing = error.message && error.message.includes("Could not load the \"sharp\" module"); @@ -21,9 +21,9 @@ describe("Light Environment Sanity Check #omitOptionalDeps", function () { try { const moduleName = "pdf.js-extract"; await import(moduleName); - expect.fail("pdf.js-extract should not be installed, but it was found!"); + assert.fail("pdf.js-extract should not be installed, but it was found!"); } catch (error: any) { - expect(error.code).to.equal("ERR_MODULE_NOT_FOUND"); + assert.strictEqual(error.code, "ERR_MODULE_NOT_FOUND"); } }); @@ -31,9 +31,9 @@ describe("Light Environment Sanity Check #omitOptionalDeps", function () { try { const moduleName = "@cantoo/pdf-lib"; await import(moduleName); - expect.fail("@cantoo/pdf-lib should not be installed, but it was found!"); + assert.fail("@cantoo/pdf-lib should not be installed, but it was found!"); } catch (error: any) { - expect(error.code).to.equal("ERR_MODULE_NOT_FOUND"); + assert.strictEqual(error.code, "ERR_MODULE_NOT_FOUND"); } }); }); diff --git a/tests/geometry.spec.ts b/tests/geometry.spec.ts index 2d85e5fea..8bef96b3e 100644 --- a/tests/geometry.spec.ts +++ b/tests/geometry.spec.ts @@ -1,5 +1,5 @@ import * as geometry from "@/geometry/index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; describe("Geometry functions", () => { // 90° rectangle, overlaps polygonB @@ -28,51 +28,60 @@ describe("Geometry functions", () => { it("should get a polygon's bbox", () => { const bboxA = geometry.getBbox(polygonA); - expect(bboxA.xMin).to.be.eq(0.123); - expect(bboxA.yMin).to.be.eq(0.53); - expect(bboxA.xMax).to.be.eq(0.175); - expect(bboxA.yMax).to.be.eq(0.546); + assert.strictEqual(bboxA.xMin, 0.123); + assert.strictEqual(bboxA.yMin, 0.53); + assert.strictEqual(bboxA.xMax, 0.175); + assert.strictEqual(bboxA.yMax, 0.546); const bboxB = geometry.getBbox(polygonB); - expect(bboxB.xMin).to.be.eq(0.124); - expect(bboxB.yMin).to.be.eq(0.535); - expect(bboxB.xMax).to.be.eq(0.19); - expect(bboxB.yMax).to.be.eq(0.546); + assert.strictEqual(bboxB.xMin, 0.124); + assert.strictEqual(bboxB.yMin, 0.535); + assert.strictEqual(bboxB.xMax, 0.19); + assert.strictEqual(bboxB.yMax, 0.546); const bboxC = geometry.getBbox(polygonC); - expect(bboxC.xMin).to.be.eq(0.205); - expect(bboxC.yMin).to.be.eq(0.407); - expect(bboxC.xMax).to.be.eq(0.381); - expect(bboxC.yMax).to.be.eq(0.43); + assert.strictEqual(bboxC.xMin, 0.205); + assert.strictEqual(bboxC.yMin, 0.407); + assert.strictEqual(bboxC.xMax, 0.381); + assert.strictEqual(bboxC.yMax, 0.43); }); it("should get a polygon's bounding box", () => { - expect(geometry.getBoundingBox(polygonA)).to.deep.ordered.members([ - [0.123, 0.53], - [0.175, 0.53], - [0.175, 0.546], - [0.123, 0.546], - ]); - expect(geometry.getBoundingBox(polygonB)).to.deep.ordered.members([ - [0.124, 0.535], - [0.19, 0.535], - [0.19, 0.546], - [0.124, 0.546], - ]); - expect(geometry.getBoundingBox(polygonC)).to.deep.ordered.members([ - [0.205, 0.407], - [0.381, 0.407], - [0.381, 0.43], - [0.205, 0.43], - ]); + assert.deepStrictEqual( + geometry.getBoundingBox(polygonA), + new geometry.BoundingBox( + [0.123, 0.53], + [0.175, 0.53], + [0.175, 0.546], + [0.123, 0.546], + ) + ); + assert.deepStrictEqual( + geometry.getBoundingBox(polygonB), + new geometry.BoundingBox( + [0.124, 0.535], + [0.19, 0.535], + [0.19, 0.546], + [0.124, 0.546], + ) + ); + assert.deepStrictEqual( + geometry.getBoundingBox(polygonC), + new geometry.BoundingBox( + [0.205, 0.407], + [0.381, 0.407], + [0.381, 0.43], + [0.205, 0.43], + ) + ); }); it("should calculate a polygon's centroid", () => { const utilsCentroid = geometry.getCentroid(polygonA); const polygonCentroid = polygonA.getCentroid(); const expectedCentroid = [0.149, 0.538]; - expect(utilsCentroid).to.deep.ordered.members(expectedCentroid); - expect(polygonCentroid).to.deep.ordered.members(expectedCentroid); + assert.deepStrictEqual(utilsCentroid, expectedCentroid); + assert.deepStrictEqual(polygonCentroid, expectedCentroid); }); it("should determine if two polygons are on the same line", () => { @@ -81,19 +90,19 @@ describe("Geometry functions", () => { // Should only be in polygon C const pointB: geometry.Point = [0.3, 0.42]; - expect(geometry.isPointInPolygonY(pointA, polygonA)).to.be.true; - expect(polygonA.isPointInY(pointA)).to.be.true; - expect(geometry.isPointInPolygonY(pointA, polygonB)).to.be.true; - expect(polygonB.isPointInY(pointA)).to.be.true; - expect(geometry.isPointInPolygonY(pointA, polygonC)).to.be.false; - expect(polygonC.isPointInY(pointA)).to.be.false; - - expect(geometry.isPointInPolygonY(pointB, polygonA)).to.be.false; - expect(polygonA.isPointInY(pointB)).to.be.false; - expect(geometry.isPointInPolygonY(pointB, polygonB)).to.be.false; - expect(polygonB.isPointInY(pointB)).to.be.false; - expect(geometry.isPointInPolygonY(pointB, polygonC)).to.be.true; - expect(polygonC.isPointInY(pointB)).to.be.true; + assert.ok(geometry.isPointInPolygonY(pointA, polygonA)); + assert.ok(polygonA.isPointInY(pointA)); + assert.ok(geometry.isPointInPolygonY(pointA, polygonB)); + assert.ok(polygonB.isPointInY(pointA)); + assert.ok(!geometry.isPointInPolygonY(pointA, polygonC)); + assert.ok(!polygonC.isPointInY(pointA)); + + assert.ok(!geometry.isPointInPolygonY(pointB, polygonA)); + assert.ok(!polygonA.isPointInY(pointB)); + assert.ok(!geometry.isPointInPolygonY(pointB, polygonB)); + assert.ok(!polygonB.isPointInY(pointB)); + assert.ok(geometry.isPointInPolygonY(pointB, polygonC)); + assert.ok(polygonC.isPointInY(pointB)); }); it("should determine if two polygons are on the same column", () => { @@ -102,30 +111,33 @@ describe("Geometry functions", () => { // Should only be in polygon C const pointB: geometry.Point = [0.3, 0.42]; - expect(geometry.isPointInPolygonX(pointA, polygonA)).to.be.true; - expect(polygonA.isPointInX(pointA)).to.be.true; - expect(geometry.isPointInPolygonX(pointA, polygonB)).to.be.true; - expect(polygonB.isPointInX(pointA)).to.be.true; - expect(geometry.isPointInPolygonX(pointA, polygonC)).to.be.false; - expect(polygonC.isPointInX(pointA)).to.be.false; - - expect(geometry.isPointInPolygonX(pointB, polygonA)).to.be.false; - expect(polygonA.isPointInX(pointB)).to.be.false; - expect(geometry.isPointInPolygonX(pointB, polygonB)).to.be.false; - expect(polygonB.isPointInX(pointB)).to.be.false; - expect(geometry.isPointInPolygonX(pointB, polygonC)).to.be.true; - expect(polygonC.isPointInX(pointB)).to.be.true; + assert.ok(geometry.isPointInPolygonX(pointA, polygonA)); + assert.ok(polygonA.isPointInX(pointA)); + assert.ok(geometry.isPointInPolygonX(pointA, polygonB)); + assert.ok(polygonB.isPointInX(pointA)); + assert.ok(!geometry.isPointInPolygonX(pointA, polygonC)); + assert.ok(!polygonC.isPointInX(pointA)); + + assert.ok(!geometry.isPointInPolygonX(pointB, polygonA)); + assert.ok(!polygonA.isPointInX(pointB)); + assert.ok(!geometry.isPointInPolygonX(pointB, polygonB)); + assert.ok(!polygonB.isPointInX(pointB)); + assert.ok(geometry.isPointInPolygonX(pointB, polygonC)); + assert.ok(polygonC.isPointInX(pointB)); }); it("should merge two Bbox", () => { - const firsBBox: geometry.BBox = new geometry.BBox(0.081, 0.442, 0.15, 0.451); - const secondBBox: geometry.BBox = new geometry.BBox(0.157, 0.442, 0.26, 0.451); - + const firsBBox: geometry.BBox = new geometry.BBox( + 0.081, 0.442, 0.15, 0.451 + ); + const secondBBox: geometry.BBox = new geometry.BBox( + 0.157, 0.442, 0.26, 0.451 + ); const mergedBbox = geometry.mergeBbox(firsBBox, secondBBox); - expect(mergedBbox.xMin).to.be.eq(0.081); - expect(mergedBbox.yMin).to.be.eq(0.442); - expect(mergedBbox.xMax).to.be.eq(0.26); - expect(mergedBbox.yMax).to.be.eq(0.451); + assert.strictEqual(mergedBbox.xMin, 0.081); + assert.strictEqual(mergedBbox.yMin, 0.442); + assert.strictEqual(mergedBbox.xMax, 0.26); + assert.strictEqual(mergedBbox.yMax, 0.451); }); }); diff --git a/tests/input/compression.spec.ts b/tests/input/compression.spec.ts index a08f134c0..db6686e34 100644 --- a/tests/input/compression.spec.ts +++ b/tests/input/compression.spec.ts @@ -3,7 +3,7 @@ import { } from "@/input/index.js"; import * as fs from "fs"; import * as path from "path"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import { compressImage } from "@/image/index.js"; import { compressPdf } from "@/pdf/index.js"; import { extractTextFromPdf } from "@/pdf/pdfUtils.js"; @@ -24,7 +24,7 @@ describe("Input Sources - compression and resize #includeOptionalDeps", () => { const initialFileStats = await fs.promises.stat(path.join(RESOURCE_PATH, "file_types/receipt.jpg")); const renderedFileStats = await fs.promises.stat(path.join(outputPath, "compress_indirect.jpg")); - expect(renderedFileStats.size).to.be.lessThan(initialFileStats.size); + assert.ok(renderedFileStats.size < initialFileStats.size); }); it("Image Quality Compresses From Compressor", async () => { @@ -48,11 +48,11 @@ describe("Input Sources - compression and resize #includeOptionalDeps", () => { fileNames.map(fileName => fs.promises.stat(path.join(outputPath, fileName))) ); - expect(initialFileStats.size).to.be.lessThan(renderedFileStats[0].size); - expect(initialFileStats.size).to.be.lessThan(renderedFileStats[1].size); - expect(renderedFileStats[1].size).to.be.greaterThan(renderedFileStats[2].size); - expect(renderedFileStats[2].size).to.be.greaterThan(renderedFileStats[3].size); - expect(renderedFileStats[3].size).to.be.greaterThan(renderedFileStats[4].size); + assert.ok(initialFileStats.size < renderedFileStats[0].size); + assert.ok(initialFileStats.size < renderedFileStats[1].size); + assert.ok(renderedFileStats[1].size > renderedFileStats[2].size); + assert.ok(renderedFileStats[2].size > renderedFileStats[3].size); + assert.ok(renderedFileStats[3].size > renderedFileStats[4].size); }); it("Image Resize From InputSource", async () => { @@ -64,11 +64,11 @@ describe("Input Sources - compression and resize #includeOptionalDeps", () => { const initialFileStats = await fs.promises.stat(path.join(RESOURCE_PATH, "file_types/receipt.jpg")); const renderedFileStats = await fs.promises.stat(path.join(outputPath, "resize_indirect.jpg")); - expect(renderedFileStats.size).to.be.lessThan(initialFileStats.size); + assert.ok(renderedFileStats.size < initialFileStats.size); const sharp = await import("sharp"); const metadata = await sharp.default(imageResizeInput.fileObject).metadata(); - expect(metadata.width).to.equal(250); - expect(metadata.height).to.equal(333); + assert.strictEqual(metadata.width, 250); + assert.strictEqual(metadata.height, 333); }); it("Image Resize From Compressor", async () => { @@ -92,10 +92,10 @@ describe("Input Sources - compression and resize #includeOptionalDeps", () => { fileNames.map(fileName => fs.promises.stat(path.join(outputPath, fileName))) ); - expect(initialFileStats.size).to.be.greaterThan(renderedFileStats[0].size); - expect(renderedFileStats[0].size).to.be.greaterThan(renderedFileStats[1].size); - expect(renderedFileStats[1].size).to.be.greaterThan(renderedFileStats[2].size); - expect(renderedFileStats[2].size).to.be.equals(renderedFileStats[3].size); + assert.ok(initialFileStats.size > renderedFileStats[0].size); + assert.ok(renderedFileStats[0].size > renderedFileStats[1].size); + assert.ok(renderedFileStats[1].size > renderedFileStats[2].size); + assert.strictEqual(renderedFileStats[2].size, renderedFileStats[3].size); }); @@ -108,9 +108,9 @@ describe("Input Sources - compression and resize #includeOptionalDeps", () => { const hasNoSourceTextInput = new PathInput({ inputPath: hasNoSourceTextPath }); const hasNoSourceTextSinceItsImageInput = new PathInput({ inputPath: hasNoSourceTextSinceItsImagePath }); - expect(await hasSourceTextInput.hasSourceText()).to.be.true; - expect(await hasNoSourceTextInput.hasSourceText()).to.be.false; - expect(await hasNoSourceTextSinceItsImageInput.hasSourceText()).to.be.false; + assert.ok(await hasSourceTextInput.hasSourceText()); + assert.ok(!(await hasNoSourceTextInput.hasSourceText())); + assert.ok(!(await hasNoSourceTextSinceItsImageInput.hasSourceText())); }); it("PDF Compress From InputSource", async () => { @@ -130,7 +130,7 @@ describe("Input Sources - compression and resize #includeOptionalDeps", () => { const renderedFileStats = await fs.promises.stat( path.join(outputPath, "resize_indirect.pdf") ); - expect(renderedFileStats.size).to.be.lessThan(initialFileStats.size); + assert.ok(renderedFileStats.size < initialFileStats.size); }).timeout(10000); it("PDF Compress From Compressor", async () => { @@ -158,10 +158,10 @@ describe("Input Sources - compression and resize #includeOptionalDeps", () => { fileNames.map(fileName => fs.promises.stat(path.join(outputPath, fileName))) ); - expect(initialFileStats.size).to.be.greaterThan(renderedFileStats[0].size); - expect(renderedFileStats[0].size).to.be.greaterThan(renderedFileStats[1].size); - expect(renderedFileStats[1].size).to.be.greaterThan(renderedFileStats[2].size); - expect(renderedFileStats[2].size).to.be.greaterThan(renderedFileStats[3].size); + assert.ok(initialFileStats.size > renderedFileStats[0].size); + assert.ok(renderedFileStats[0].size > renderedFileStats[1].size); + assert.ok(renderedFileStats[1].size > renderedFileStats[2].size); + assert.ok(renderedFileStats[2].size > renderedFileStats[3].size); }).timeout(20000); it("PDF Compress With Text Keeps Text", async () => { @@ -176,7 +176,7 @@ describe("Input Sources - compression and resize #includeOptionalDeps", () => { const originalText = (await extractTextFromPdf(initialWithText.fileObject)).getConcatenatedText(); const compressedText = (await extractTextFromPdf(compressedWithText)).getConcatenatedText(); - expect(compressedText).to.equal(originalText); + assert.strictEqual(compressedText, originalText); }).timeout(60000); it("PDF Compress With Text Does Not Compress", async () => { @@ -187,7 +187,7 @@ describe("Input Sources - compression and resize #includeOptionalDeps", () => { const compressedWithText = await compressPdf(initialWithText.fileObject, 50); - expect(compressedWithText).to.deep.equal(initialWithText.fileObject); + assert.deepStrictEqual(compressedWithText, initialWithText.fileObject); }).timeout(10000); after(async function () { diff --git a/tests/input/pageOperations.spec.ts b/tests/input/pageOperations.spec.ts index 790843660..a56fa516e 100644 --- a/tests/input/pageOperations.spec.ts +++ b/tests/input/pageOperations.spec.ts @@ -5,7 +5,7 @@ import { } from "@/input/index.js"; import * as fs from "fs"; import * as path from "path"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import { RESOURCE_PATH } from "../index.js"; describe("Input Sources - high level multi-page operations #includeOptionalDeps", () => { @@ -18,9 +18,9 @@ describe("Input Sources - high level multi-page operations #includeOptionalDeps" pageIndexes: [0, -2, -1], onMinPages: 5, }); - expect(input.inputType).to.equals(INPUT_TYPE_PATH); - expect(input.filename).to.equals("multipage.pdf"); - expect(input.mimeType).to.equals("application/pdf"); + assert.strictEqual(input.inputType, INPUT_TYPE_PATH); + assert.strictEqual(input.filename, "multipage.pdf"); + assert.strictEqual(input.mimeType, "application/pdf"); // This is how the length of the word is set in the // raw PDF file. @@ -34,7 +34,7 @@ describe("Input Sources - high level multi-page operations #includeOptionalDeps" const expectedLengths = expectedResult.match(lengthRE); const inputDocLengths = input.fileObject.toString("utf-8").match(lengthRE) || []; - expect(expectedLengths).to.have.ordered.members(inputDocLengths); + assert.deepStrictEqual(inputDocLengths, expectedLengths); }); it("should not cut the PDF", async () => { @@ -44,9 +44,9 @@ describe("Input Sources - high level multi-page operations #includeOptionalDeps" }); await input.init(); const expectedResult = await fs.promises.readFile(filePath); - expect(input.inputType).to.equals(INPUT_TYPE_PATH); - expect(input.filename).to.equals("multipage.pdf"); - expect(input.mimeType).to.equals("application/pdf"); - expect(input.fileObject).to.eql(expectedResult); + assert.strictEqual(input.inputType, INPUT_TYPE_PATH); + assert.strictEqual(input.filename, "multipage.pdf"); + assert.strictEqual(input.mimeType, "application/pdf"); + assert.deepStrictEqual(input.fileObject, expectedResult); }); }); diff --git a/tests/input/sources.spec.ts b/tests/input/sources.spec.ts index 672e8d3af..01c5e0a64 100644 --- a/tests/input/sources.spec.ts +++ b/tests/input/sources.spec.ts @@ -13,7 +13,7 @@ import { } from "@/input/index.js"; import * as fs from "fs"; import * as path from "path"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import { Buffer } from "node:buffer"; import { MindeeInputSourceError } from "@/errors/index.js"; import { RESOURCE_PATH, V1_PRODUCT_PATH } from "../index.js"; @@ -33,17 +33,17 @@ describe("Input Sources: - load different types of input", () => { filename: filename, }); await inputSource.init(); - expect(inputSource.inputType).to.equals(INPUT_TYPE_BASE64); - expect(inputSource.filename).to.equals(filename); - expect(inputSource.mimeType).to.equals("image/jpeg"); - expect(inputSource.isPdf()).to.false; - expect(await inputSource.getPageCount()).to.equals(1); + assert.strictEqual(inputSource.inputType, INPUT_TYPE_BASE64); + assert.strictEqual(inputSource.filename, filename); + assert.strictEqual(inputSource.mimeType, "image/jpeg"); + assert.ok(!inputSource.isPdf()); + assert.strictEqual(await inputSource.getPageCount(), 1); // we need to insert a newline very 76 chars to match the format // of the input file. const expectedString = inputSource.fileObject .toString("base64") .replace(/(.{76})/gm, "$1\n"); - expect(expectedString).to.eqls(b64String); + assert.deepStrictEqual(expectedString, b64String); }); it("should accept JPEG files from a path", async () => { @@ -55,12 +55,12 @@ describe("Input Sources: - load different types of input", () => { const expectedResult = await fs.promises.readFile( path.join(V1_PRODUCT_PATH, "expense_receipts/default_sample.jpg") ); - expect(inputSource.inputType).to.equals(INPUT_TYPE_PATH); - expect(inputSource.filename).to.equals("default_sample.jpg"); - expect(inputSource.mimeType).to.equals("image/jpeg"); - expect(inputSource.isPdf()).to.false; - expect(await inputSource.getPageCount()).to.equals(1); - expect(inputSource.fileObject).to.eqls(expectedResult); + assert.strictEqual(inputSource.inputType, INPUT_TYPE_PATH); + assert.strictEqual(inputSource.filename, "default_sample.jpg"); + assert.strictEqual(inputSource.mimeType, "image/jpeg"); + assert.ok(!inputSource.isPdf()); + assert.strictEqual(await inputSource.getPageCount(), 1); + assert.deepStrictEqual(inputSource.fileObject, expectedResult); }); it("should accept TIFF from a path", async () => { @@ -71,12 +71,12 @@ describe("Input Sources: - load different types of input", () => { const expectedResult = await fs.promises.readFile( path.join(RESOURCE_PATH, "file_types/receipt.tif") ); - expect(inputSource.inputType).to.equals(INPUT_TYPE_PATH); - expect(inputSource.filename).to.equals("receipt.tif"); - expect(inputSource.mimeType).to.equals("image/tiff"); - expect(inputSource.isPdf()).to.false; - expect(await inputSource.getPageCount()).to.equals(1); - expect(inputSource.fileObject).to.eqls(expectedResult); + assert.strictEqual(inputSource.inputType, INPUT_TYPE_PATH); + assert.strictEqual(inputSource.filename, "receipt.tif"); + assert.strictEqual(inputSource.mimeType, "image/tiff"); + assert.ok(!inputSource.isPdf()); + assert.strictEqual(await inputSource.getPageCount(), 1); + assert.deepStrictEqual(inputSource.fileObject, expectedResult); }); it("should accept HEIC from a path", async () => { @@ -87,12 +87,12 @@ describe("Input Sources: - load different types of input", () => { const expectedResult = await fs.promises.readFile( path.join(RESOURCE_PATH, "file_types/receipt.heic") ); - expect(inputSource.inputType).to.equals(INPUT_TYPE_PATH); - expect(inputSource.filename).to.equals("receipt.heic"); - expect(inputSource.mimeType).to.equals("image/heic"); - expect(inputSource.isPdf()).to.false; - expect(await inputSource.getPageCount()).to.equals(1); - expect(inputSource.fileObject).to.eqls(expectedResult); + assert.strictEqual(inputSource.inputType, INPUT_TYPE_PATH); + assert.strictEqual(inputSource.filename, "receipt.heic"); + assert.strictEqual(inputSource.mimeType, "image/heic"); + assert.ok(!inputSource.isPdf()); + assert.strictEqual(await inputSource.getPageCount(), 1); + assert.deepStrictEqual(inputSource.fileObject, expectedResult); }); it("should accept WEBP from a path", async () => { @@ -103,12 +103,12 @@ describe("Input Sources: - load different types of input", () => { const expectedResult = await fs.promises.readFile( path.join(RESOURCE_PATH, "file_types/receipt.webp") ); - expect(inputSource.inputType).to.equals(INPUT_TYPE_PATH); - expect(inputSource.filename).to.equals("receipt.webp"); - expect(inputSource.mimeType).to.equals("image/webp"); - expect(inputSource.isPdf()).to.false; - expect(await inputSource.getPageCount()).to.equals(1); - expect(inputSource.fileObject).to.eqls(expectedResult); + assert.strictEqual(inputSource.inputType, INPUT_TYPE_PATH); + assert.strictEqual(inputSource.filename, "receipt.webp"); + assert.strictEqual(inputSource.mimeType, "image/webp"); + assert.ok(!inputSource.isPdf()); + assert.strictEqual(await inputSource.getPageCount(), 1); + assert.deepStrictEqual(inputSource.fileObject, expectedResult); }); it("should accept read streams", async () => { @@ -120,13 +120,13 @@ describe("Input Sources: - load different types of input", () => { filename: filename, }); await inputSource.init(); - expect(inputSource.inputType).to.equals(INPUT_TYPE_STREAM); - expect(inputSource.filename).to.equals(filename); - expect(inputSource.mimeType).to.equals("image/jpeg"); - expect(inputSource.isPdf()).to.false; - expect(await inputSource.getPageCount()).to.equals(1); + assert.strictEqual(inputSource.inputType, INPUT_TYPE_STREAM); + assert.strictEqual(inputSource.filename, filename); + assert.strictEqual(inputSource.mimeType, "image/jpeg"); + assert.ok(!inputSource.isPdf()); + assert.strictEqual(await inputSource.getPageCount(), 1); const expectedResult = await fs.promises.readFile(filePath); - expect(inputSource.fileObject.toString()).to.eqls(expectedResult.toString()); + assert.deepStrictEqual(inputSource.fileObject.toString(), expectedResult.toString()); }); it("should handle aborted streams", async () => { @@ -145,10 +145,13 @@ describe("Input Sources: - load different types of input", () => { try { await streamInput.init(); - expect.fail("Should have thrown an error"); + assert.fail("Should have thrown an error"); } catch (e: any) { - expect(e).to.be.instanceOf(MindeeInputSourceError); - expect(e.toString()).to.eq("MindeeInputSourceError: Error converting stream - Error: aborted"); + assert.ok(e instanceof MindeeInputSourceError); + assert.strictEqual( + e.toString(), + "MindeeInputSourceError: Error converting stream - Error: aborted" + ); } }); @@ -165,10 +168,10 @@ describe("Input Sources: - load different types of input", () => { try { await streamInput.init(); - expect.fail("Should have thrown an error"); + assert.fail("Should have thrown an error"); } catch (e: any) { - expect(e).to.be.instanceOf(MindeeInputSourceError); - expect(e.toString()).to.equal("MindeeInputSourceError: Stream is already closed"); + assert.ok(e instanceof MindeeInputSourceError); + assert.strictEqual(e.toString(), "MindeeInputSourceError: Stream is already closed"); } }); @@ -194,8 +197,11 @@ describe("Input Sources: - load different types of input", () => { try { await streamInput.init(); } catch (e: any) { - expect(e).to.be.instanceOf(MindeeInputSourceError); - expect(e.toString()).to.eq("MindeeInputSourceError: Error converting stream - Error: aborted"); + assert.ok(e instanceof MindeeInputSourceError); + assert.strictEqual( + e.toString(), + "MindeeInputSourceError: Error converting stream - Error: aborted" + ); } }); @@ -210,13 +216,13 @@ describe("Input Sources: - load different types of input", () => { filename: filename, }); await inputSource.init(); - expect(inputSource.inputType).to.equal(INPUT_TYPE_BYTES); - expect(inputSource.filename).to.equal(filename); - expect(inputSource.mimeType).to.equal("image/jpeg"); - expect(inputSource.isPdf()).to.false; - expect(await inputSource.getPageCount()).to.equals(1); + assert.strictEqual(inputSource.inputType, INPUT_TYPE_BYTES); + assert.strictEqual(inputSource.filename, filename); + assert.strictEqual(inputSource.mimeType, "image/jpeg"); + assert.ok(!inputSource.isPdf()); + assert.strictEqual(await inputSource.getPageCount(), 1); const expectedResult = await fs.promises.readFile(filePath); - expect(Buffer.compare(inputSource.fileObject, expectedResult)).to.equal(0); + assert.strictEqual(Buffer.compare(inputSource.fileObject, expectedResult), 0); }); it("should accept a Buffer", async () => { @@ -231,13 +237,13 @@ describe("Input Sources: - load different types of input", () => { filename: filename, }); await inputSource.init(); - expect(inputSource.inputType).to.equals(INPUT_TYPE_BUFFER); - expect(inputSource.filename).to.equals(filename); - expect(inputSource.isPdf()).to.be.true; + assert.strictEqual(inputSource.inputType, INPUT_TYPE_BUFFER); + assert.strictEqual(inputSource.filename, filename); + assert.ok(inputSource.isPdf()); it("#includeOptionalDeps", async () => { - expect(await inputSource.getPageCount()).to.equals(10); + assert.strictEqual(await inputSource.getPageCount(), 10); }); - expect(inputSource.fileObject).to.be.instanceOf(Buffer); + assert.ok(inputSource.fileObject instanceof Buffer); }); }); diff --git a/tests/input/urlInputSource.spec.ts b/tests/input/urlInputSource.spec.ts index ff777f76a..ce987f49f 100644 --- a/tests/input/urlInputSource.spec.ts +++ b/tests/input/urlInputSource.spec.ts @@ -1,6 +1,6 @@ import { BytesInput, UrlInput } from "@/index.js"; import { LocalInputSource } from "@/input/index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import { MockAgent, setGlobalDispatcher } from "undici"; const mockAgent = new MockAgent(); @@ -15,7 +15,7 @@ describe("Input Sources - URL input source", () => { dispatcher: mockAgent, }); await input.init(); - expect(input.fileObject).to.be.a("string"); + assert.strictEqual(typeof input.fileObject, "string"); }); it("should throw an error for non-HTTPS URL", async () => { @@ -24,10 +24,10 @@ describe("Input Sources - URL input source", () => { try { await urlSource.init(); - expect.fail("Expected an error to be thrown"); + assert.fail("Expected an error to be thrown"); } catch (error) { - expect(error).to.be.instanceOf(Error); - expect((error as Error).message).to.equal("URL must be HTTPS"); + assert.ok(error instanceof Error); + assert.strictEqual((error as Error).message, "URL must be HTTPS"); } }); @@ -47,9 +47,9 @@ describe("Input Sources - URL input source", () => { const localInput = await urlInput.asLocalInputSource(); await localInput.init(); - expect(localInput).to.be.instanceOf(BytesInput); - expect(localInput.filename).to.equal("file.pdf"); - expect(localInput.fileObject.toString()).to.eq(fileContent.toString()); + assert.ok(localInput instanceof BytesInput); + assert.strictEqual(localInput.filename, "file.pdf"); + assert.strictEqual(localInput.fileObject.toString(), fileContent.toString()); }); it("should handle redirects", async () => { @@ -75,9 +75,9 @@ describe("Input Sources - URL input source", () => { const localInput = await urlInput.asLocalInputSource(); await localInput.init(); - expect(localInput).to.be.instanceOf(LocalInputSource); - expect(localInput.filename).to.equal("redirected.pdf"); - expect(localInput.fileObject).to.deep.equal(fileContent); + assert.ok(localInput instanceof LocalInputSource); + assert.strictEqual(localInput.filename, "redirected.pdf"); + assert.deepStrictEqual(localInput.fileObject, fileContent); }); it("should throw an error for HTTP error responses", async () => { @@ -91,10 +91,13 @@ describe("Input Sources - URL input source", () => { try { await urlInput.asLocalInputSource(); - expect.fail("Expected an error to be thrown"); + assert.fail("Expected an error to be thrown"); } catch (error) { - expect(error).to.be.instanceOf(Error); - expect((error as Error).message).to.equal("Couldn't retrieve file from server, error code 404."); + assert.ok(error instanceof Error); + assert.strictEqual( + (error as Error).message, + "Couldn't retrieve file from server, error code 404." + ); } }); @@ -110,7 +113,7 @@ describe("Input Sources - URL input source", () => { const localInput = await urlInput.asLocalInputSource({ filename: "custom.pdf" }); await localInput.init(); - expect(localInput.filename).to.equal("custom.pdf"); + assert.strictEqual(localInput.filename, "custom.pdf"); }); it("should throw an error for invalid filename", async () => { @@ -124,10 +127,11 @@ describe("Input Sources - URL input source", () => { try { const localInput = await urlInput.asLocalInputSource({ filename: "invalid" }); await localInput.init(); - expect.fail("Expected an error to be thrown"); + assert.fail("Expected an error to be thrown"); } catch (error) { - expect(error).to.be.instanceOf(Error); - expect((error as Error).message).to.equal( + assert.ok(error instanceof Error); + assert.strictEqual( + (error as Error).message, "Invalid file type, must be one of .pdf, .heic, .jpg, .jpeg, .png, .tif, .tiff, .webp." ); } diff --git a/tests/pdf/pdfOperation.spec.ts b/tests/pdf/pdfOperation.spec.ts index 4a00c7b6e..187485f83 100644 --- a/tests/pdf/pdfOperation.spec.ts +++ b/tests/pdf/pdfOperation.spec.ts @@ -1,7 +1,7 @@ import * as pdf from "@/pdf/index.js"; import * as path from "path"; import * as fs from "fs"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import { PageOptions, PageOptionsOperation } from "@/index.js"; import { PathInput } from "@/index.js"; import { RESOURCE_PATH } from "../index.js"; @@ -19,8 +19,8 @@ describe("Test pdf operation #includeOptionalDeps", () => { onMinPages: 1, }; const splitPdf = await pdf.extractPages(inputSource.fileObject, pageOptions); - expect(splitPdf.totalPagesRemoved).to.eq(10); - expect(await pdf.countPages(splitPdf.file)).to.eq(2); + assert.strictEqual(splitPdf.totalPagesRemoved, 10); + assert.strictEqual(await pdf.countPages(splitPdf.file), 2); }); it("should cut a PDF to get only the first page", async () => { @@ -35,8 +35,8 @@ describe("Test pdf operation #includeOptionalDeps", () => { onMinPages: 1, }; const splitPdf = await pdf.extractPages(inputSource.fileObject, pageOptions); - expect(splitPdf.totalPagesRemoved).to.eq(11); - expect(await pdf.countPages(splitPdf.file)).to.eq(1); + assert.strictEqual(splitPdf.totalPagesRemoved, 11); + assert.strictEqual(await pdf.countPages(splitPdf.file), 1); }); it("should not cut a PDF but throw exception because index page out of range", async () => { @@ -53,8 +53,8 @@ describe("Test pdf operation #includeOptionalDeps", () => { try { await pdf.extractPages(inputSource.fileObject, pageOptions); } catch (error: any) { - expect(error).to.be.an("error"); - expect(error.name).to.be.eq("MindeeError"); + assert.ok(error instanceof Error); + assert.strictEqual(error.name, "MindeeError"); } }); @@ -73,8 +73,8 @@ describe("Test pdf operation #includeOptionalDeps", () => { try { await pdf.extractPages(inputSource.fileObject, pageOptions); } catch (error: any) { - expect(error).to.be.an("error"); - expect(error.name).to.be.eq("MindeeError"); + assert.ok(error instanceof Error); + assert.strictEqual(error.name, "MindeeError"); } }); @@ -92,8 +92,8 @@ describe("Test pdf operation #includeOptionalDeps", () => { const splitPdf = await pdf.extractPages(inputSource.fileObject, pageOptions); - expect(splitPdf.totalPagesRemoved).to.eq(3); - expect(await pdf.countPages(splitPdf.file)).to.eq(9); + assert.strictEqual(splitPdf.totalPagesRemoved, 3); + assert.strictEqual(await pdf.countPages(splitPdf.file), 9); }); it("should not remove pages from a PDF because min pages are not met", async () => { @@ -108,8 +108,8 @@ describe("Test pdf operation #includeOptionalDeps", () => { onMinPages: 5, }; const splitPdf = await pdf.extractPages(inputSource.fileObject, pageOptions); - expect(splitPdf.totalPagesRemoved).to.eq(0); - expect(await pdf.countPages(splitPdf.file)).to.eq(2); + assert.strictEqual(splitPdf.totalPagesRemoved, 0); + assert.strictEqual(await pdf.countPages(splitPdf.file), 2); }); it("should not cut pages from a PDF because min pages are not met", async () => { @@ -124,8 +124,8 @@ describe("Test pdf operation #includeOptionalDeps", () => { onMinPages: 12, }; const splitPdf = await pdf.extractPages(inputSource.fileObject, pageOptions); - expect(splitPdf.totalPagesRemoved).to.eq(0); - expect(await pdf.countPages(splitPdf.file)).to.eq(2); + assert.strictEqual(splitPdf.totalPagesRemoved, 0); + assert.strictEqual(await pdf.countPages(splitPdf.file), 2); }); it("should cut the first and the 2 last pages from a PDF", async () => { @@ -140,8 +140,8 @@ describe("Test pdf operation #includeOptionalDeps", () => { onMinPages: 0, }; const newPdf = await pdf.extractPages(inputSource.fileObject, pageOptions); - expect(newPdf.totalPagesRemoved).to.eq(9); - expect(await pdf.countPages(newPdf.file)).to.eq(3); + assert.strictEqual(newPdf.totalPagesRemoved, 9); + assert.strictEqual(await pdf.countPages(newPdf.file), 3); // This is how the length of the word is set in the // raw PDF file. @@ -156,6 +156,6 @@ describe("Test pdf operation #includeOptionalDeps", () => { const expectedLengths = expectedResult.match(lengthRE); const inputDocLengths = inputSource.fileObject.toString("utf-8").match(lengthRE) || []; - expect(expectedLengths).to.have.ordered.members(inputDocLengths); + assert.deepStrictEqual(inputDocLengths, expectedLengths); }); }); diff --git a/tests/pdf/pdfTypes.spec.ts b/tests/pdf/pdfTypes.spec.ts index 4bd6238c2..b6c615912 100644 --- a/tests/pdf/pdfTypes.spec.ts +++ b/tests/pdf/pdfTypes.spec.ts @@ -1,5 +1,5 @@ import path from "path"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as pdf from "@/pdf/index.js"; import { PageOptions } from "@/input/index.js"; import { PageOptionsOperation, PathInput } from "@/index.js"; @@ -12,7 +12,7 @@ describe("Test pdf lib #includeOptionalDeps", () => { { inputPath: path.join(RESOURCE_PATH, "file_types/pdf/XfaForm.pdf") } ); await inputDoc.init(); - expect(await pdf.countPages(inputDoc.fileObject)).to.eq(1); + assert.strictEqual(await pdf.countPages(inputDoc.fileObject), 1); }); it("should open an encrypted XFA form PDF.", async () => { @@ -20,7 +20,7 @@ describe("Test pdf lib #includeOptionalDeps", () => { { inputPath: path.join(RESOURCE_PATH, "file_types/pdf/XfaForm_15p_encrypted.pdf") } ); await inputDoc.init(); - expect(await pdf.countPages(inputDoc.fileObject)).to.eq(15); + assert.strictEqual(await pdf.countPages(inputDoc.fileObject), 15); }); @@ -36,7 +36,7 @@ describe("Test pdf lib #includeOptionalDeps", () => { onMinPages: 1, }; const splitPdf = await pdf.extractPages(inputDoc.fileObject, pageOptions); - expect(splitPdf.totalPagesRemoved).to.eq(13); - expect(await pdf.countPages(splitPdf.file)).to.eq(2); + assert.strictEqual(splitPdf.totalPagesRemoved, 13); + assert.strictEqual(await pdf.countPages(splitPdf.file), 2); }); }); diff --git a/tests/v1/api/asyncResponse.spec.ts b/tests/v1/api/asyncResponse.spec.ts index 4501d95a3..ed109a581 100644 --- a/tests/v1/api/asyncResponse.spec.ts +++ b/tests/v1/api/asyncResponse.spec.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import assert from "node:assert/strict"; import { AsyncPredictResponse } from "@/v1/index.js"; import { promises as fs } from "fs"; import * as path from "path"; @@ -16,12 +16,12 @@ describe("MindeeV1 - Asynchronous API predict response", () => { data: JSON.parse(jsonData.toString()), }; const response = new AsyncPredictResponse(InvoiceSplitterV1, httpResponse.data); - expect(response.job).to.not.be.undefined; - expect(response.job.issuedAt.toISOString()).to.be.equals( + assert.ok(response.job); + assert.strictEqual(response.job.issuedAt.toISOString(), "2023-02-16T12:33:49.602Z" ); - expect(response.job.availableAt?.toISOString()).to.be.undefined; - expect(response.apiRequest.error).to.deep.equal({}); + assert.strictEqual(response.job.availableAt?.toISOString(), undefined); + assert.deepStrictEqual(response.apiRequest.error, {}); }); it("should parse a failed enqueue", async () => { @@ -31,7 +31,9 @@ describe("MindeeV1 - Asynchronous API predict response", () => { const httpResponse: StringDict = { data: JSON.parse(jsonData.toString()), }; - expect(isValidAsyncResponse(cleanRequestData(httpResponse.data))).to.be.false; + assert.strictEqual( + isValidAsyncResponse(cleanRequestData(httpResponse.data)), false + ); }); it("should parse a failed job", async () => { @@ -41,7 +43,9 @@ describe("MindeeV1 - Asynchronous API predict response", () => { const httpResponse: StringDict = { data: JSON.parse(jsonData.toString()), }; - expect(isValidAsyncResponse(cleanRequestData(httpResponse.data))).to.be.false; + assert.strictEqual( + isValidAsyncResponse(cleanRequestData(httpResponse.data)), false + ); }); it("should parse a job in progress", async () => { @@ -52,12 +56,12 @@ describe("MindeeV1 - Asynchronous API predict response", () => { data: JSON.parse(jsonData.toString()), }; const response = new AsyncPredictResponse(InvoiceSplitterV1, httpResponse.data); - expect(response.job).to.not.be.undefined; - expect(response.job.issuedAt.toISOString()).to.be.equals( + assert.ok(response.job); + assert.strictEqual(response.job.issuedAt.toISOString(), "2023-03-16T12:33:49.602Z" ); - expect(response.job.availableAt?.toISOString()).to.be.undefined; - expect(response.apiRequest.error).to.deep.equal({}); + assert.strictEqual(response.job.availableAt?.toISOString(), undefined); + assert.deepStrictEqual(response.apiRequest.error, {}); }); it("should parse a completed job", async () => { @@ -68,14 +72,14 @@ describe("MindeeV1 - Asynchronous API predict response", () => { data: JSON.parse(jsonData.toString()), }; const response = new AsyncPredictResponse(InvoiceSplitterV1, httpResponse.data); - expect(response.job).to.not.be.undefined; - expect(response.job.issuedAt.toISOString()).to.be.equals( + assert.ok(response.job); + assert.strictEqual(response.job.issuedAt.toISOString(), "2023-03-21T13:52:56.326Z" ); - expect(response.job.availableAt?.toISOString()).to.be.equals( + assert.strictEqual(response.job.availableAt?.toISOString(), "2023-03-21T13:53:00.990Z" ); - expect(response.job.milliSecsTaken)?.to.equals(4664); - expect(response.apiRequest.error).to.deep.equal({}); + assert.strictEqual(response.job.milliSecsTaken, 4664); + assert.deepStrictEqual(response.apiRequest.error, {}); }); }); diff --git a/tests/v1/api/endpoint.spec.ts b/tests/v1/api/endpoint.spec.ts index 460222cd2..bb2301065 100644 --- a/tests/v1/api/endpoint.spec.ts +++ b/tests/v1/api/endpoint.spec.ts @@ -1,6 +1,5 @@ import * as fs from "node:fs"; import * as path from "path"; -import { expect } from "chai"; import { MockAgent, setGlobalDispatcher } from "undici"; import { PathInput } from "@/index.js"; import { Client, product } from "@/v1/index.js"; @@ -47,10 +46,10 @@ describe("MindeeV1 - HTTP calls", () => { await assert.rejects( client.parse(product.InvoiceV4, doc), (error: any) => { - expect(error).to.be.instanceOf(MindeeHttp400Error); - expect(error.code).to.be.equals(400); - expect(error.message).to.be.undefined; - expect(error.details).to.deep.equal({ document: ["error message"] }); + assert.ok(error instanceof MindeeHttp400Error); + assert.strictEqual(error.code, 400); + assert.strictEqual(error.message, undefined); + assert.deepStrictEqual(error.details, { document: ["error message"] }); return true; }); }); @@ -61,10 +60,10 @@ describe("MindeeV1 - HTTP calls", () => { await assert.rejects( client.parse(product.InvoiceV4, doc), (error: any) => { - expect(error).to.be.instanceOf(MindeeHttp401Error); - expect(error.code).to.be.equals(401); - expect(error.message).to.be.equals("Authorization required"); - expect(error.details).to.be.equals("No token provided"); + assert.ok(error instanceof MindeeHttp401Error); + assert.strictEqual(error.code, 401); + assert.strictEqual(error.message, "Authorization required"); + assert.strictEqual(error.details, "No token provided"); return true; }); }); @@ -75,10 +74,10 @@ describe("MindeeV1 - HTTP calls", () => { await assert.rejects( client.parse(product.InvoiceV4, doc), (error: any) => { - expect(error).to.be.instanceOf(MindeeHttp429Error); - expect(error.code).to.be.equals(429); - expect(error.message).to.be.equals("Too many requests"); - expect(error.details).to.be.equals("Too Many Requests."); + assert.ok(error instanceof MindeeHttp429Error); + assert.strictEqual(error.code, 429); + assert.strictEqual(error.message, "Too many requests"); + assert.strictEqual(error.details, "Too Many Requests."); return true; }); }); @@ -89,10 +88,10 @@ describe("MindeeV1 - HTTP calls", () => { await assert.rejects( client.parse(product.InvoiceV4, doc), (error: any) => { - expect(error).to.be.instanceOf(MindeeHttp500Error); - expect(error.code).to.be.equals(500); - expect(error.message).to.be.equals("Inference failed"); - expect(error.details).to.be.equals("Can not run prediction: "); + assert.ok(error instanceof MindeeHttp500Error); + assert.strictEqual(error.code, 500); + assert.strictEqual(error.message, "Inference failed"); + assert.strictEqual(error.details, "Can not run prediction: "); return true; }); }); @@ -103,8 +102,8 @@ describe("MindeeV1 - HTTP calls", () => { await assert.rejects( client.parse(product.InvoiceV4, doc), (error: any) => { - expect(error).to.be.instanceOf(MindeeHttp500Error); - expect(error.code).to.be.equals(500); + assert.ok(error instanceof MindeeHttp500Error); + assert.strictEqual(error.code, 500); return true; }); }); @@ -117,10 +116,10 @@ describe ("Endpoint parameters" , () => { "dummy-endpoint", "dummy-account" ); - expect(customEndpoint.version).to.equal("1"); - expect(customEndpoint.settings.timeout).to.equal(120); - expect(customEndpoint.settings.hostname).to.equal("api.mindee.net"); - expect(customEndpoint.settings.apiKey).to.equal("dummy-api-key"); + assert.strictEqual(customEndpoint.version, "1"); + assert.strictEqual(customEndpoint.settings.timeout, 120); + assert.strictEqual(customEndpoint.settings.hostname, "api.mindee.net"); + assert.strictEqual(customEndpoint.settings.apiKey, "dummy-api-key"); }); it ("should initialize environment parameters properly", async () => { @@ -133,10 +132,10 @@ describe ("Endpoint parameters" , () => { "dummy-endpoint", "dummy-account" ); - expect(customEndpoint.version).to.equal("1"); - expect(customEndpoint.settings.timeout).to.equal(30); - expect(customEndpoint.settings.hostname).to.equal("v1-endpoint-host"); - expect(customEndpoint.settings.apiKey).to.equal("dummy-key"); + assert.strictEqual(customEndpoint.version, "1"); + assert.strictEqual(customEndpoint.settings.timeout, 30); + assert.strictEqual(customEndpoint.settings.hostname, "v1-endpoint-host"); + assert.strictEqual(customEndpoint.settings.apiKey, "dummy-key"); delete process.env.MINDEE_API_HOST; delete process.env.MINDEE_API_KEY; diff --git a/tests/v1/api/feedbackResponse.spec.ts b/tests/v1/api/feedbackResponse.spec.ts index eeb26cc58..24223f71d 100644 --- a/tests/v1/api/feedbackResponse.spec.ts +++ b/tests/v1/api/feedbackResponse.spec.ts @@ -1,5 +1,5 @@ import path from "path"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import { promises as fs } from "fs"; import { FeedbackResponse } from "@/v1/parsing/common/index.js"; import { V1_PRODUCT_PATH } from "../../index.js"; @@ -10,7 +10,7 @@ describe("MindeeV1 - Feedback response", () => { path.join(V1_PRODUCT_PATH, "invoices/feedback_response/empty.json") ); const feedbackResponse: FeedbackResponse = new FeedbackResponse(JSON.parse(jsonData.toString())); - expect(feedbackResponse.feedback).to.not.be.undefined; - expect(feedbackResponse.feedback.customer_address).to.be.null; + assert.ok(feedbackResponse.feedback); + assert.strictEqual(feedbackResponse.feedback.customer_address, null); }); }); diff --git a/tests/v1/api/response.spec.ts b/tests/v1/api/response.spec.ts index 226ff069e..4a45ca658 100644 --- a/tests/v1/api/response.spec.ts +++ b/tests/v1/api/response.spec.ts @@ -1,6 +1,6 @@ import { promises as fs } from "fs"; import * as path from "path"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import { PredictResponse } from "@/v1/index.js"; import { InvoiceV4, ReceiptV5 } from "@/v1/product/index.js"; import { V1_PRODUCT_PATH } from "../../index.js"; @@ -16,12 +16,12 @@ describe("MindeeV1 - Synchronous API predict response", () => { const jsonData = await fs.readFile(path.resolve(dataPath.receiptV5)); const httpResponse = JSON.parse(jsonData.toString()); const response = new PredictResponse(ReceiptV5, httpResponse); - expect(response.document.inference.prediction).to.not.be.undefined; - expect(response.document.inference.pages.length).to.be.equals(1); - expect(response.document.nPages).to.be.equals(1); + assert.ok(response.document.inference.prediction); + assert.strictEqual(response.document.inference.pages.length, 1); + assert.strictEqual(response.document.nPages, 1); response.document.inference.pages.forEach((page, idx) => { - expect(page.id).to.be.equals(idx); - expect(page.toString()).to.not.be.undefined; + assert.strictEqual(page.id, idx); + assert.ok(page.toString()); }); }); @@ -29,12 +29,12 @@ describe("MindeeV1 - Synchronous API predict response", () => { const jsonData = await fs.readFile(path.resolve(dataPath.invoiceV4)); const httpResponse = JSON.parse(jsonData.toString()); const response = new PredictResponse(InvoiceV4, httpResponse); - expect(response.document.inference.prediction).to.not.be.undefined; - expect(response.document.inference.pages.length).to.be.equals(1); - expect(response.document.nPages).to.be.equals(1); + assert.ok(response.document.inference.prediction); + assert.strictEqual(response.document.inference.pages.length, 1); + assert.strictEqual(response.document.nPages, 1); response.document.inference.pages.forEach((page, idx) => { - expect(page.id).to.be.equals(idx); - expect(page.toString()).to.not.be.undefined; + assert.strictEqual(page.id, idx); + assert.ok(page.toString()); }); }); diff --git a/tests/v1/clientInit.spec.ts b/tests/v1/clientInit.spec.ts index bdb59a748..079138749 100644 --- a/tests/v1/clientInit.spec.ts +++ b/tests/v1/clientInit.spec.ts @@ -1,5 +1,4 @@ import { Client } from "@/v1/index.js"; -import { expect } from "chai"; import assert from "node:assert/strict"; describe("Test client initialization", () => { @@ -13,11 +12,11 @@ describe("Test client initialization", () => { it("should create a client with an API key", () => { const client = new Client({ apiKey: "invalid-api-key" }); - expect(client).to.exist; + assert.ok(client); }); it("should create a client in debug mode", () => { const client = new Client({ apiKey: "invalid-api-key", debug: true }); - expect(client).to.exist; + assert.ok(client); }); }); diff --git a/tests/v1/extraction/invoiceSplitterExtractor.spec.ts b/tests/v1/extraction/invoiceSplitterExtractor.spec.ts index d79c63014..fa7a35382 100644 --- a/tests/v1/extraction/invoiceSplitterExtractor.spec.ts +++ b/tests/v1/extraction/invoiceSplitterExtractor.spec.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import assert from "node:assert/strict"; import { promises as fs } from "fs"; import path from "path"; import { InvoiceSplitterV1 } from "@/v1/product/index.js"; @@ -20,14 +20,14 @@ describe("A multi-page invoice document #includeOptionalDeps", () => { await inputSample.init(); const extractedInvoices = await extractInvoices(inputSample, doc); - expect(extractedInvoices.length).to.be.equals(3); - expect(extractedInvoices[0].buffer).to.be.not.null; - expect(extractedInvoices[1].buffer).to.be.not.null; - expect(extractedInvoices[0].pageIdMin).to.be.equals(0); - expect(extractedInvoices[0].pageIdMax).to.be.equals(0); - expect(extractedInvoices[1].pageIdMin).to.be.equals(1); - expect(extractedInvoices[1].pageIdMax).to.be.equals(3); - expect(extractedInvoices[2].pageIdMax).to.be.equals(4); - expect(extractedInvoices[2].pageIdMax).to.be.equals(4); + assert.strictEqual(extractedInvoices.length, 3); + assert.ok(extractedInvoices[0].buffer); + assert.ok(extractedInvoices[1].buffer); + assert.strictEqual(extractedInvoices[0].pageIdMin, 0); + assert.strictEqual(extractedInvoices[0].pageIdMax, 0); + assert.strictEqual(extractedInvoices[1].pageIdMin, 1); + assert.strictEqual(extractedInvoices[1].pageIdMax, 3); + assert.strictEqual(extractedInvoices[2].pageIdMax, 4); + assert.strictEqual(extractedInvoices[2].pageIdMax, 4); }); }); diff --git a/tests/v1/extraction/invoiceSplitterReconstruction.spec.ts b/tests/v1/extraction/invoiceSplitterReconstruction.spec.ts index 1f7d08a55..e6d425c82 100644 --- a/tests/v1/extraction/invoiceSplitterReconstruction.spec.ts +++ b/tests/v1/extraction/invoiceSplitterReconstruction.spec.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import assert from "node:assert/strict"; import { promises as fs } from "fs"; import * as path from "path"; import { Document } from "@/v1/index.js"; @@ -17,16 +17,16 @@ describe("MindeeV1 - A Multipage Invoice Document #includeOptionalDeps", () => { const response = JSON.parse(jsonData.toString()); const doc = new Document(InvoiceSplitterV1, response.document); const extractedInvoices = await extractInvoices(sourceDoc, doc.inference, false); - expect(extractedInvoices.length).to.be.equals(3); - expect(extractedInvoices[0].pageIdMin).to.be.equal(0); - expect(extractedInvoices[0].pageIdMax).to.be.equal(0); - expect(extractedInvoices[1].pageIdMin).to.be.equal(1); - expect(extractedInvoices[1].pageIdMax).to.be.equal(3); - expect(extractedInvoices[2].pageIdMin).to.be.equal(4); - expect(extractedInvoices[2].pageIdMax).to.be.equal(4); + assert.strictEqual(extractedInvoices.length, 3); + assert.strictEqual(extractedInvoices[0].pageIdMin, 0); + assert.strictEqual(extractedInvoices[0].pageIdMax, 0); + assert.strictEqual(extractedInvoices[1].pageIdMin, 1); + assert.strictEqual(extractedInvoices[1].pageIdMax, 3); + assert.strictEqual(extractedInvoices[2].pageIdMin, 4); + assert.strictEqual(extractedInvoices[2].pageIdMax, 4); for (const extractedInvoice of extractedInvoices) { - expect(Buffer.byteLength(extractedInvoice.asSource().fileObject)).to.be.lessThan(10485760); - expect(Buffer.byteLength(extractedInvoice.asSource().fileObject)).to.be.greaterThan(100000); + assert.ok(Buffer.byteLength(extractedInvoice.asSource().fileObject) < 10485760); + assert.ok(Buffer.byteLength(extractedInvoice.asSource().fileObject) > 100000); } }); @@ -39,6 +39,6 @@ describe("MindeeV1 - A Multipage Invoice Document #includeOptionalDeps", () => { const response = JSON.parse(jsonData.toString()); const doc = new Document(InvoiceSplitterV1, response.document); const extractedConfidentInvoices = await extractInvoices(sourceDoc, doc.inference, true); - expect(extractedConfidentInvoices.length).to.be.equals(2); + assert.strictEqual(extractedConfidentInvoices.length, 2); }); }); diff --git a/tests/v1/extraction/multiReceiptsExtractor.spec.ts b/tests/v1/extraction/multiReceiptsExtractor.spec.ts index 16f7b4271..da4ab6bf0 100644 --- a/tests/v1/extraction/multiReceiptsExtractor.spec.ts +++ b/tests/v1/extraction/multiReceiptsExtractor.spec.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import assert from "node:assert/strict"; import { promises as fs } from "fs"; import path from "path"; import { MultiReceiptsDetectorV1 } from "@/v1/product/index.js"; @@ -21,11 +21,11 @@ describe("Multi-Receipt #includeOptionalDeps", () => { const inputSample = new PathInput({ inputPath: dataPath.fileSample }); await inputSample.init(); const extractedReceipts = await extractReceipts(inputSample, doc); - expect(extractedReceipts.length).to.be.equals(6); + assert.strictEqual(extractedReceipts.length, 6); for (let i = 0; i < extractedReceipts.length; i++) { - expect(extractedReceipts[i].buffer).to.be.not.null; - expect(extractedReceipts[i].pageId).to.be.equals(0); - expect(extractedReceipts[i].receiptId).to.be.equals(i); + assert.ok(extractedReceipts[i].buffer); + assert.strictEqual(extractedReceipts[i].pageId, 0); + assert.strictEqual(extractedReceipts[i].receiptId, i); } }); }); @@ -37,27 +37,27 @@ describe("Multi-Receipt #includeOptionalDeps", () => { const inputSample = new PathInput({ inputPath: dataPath.multiPageSample }); await inputSample.init(); const extractedReceipts = await extractReceipts(inputSample, doc); - expect(extractedReceipts.length).to.be.equals(5); + assert.strictEqual(extractedReceipts.length, 5); - expect(extractedReceipts[0].buffer).to.be.not.null; - expect(extractedReceipts[0].pageId).to.be.equals(0); - expect(extractedReceipts[0].receiptId).to.be.equals(0); + assert.ok(extractedReceipts[0].buffer); + assert.strictEqual(extractedReceipts[0].pageId, 0); + assert.strictEqual(extractedReceipts[0].receiptId, 0); - expect(extractedReceipts[1].buffer).to.be.not.null; - expect(extractedReceipts[1].pageId).to.be.equals(0); - expect(extractedReceipts[1].receiptId).to.be.equals(1); + assert.ok(extractedReceipts[1].buffer); + assert.strictEqual(extractedReceipts[1].pageId, 0); + assert.strictEqual(extractedReceipts[1].receiptId, 1); - expect(extractedReceipts[2].buffer).to.be.not.null; - expect(extractedReceipts[2].pageId).to.be.equals(0); - expect(extractedReceipts[2].receiptId).to.be.equals(2); + assert.ok(extractedReceipts[2].buffer); + assert.strictEqual(extractedReceipts[2].pageId, 0); + assert.strictEqual(extractedReceipts[2].receiptId, 2); - expect(extractedReceipts[3].buffer).to.be.not.null; - expect(extractedReceipts[3].pageId).to.be.equals(1); - expect(extractedReceipts[3].receiptId).to.be.equals(0); + assert.ok(extractedReceipts[3].buffer); + assert.strictEqual(extractedReceipts[3].pageId, 1); + assert.strictEqual(extractedReceipts[3].receiptId, 0); - expect(extractedReceipts[4].buffer).to.be.not.null; - expect(extractedReceipts[4].pageId).to.be.equals(1); - expect(extractedReceipts[4].receiptId).to.be.equals(1); + assert.ok(extractedReceipts[4].buffer); + assert.strictEqual(extractedReceipts[4].pageId, 1); + assert.strictEqual(extractedReceipts[4].receiptId, 1); }); }); }); diff --git a/tests/v1/extraction/multiReceiptsReconstruction.integration.ts b/tests/v1/extraction/multiReceiptsReconstruction.integration.ts index 699485ad2..1f4a82dd9 100644 --- a/tests/v1/extraction/multiReceiptsReconstruction.integration.ts +++ b/tests/v1/extraction/multiReceiptsReconstruction.integration.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as path from "path"; import { Client } from "@/v1/index.js"; import { MultiReceiptsDetectorV1, ReceiptV5 } from "@/v1/product/index.js"; @@ -33,43 +33,47 @@ describe("MindeeV1 - #includeOptionalDeps", () => { it("should send to the server and cut properly", async () => { const multiReceiptResult = await client.parse(MultiReceiptsDetectorV1, sourceDoc); - expect(multiReceiptResult.document?.inference.prediction.receipts.length).to.be.equals(5); + assert.strictEqual(multiReceiptResult.document?.inference.prediction.receipts.length, 5); const extractedReceipts = await extractReceipts(sourceDoc, multiReceiptResult.document!.inference); - expect(extractedReceipts.length).to.be.equals(5); - expect(multiReceiptResult.document?.inference.pages[0].orientation?.value).to.be.equals(0); - expect(multiReceiptResult.document?.inference.pages[1].orientation?.value).to.be.equals(0); + assert.strictEqual(extractedReceipts.length, 5); + assert.strictEqual(multiReceiptResult.document?.inference.pages[0].orientation?.value, 0); + assert.strictEqual(multiReceiptResult.document?.inference.pages[1].orientation?.value, 0); const receiptsResults = []; for (const extractedReceipt of extractedReceipts) { const localInput = extractedReceipt.asSource(); receiptsResults.push(await client.parse(ReceiptV5, localInput)); await setTimeout(1000); } - expect(receiptsResults[0].document.inference.prediction.lineItems.length).to.be.equals(5); - expect(receiptsResults[0].document.inference.prediction.lineItems[0].totalAmount).to.be.equals(70); - expect(receiptsResults[0].document.inference.prediction.lineItems[1].totalAmount).to.be.equals(12); - expect(receiptsResults[0].document.inference.prediction.lineItems[2].totalAmount).to.be.equals(14); - expect(receiptsResults[0].document.inference.prediction.lineItems[3].totalAmount).to.be.equals(11); - expect(receiptsResults[0].document.inference.prediction.lineItems[4].totalAmount).to.be.equals(5.6); + const firstPrediction = receiptsResults[0].document.inference.prediction; + assert.strictEqual(firstPrediction.lineItems.length, 5); + assert.strictEqual(firstPrediction.lineItems[0].totalAmount, 70); + assert.strictEqual(firstPrediction.lineItems[1].totalAmount, 12); + assert.strictEqual(firstPrediction.lineItems[2].totalAmount, 14); + assert.strictEqual(firstPrediction.lineItems[3].totalAmount, 11); + assert.strictEqual(firstPrediction.lineItems[4].totalAmount, 5.6); - expect(receiptsResults[1].document.inference.prediction.lineItems.length).to.be.equals(7); - expect(receiptsResults[1].document.inference.prediction.lineItems[0].totalAmount).to.be.equals(6); - expect(receiptsResults[1].document.inference.prediction.lineItems[1].totalAmount).to.be.equals(11); - expect(receiptsResults[1].document.inference.prediction.lineItems[2].totalAmount).to.be.equals(67.2); - expect(receiptsResults[1].document.inference.prediction.lineItems[3].totalAmount).to.be.equals(19.2); - expect(receiptsResults[1].document.inference.prediction.lineItems[4].totalAmount).to.be.equals(7); - expect(receiptsResults[1].document.inference.prediction.lineItems[5].totalAmount).to.be.equals(5.5); - expect(receiptsResults[1].document.inference.prediction.lineItems[6].totalAmount).to.be.equals(36); + const secondPrediction = receiptsResults[1].document.inference.prediction; + assert.strictEqual(secondPrediction.lineItems.length, 7); + assert.strictEqual(secondPrediction.lineItems[0].totalAmount, 6); + assert.strictEqual(secondPrediction.lineItems[1].totalAmount, 11); + assert.strictEqual(secondPrediction.lineItems[2].totalAmount, 67.2); + assert.strictEqual(secondPrediction.lineItems[3].totalAmount, 19.2); + assert.strictEqual(secondPrediction.lineItems[4].totalAmount, 7); + assert.strictEqual(secondPrediction.lineItems[5].totalAmount, 5.5); + assert.strictEqual(secondPrediction.lineItems[6].totalAmount, 36); - expect(receiptsResults[2].document.inference.prediction.lineItems.length).to.be.equals(1); - expect(receiptsResults[2].document.inference.prediction.lineItems[0].totalAmount).to.be.equals(275); + const thirdPrediction = receiptsResults[2].document.inference.prediction; + assert.strictEqual(thirdPrediction.lineItems.length, 1); + assert.strictEqual(thirdPrediction.lineItems[0].totalAmount, 275); - expect(receiptsResults[3].document.inference.prediction.lineItems.length).to.be.equals(2); - expect(receiptsResults[3].document.inference.prediction.lineItems[0].totalAmount).to.be.equals(11.5); - expect(receiptsResults[3].document.inference.prediction.lineItems[1].totalAmount).to.be.equals(2); - - expect(receiptsResults[4].document.inference.prediction.lineItems.length).to.be.equals(1); - expect(receiptsResults[4].document.inference.prediction.lineItems[0].totalAmount).to.be.equals(16.5); + const fourthPrediction = receiptsResults[3].document.inference.prediction; + assert.strictEqual(fourthPrediction.lineItems.length, 2); + assert.strictEqual(fourthPrediction.lineItems[0].totalAmount, 11.5); + assert.strictEqual(fourthPrediction.lineItems[1].totalAmount, 2); + const fifthPrediction = receiptsResults[4].document.inference.prediction; + assert.strictEqual(fifthPrediction.lineItems.length, 1); + assert.strictEqual(fifthPrediction.lineItems[0].totalAmount, 16.5); }).timeout(60000); }); @@ -86,14 +90,14 @@ describe("MindeeV1 - #includeOptionalDeps", () => { it("should send to the server and cut properly", async () => { const multiReceiptResult = await client.parse(MultiReceiptsDetectorV1, sourceDoc); - expect(multiReceiptResult.document?.inference.prediction.receipts.length).to.be.equals(1); + assert.strictEqual(multiReceiptResult.document?.inference.prediction.receipts.length, 1); const receipts = await extractReceipts(sourceDoc, multiReceiptResult.document!.inference); - expect(receipts.length).to.be.equals(1); + assert.strictEqual(receipts.length, 1); const receiptResult = await client.parse(ReceiptV5, receipts[0].asSource()); - expect(receiptResult.document.inference.prediction.lineItems.length).to.be.equals(1); - expect(receiptResult.document.inference.prediction.lineItems[0].totalAmount).to.be.equals(10.2); - expect(receiptResult.document.inference.prediction.taxes.length).to.be.equals(1); - expect(receiptResult.document.inference.prediction.taxes[0].value).to.be.equals(1.7); + assert.strictEqual(receiptResult.document.inference.prediction.lineItems.length, 1); + assert.strictEqual(receiptResult.document.inference.prediction.lineItems[0].totalAmount, 10.2); + assert.strictEqual(receiptResult.document.inference.prediction.taxes.length, 1); + assert.strictEqual(receiptResult.document.inference.prediction.taxes[0].value, 1.7); }).timeout(60000); }); }); diff --git a/tests/v1/extraction/multiReceiptsReconstruction.spec.ts b/tests/v1/extraction/multiReceiptsReconstruction.spec.ts index c0ede55cd..3da66ae31 100644 --- a/tests/v1/extraction/multiReceiptsReconstruction.spec.ts +++ b/tests/v1/extraction/multiReceiptsReconstruction.spec.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import assert from "node:assert/strict"; import { promises as fs } from "fs"; import * as path from "path"; import { PathInput } from "@/index.js"; @@ -38,13 +38,13 @@ rotations.forEach(({ angle, suffix }) => { }); it("should be split into the proper receipts", async () => { - expect(extractedReceipts.length).to.be.equals(6); + assert.strictEqual(extractedReceipts.length, 6); let i = 0; for (const extractedReceipt of extractedReceipts) { - expect(extractedReceipt.pageId).to.be.equal(0); - expect(extractedReceipt.receiptId).to.be.equal(i); - expect(Buffer.byteLength(extractedReceipt.asSource().fileObject)).to.be.lessThan(10485760); - expect(Buffer.byteLength(extractedReceipt.asSource().fileObject)).to.be.greaterThan(100000); + assert.strictEqual(extractedReceipt.pageId, 0); + assert.strictEqual(extractedReceipt.receiptId, i); + assert.ok(Buffer.byteLength(extractedReceipt.asSource().fileObject) < 10485760); + assert.ok(Buffer.byteLength(extractedReceipt.asSource().fileObject) > 100000); i++; } }); @@ -59,13 +59,13 @@ rotations.forEach(({ angle, suffix }) => { const pdfStat = await fs.stat(path.join(RESOURCE_PATH, `output/${outputPrefix}.pdf`)); // Arbitrary to assert noticeable discrepancies between OSes - expect(pdfStat.size).to.be.greaterThan(500000); + assert.ok(pdfStat.size > 500000); const jpgStat = await fs.stat(path.join(RESOURCE_PATH, `output/${outputPrefix}.jpg`)); - expect(jpgStat.size).to.be.greaterThan(40000); + assert.ok(jpgStat.size > 40000); const pngStat = await fs.stat(path.join(RESOURCE_PATH, `output/${outputPrefix}.png`)); - expect(pngStat.size).to.be.greaterThan(290000); + assert.ok(pngStat.size > 290000); i++; } }).timeout(20000); diff --git a/tests/v1/extras/extras.integration.ts b/tests/v1/extras/extras.integration.ts index 2d8faeb14..8967aa54c 100644 --- a/tests/v1/extras/extras.integration.ts +++ b/tests/v1/extras/extras.integration.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as mindee from "@/index.js"; import path from "path"; import { V1_PRODUCT_PATH } from "../../index.js"; @@ -19,7 +19,7 @@ describe("MindeeV1 - Extras Integration Tests", async () => { const response = await client.parse( mindee.v1.product.InvoiceV4, sample, { cropper: true } ); - expect(response.document.inference.pages[0]?.extras?.cropper).to.exist; + assert.ok(response.document.inference.pages[0]?.extras?.cropper); }).timeout(70000); it("should send full text OCR extra", async () => { @@ -30,7 +30,7 @@ describe("MindeeV1 - Extras Integration Tests", async () => { const response = await client.enqueueAndParse( mindee.v1.product.InternationalIdV2, sample, { fullText: true } ); - expect(response.document?.extras?.fullTextOcr).to.exist; + assert.ok(response.document?.extras?.fullTextOcr); }).timeout(70000); @@ -42,8 +42,8 @@ describe("MindeeV1 - Extras Integration Tests", async () => { const response = await client.parse( mindee.v1.product.FinancialDocumentV1, sample, { allWords: true } ); - expect(response.document?.ocr).to.exist; - expect(response.document?.ocr?.toString()).to.not.be.empty; + assert.ok(response.document?.ocr); + assert.ok(response.document?.ocr?.toString()); }).timeout(70000); @@ -55,8 +55,8 @@ describe("MindeeV1 - Extras Integration Tests", async () => { const response = await client.enqueueAndParse( mindee.v1.product.FinancialDocumentV1, sample, { allWords: true } ); - expect(response.document?.ocr).to.exist; - expect(response.document?.ocr?.toString()).to.not.be.empty; + assert.ok(response.document?.ocr); + assert.ok(response.document?.ocr?.toString()); }).timeout(70000); }); diff --git a/tests/v1/extras/fullTextOcr.spec.ts b/tests/v1/extras/fullTextOcr.spec.ts index d91874f3c..4948c862a 100644 --- a/tests/v1/extras/fullTextOcr.spec.ts +++ b/tests/v1/extras/fullTextOcr.spec.ts @@ -1,6 +1,6 @@ import { promises as fs } from "fs"; import path from "path"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import { AsyncPredictResponse } from "@/v1/index.js"; import { InternationalIdV2 } from "@/v1/product/index.js"; import { RESOURCE_PATH } from "../../index.js"; @@ -16,8 +16,9 @@ async function loadDocument() { describe("MindeeV1 - Full Text Ocr", async () => { it("should load a Full Text OCR prediction at document level", async () => { - const expectedText = (await fs.readFile(path.join(fullTextOcrDir, "full_text_ocr.txt"))).toString(); + const expectedText = (await fs.readFile(path.join(fullTextOcrDir, "full_text_ocr.txt"))) + .toString(); const fullTextOcr = await loadDocument(); - expect(fullTextOcr).to.be.equals(expectedText.trim()); + assert.strictEqual(fullTextOcr, expectedText.trim()); }); }); diff --git a/tests/v1/extras/ocr.spec.ts b/tests/v1/extras/ocr.spec.ts index 5a1093486..225a15877 100644 --- a/tests/v1/extras/ocr.spec.ts +++ b/tests/v1/extras/ocr.spec.ts @@ -1,6 +1,6 @@ import { promises as fs } from "fs"; import * as path from "path"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import { ReceiptV5 } from "@/v1/product/index.js"; import { Document } from "@/v1/index.js"; import { RESOURCE_PATH } from "../../index.js"; @@ -21,7 +21,7 @@ describe("MindeeV1 - When getting all lines in an OCR", () => { const allWordsStart = doc.ocr.mVisionV1.pages[0].allWords; // Trigger a potential change in list order const allWordsEnd = doc.ocr.mVisionV1.pages[0].allWords; - expect(allWordsStart).to.be.equals(allWordsEnd); + assert.strictEqual(allWordsStart, allWordsEnd); }); it("should match expected string exactly", async () => { @@ -32,6 +32,6 @@ describe("MindeeV1 - When getting all lines in an OCR", () => { if (!doc.ocr) { throw new Error("No ocr."); } - expect(doc.ocr.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.ocr.toString(), docString.toString()); }); }); diff --git a/tests/v1/input/localResponse.spec.ts b/tests/v1/input/localResponse.spec.ts index 436920718..bbc502efa 100644 --- a/tests/v1/input/localResponse.spec.ts +++ b/tests/v1/input/localResponse.spec.ts @@ -1,5 +1,5 @@ import * as fs from "node:fs/promises"; -import { expect } from "chai"; +import assert from "node:assert"; import path from "path"; import { AsyncPredictResponse, LocalResponse, PredictResponse } from "@/v1/index.js"; import { InternationalIdV2, InvoiceV4, MultiReceiptsDetectorV1 } from "@/v1/product/index.js"; @@ -21,55 +21,65 @@ describe("MindeeV1 - Load Local Response", () => { const fileObj = await fs.readFile(filePath, { encoding: "utf-8" }); const localResponse = new LocalResponse(fileObj); await localResponse.init(); - expect(localResponse.asDict()).to.not.be.null; - expect(localResponse.isValidHmacSignature(dummySecretKey, "invalid signature")).to.be.false; - expect(localResponse.getHmacSignature(dummySecretKey)).to.eq(signature); - expect(localResponse.isValidHmacSignature(dummySecretKey, signature)).to.be.true; + assert.ok(localResponse.asDict()); + assert.strictEqual( + localResponse.isValidHmacSignature(dummySecretKey, "invalid signature"), false + ); + assert.strictEqual(localResponse.getHmacSignature(dummySecretKey), signature); + assert.ok(localResponse.isValidHmacSignature(dummySecretKey, signature)); }); it("should load a file properly.", async () => { const localResponse = new LocalResponse(filePath); await localResponse.init(); - expect(localResponse.asDict()).to.not.be.null; - expect(localResponse.isValidHmacSignature(dummySecretKey, "invalid signature")).to.be.false; - expect(localResponse.getHmacSignature(dummySecretKey)).to.eq(signature); - expect(localResponse.isValidHmacSignature(dummySecretKey, signature)).to.be.true; + assert.ok(localResponse.asDict()); + assert.strictEqual( + localResponse.isValidHmacSignature(dummySecretKey, "invalid signature"), false + ); + assert.strictEqual(localResponse.getHmacSignature(dummySecretKey), signature); + assert.ok(localResponse.isValidHmacSignature(dummySecretKey, signature)); }); it("should load a buffer properly.", async () => { - const fileStr = (await fs.readFile(filePath, { encoding: "utf-8" })).replace(/\r/g, "").replace(/\n/g, ""); + const fileStr = (await fs.readFile(filePath, { encoding: "utf-8" })) + .replace(/\r/g, "") + .replace(/\n/g, ""); const fileBuffer = Buffer.from(fileStr, "utf-8"); const localResponse = new LocalResponse(fileBuffer); await localResponse.init(); - expect(localResponse.asDict()).to.not.be.null; - expect(localResponse.isValidHmacSignature(dummySecretKey, "invalid signature")).to.be.false; - expect(localResponse.getHmacSignature(dummySecretKey)).to.eq(signature); - expect(localResponse.isValidHmacSignature(dummySecretKey, signature)).to.be.true; + assert.ok(localResponse.asDict()); + assert.strictEqual( + localResponse.isValidHmacSignature(dummySecretKey, "invalid signature"), false + ); + assert.strictEqual(localResponse.getHmacSignature(dummySecretKey), signature); + assert.ok(localResponse.isValidHmacSignature(dummySecretKey, signature)); }); it("should load into a sync prediction.", async () => { const fileObj = await fs.readFile(multiReceiptsDetectorPath, { encoding: "utf-8" }); const localResponse = new LocalResponse(fileObj); const prediction = await localResponse.loadPrediction(MultiReceiptsDetectorV1); - expect(prediction).to.be.an.instanceof(PredictResponse); - - expect(JSON.stringify(prediction.getRawHttp())).to.eq(JSON.stringify(JSON.parse(fileObj))); + assert.ok(prediction instanceof PredictResponse); + assert.strictEqual( + JSON.stringify(prediction.getRawHttp()), JSON.stringify(JSON.parse(fileObj)) + ); }); it("should load a failed prediction.", async () => { const fileObj = await fs.readFile(failedPath, { encoding: "utf-8" }); const localResponse = new LocalResponse(fileObj); const prediction = await localResponse.loadPrediction(InvoiceV4); - expect(prediction).to.be.an.instanceof(AsyncPredictResponse); - expect((prediction as AsyncPredictResponse).job.status).to.be.eq("failed"); + assert.ok(prediction instanceof AsyncPredictResponse); + assert.strictEqual((prediction as AsyncPredictResponse).job.status, "failed"); }); it("should load into an async prediction.", async () => { const fileObj = await fs.readFile(internationalIdPath, { encoding: "utf-8" }); const localResponse = new LocalResponse(fileObj); const prediction = await localResponse.loadPrediction(InternationalIdV2); - expect(prediction).to.be.an.instanceof(AsyncPredictResponse); - - expect(JSON.stringify(prediction.getRawHttp())).to.eq(JSON.stringify(JSON.parse(fileObj))); + assert.ok(prediction instanceof AsyncPredictResponse); + assert.strictEqual( + JSON.stringify(prediction.getRawHttp()), JSON.stringify(JSON.parse(fileObj)) + ); }); }); diff --git a/tests/v1/input/sources.integration.ts b/tests/v1/input/sources.integration.ts index a4a485a2e..581e2ef70 100644 --- a/tests/v1/input/sources.integration.ts +++ b/tests/v1/input/sources.integration.ts @@ -1,6 +1,6 @@ import * as mindee from "@/index.js"; import { InvoiceV4 } from "@/v1/product/index.js"; -import { expect } from "chai"; +import assert from "node:assert"; import { promises as fs } from "fs"; import { createReadStream } from "node:fs"; import path from "path"; @@ -20,7 +20,7 @@ describe("MindeeV1 - File Input Integration Tests", async () => { const pathInput = new PathInput({ inputPath: filePath }); await pathInput.init(); const result = await client.parse(InvoiceV4, pathInput); - expect(result.document.id).to.be.a("string"); + assert.strictEqual(typeof result.document.id, "string"); }).timeout(60000); it("should send a base64 document", async () => { @@ -28,7 +28,7 @@ describe("MindeeV1 - File Input Integration Tests", async () => { const base64Content = content.toString("base64"); const base64Input = new Base64Input({ inputString: base64Content, filename: "testFile.jpg" }); const result = await client.parse(InvoiceV4, base64Input); - expect(result.document.id).to.be.a("string"); + assert.strictEqual(typeof result.document.id, "string"); }).timeout(60000); it("should send a document from a readable stream", async () => { @@ -40,7 +40,7 @@ describe("MindeeV1 - File Input Integration Tests", async () => { const buffer = Buffer.concat(chunks); const streamInput = new BufferInput({ buffer: buffer, filename: "testFile.jpg" }); const result = await client.parse(InvoiceV4, streamInput); - expect(result.document.id).to.be.a("string"); + assert.strictEqual(typeof result.document.id, "string"); }).timeout(60000); @@ -48,7 +48,7 @@ describe("MindeeV1 - File Input Integration Tests", async () => { const inputBytes = await fs.readFile(filePath); const bytesInput = new BytesInput({ inputBytes: inputBytes, filename: "testFile.jpg" }); const result = await client.parse(InvoiceV4, bytesInput); - expect(result.document.id).to.be.a("string"); + assert.strictEqual(typeof result.document.id, "string"); }).timeout(60000); it("should send a document from buffer", async () => { @@ -56,7 +56,7 @@ describe("MindeeV1 - File Input Integration Tests", async () => { const bufferInput = new BufferInput({ buffer: buffer, filename: "testFile.jpg" }); await bufferInput.init(); const result = await client.parse(InvoiceV4, bufferInput); - expect(result.document.id).to.be.a("string"); + assert.strictEqual(typeof result.document.id, "string"); }).timeout(60000); it("should send a document from a URL", async () => { @@ -65,6 +65,6 @@ describe("MindeeV1 - File Input Integration Tests", async () => { const urlInput = new UrlInput({ url: url }); await urlInput.init(); const result = await client.parse(InvoiceV4, urlInput); - expect(result.document.id).to.be.a("string"); + assert.strictEqual(typeof result.document.id, "string"); }).timeout(60000); }).timeout(60000); diff --git a/tests/v1/input/urlInputSource.integration.ts b/tests/v1/input/urlInputSource.integration.ts index 5e1d16357..c3ee67b3f 100644 --- a/tests/v1/input/urlInputSource.integration.ts +++ b/tests/v1/input/urlInputSource.integration.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import assert from "node:assert"; import { UrlInput } from "@/index.js"; import { Client } from "@/v1/index.js"; import { InvoiceV4 } from "@/v1/product/index.js"; @@ -17,8 +17,8 @@ describe("MindeeV1 - URL Input Integration Test", async () => { await remoteInput.init(); const localInput = await remoteInput.asLocalInputSource(); - expect(localInput.filename).to.equal("invoice_5p.pdf"); + assert.strictEqual(localInput.filename, "invoice_5p.pdf"); const result = await client.parse(InvoiceV4, localInput); - expect(result.document.nPages).to.equal(5); + assert.strictEqual(result.document.nPages, 5); }).timeout(60000); }); diff --git a/tests/v1/parsing/standard/amount.spec.ts b/tests/v1/parsing/standard/amount.spec.ts index 584c23f5c..e16fcc270 100644 --- a/tests/v1/parsing/standard/amount.spec.ts +++ b/tests/v1/parsing/standard/amount.spec.ts @@ -1,5 +1,5 @@ import { AmountField } from "@/v1/parsing/standard/index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; describe("Test AmountField field", () => { it("Should create an AmountField field", () => { @@ -14,9 +14,9 @@ describe("Test AmountField field", () => { ], }; const amount = new AmountField({ prediction }); - expect(amount.value).to.be.equal(2); - expect(amount.confidence).to.be.equal(0.1); - expect(amount.toString()).to.be.equal("2.00"); + assert.strictEqual(amount.value, 2); + assert.strictEqual(amount.confidence, 0.1); + assert.strictEqual(amount.toString(), "2.00"); }); it("Should create an AmountField field with a N/A value as input", () => { @@ -25,8 +25,8 @@ describe("Test AmountField field", () => { confidence: 0.1, }; const amount = new AmountField({ prediction }); - expect(amount.value).to.be.equal(undefined); - expect(amount.confidence).to.be.equal(0.0); - expect(amount.toString()).to.be.equal(""); + assert.strictEqual(amount.value, undefined); + assert.strictEqual(amount.confidence, 0.0); + assert.strictEqual(amount.toString(), ""); }); }); diff --git a/tests/v1/parsing/standard/classification.spec.ts b/tests/v1/parsing/standard/classification.spec.ts index cf7674cc4..f198c142d 100644 --- a/tests/v1/parsing/standard/classification.spec.ts +++ b/tests/v1/parsing/standard/classification.spec.ts @@ -1,5 +1,5 @@ import { ClassificationField } from "@/v1/parsing/standard/index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; describe("Test Classification field", () => { it("Should create a Classification field", () => { @@ -8,7 +8,7 @@ describe("Test Classification field", () => { confidence: 0.1, }; const field = new ClassificationField({ prediction }); - expect(field.value).to.be.equal(prediction.value); + assert.strictEqual(field.value, prediction.value); }); it("Should create a Classification field with no confidence", () => { @@ -16,6 +16,6 @@ describe("Test Classification field", () => { value: "N/A", }; const field = new ClassificationField({ prediction }); - expect(field.confidence).to.be.equals(0); + assert.strictEqual(field.confidence, 0); }); }); diff --git a/tests/v1/parsing/standard/date.spec.ts b/tests/v1/parsing/standard/date.spec.ts index a928f97ce..0e70da2b7 100644 --- a/tests/v1/parsing/standard/date.spec.ts +++ b/tests/v1/parsing/standard/date.spec.ts @@ -1,5 +1,6 @@ import { DateField } from "@/v1/parsing/standard/index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; +import { BoundingBox } from "@/geometry/index.js"; describe("Test Date field", () => { it("Should create a Date field", () => { @@ -12,13 +13,17 @@ describe("Test Date field", () => { [0.414, 0.831], [0.016, 0.831], ], + // eslint-disable-next-line @typescript-eslint/naming-convention,camelcase is_computed: true }; const field = new DateField({ prediction }); - expect(field.value).to.be.equal(prediction.value); - expect(field.dateObject).to.be.deep.equal(new Date(prediction.value)); - expect(field.boundingBox).to.have.deep.members(prediction["polygon"]); - expect(field.isComputed).to.be.true; + assert.strictEqual(field.value, prediction.value); + assert.deepStrictEqual(field.dateObject, new Date(prediction.value)); + assert.deepStrictEqual( + // @ts-expect-error: prediction polygon is not typed + field.boundingBox, new BoundingBox(...prediction["polygon"]) + ); + assert.ok(field.isComputed); }); it("Should create a Date field with N/A value as input", () => { const prediction = { @@ -26,8 +31,8 @@ describe("Test Date field", () => { confidence: 0.1, }; const field = new DateField({ prediction }); - expect(field.value).to.be.equal(undefined); - expect(field.dateObject).to.be.equal(undefined); - expect(field.polygon).to.be.empty; + assert.strictEqual(field.value, undefined); + assert.strictEqual(field.dateObject, undefined); + assert.strictEqual(field.polygon.length, 0); }); }); diff --git a/tests/v1/parsing/standard/field.spec.ts b/tests/v1/parsing/standard/field.spec.ts index 2bcbfd079..767597d5c 100644 --- a/tests/v1/parsing/standard/field.spec.ts +++ b/tests/v1/parsing/standard/field.spec.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import assert from "node:assert/strict"; import { Field } from "@/v1/parsing/standard/index.js"; describe("Test different inits of Field", () => { @@ -14,10 +14,9 @@ describe("Test different inits of Field", () => { ], }; const field = new Field({ prediction }); - // const field = new Field({ prediction }); - expect(field.value).to.equals("test"); - expect(field.confidence).to.equals(0.1); - expect(field.boundingBox.length).to.satisfy((length: number) => length > 0); + assert.strictEqual(field.value, "test"); + assert.strictEqual(field.confidence, 0.1); + assert.ok(field.boundingBox.length > 0); }); it("should not fail if no polygon given", () => { @@ -26,7 +25,7 @@ describe("Test different inits of Field", () => { confidence: 0.1, }; const field = new Field({ prediction }); - expect(field.polygon.length).to.equals(0); + assert.strictEqual(field.polygon.length, 0); }); it("should be equal to itself only", () => { @@ -40,8 +39,8 @@ describe("Test different inits of Field", () => { }; const field1 = new Field({ prediction: prediction1 }); const field2 = new Field({ prediction: prediction2 }); - expect(field1.compare(field1)).to.be.true; - expect(field1.compare(field2)).to.not.be.true; + assert.ok(field1.compare(field1)); + assert.ok(!field1.compare(field2)); }); it("should create with an N/A value", () => { @@ -49,8 +48,8 @@ describe("Test different inits of Field", () => { value: null, }; const field = new Field({ prediction }); - expect(field.value).to.be.undefined; - expect(field.confidence).to.be.equals(0.0); + assert.strictEqual(field.value, undefined); + assert.strictEqual(field.confidence, 0.0); }); it("should manipulate multiple fields", () => { @@ -58,13 +57,13 @@ describe("Test different inits of Field", () => { new Field({ prediction: { value: 1, confidence: 0.1 } }), new Field({ prediction: { value: 2, confidence: 0.8 } }), ]; - expect(Field.arrayConfidence(fields)).to.be.equals(0.8 * 0.1); - expect(Field.arraySum(fields)).to.be.equals(3); + assert.strictEqual(Field.arrayConfidence(fields), 0.8 * 0.1); + assert.strictEqual(Field.arraySum(fields), 3); const fields2 = [ new Field({ prediction: { value: undefined, confidence: undefined } }), new Field({ prediction: { value: 4, confidence: 0.8 } }), ]; - expect(Field.arrayConfidence(fields2)).to.be.equals(0.0); - expect(Field.arraySum(fields2)).to.be.equals(0.0); + assert.strictEqual(Field.arrayConfidence(fields2), 0.0); + assert.strictEqual(Field.arraySum(fields2), 0.0); }); }); diff --git a/tests/v1/parsing/standard/locale.spec.ts b/tests/v1/parsing/standard/locale.spec.ts index 01a0984bd..541c0cdb0 100644 --- a/tests/v1/parsing/standard/locale.spec.ts +++ b/tests/v1/parsing/standard/locale.spec.ts @@ -1,5 +1,5 @@ import { LocaleField } from "@/v1/parsing/standard/index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; describe("Test LocaleField field", () => { it("Should create a LocaleField", () => { @@ -11,11 +11,11 @@ describe("Test LocaleField field", () => { confidence: 0.1, }; const field = new LocaleField({ prediction }); - expect(field.value).to.be.equal("en-EN"); - expect(field.language).to.be.equal("en"); - expect(field.country).to.be.equal("uk"); - expect(field.currency).to.be.equal("GBP"); - expect(field.confidence).to.be.equal(0.1); + assert.strictEqual(field.value, "en-EN"); + assert.strictEqual(field.language, "en"); + assert.strictEqual(field.country, "uk"); + assert.strictEqual(field.currency, "GBP"); + assert.strictEqual(field.confidence, 0.1); }); it("Should create a LocaleField without the value property", () => { @@ -26,11 +26,11 @@ describe("Test LocaleField field", () => { confidence: 0.15, }; const field = new LocaleField({ prediction }); - expect(field.value).to.be.be.equal("fr"); - expect(field.language).to.be.equal("fr"); - expect(field.country).to.be.equal("fr"); - expect(field.currency).to.be.equal("EUR"); - expect(field.confidence).to.be.equal(0.15); + assert.strictEqual(field.value, "fr"); + assert.strictEqual(field.language, "fr"); + assert.strictEqual(field.country, "fr"); + assert.strictEqual(field.currency, "EUR"); + assert.strictEqual(field.confidence, 0.15); }); it("Should create a LocaleField with mainly empty fields", () => { @@ -39,8 +39,8 @@ describe("Test LocaleField field", () => { confidence: 0.1, }; const field = new LocaleField({ prediction }); - expect(field.language).to.be.undefined; - expect(field.country).to.be.undefined; - expect(field.currency).to.be.undefined; + assert.strictEqual(field.language, undefined); + assert.strictEqual(field.country, undefined); + assert.strictEqual(field.currency, undefined); }); }); diff --git a/tests/v1/parsing/standard/orientation.spec.ts b/tests/v1/parsing/standard/orientation.spec.ts index 5ec946d5f..fd481bc21 100644 --- a/tests/v1/parsing/standard/orientation.spec.ts +++ b/tests/v1/parsing/standard/orientation.spec.ts @@ -1,5 +1,5 @@ import { OrientationField } from "@/v1/parsing/common/index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; describe("Test Orientation field", () => { it("should create an Orientation field", () => { @@ -7,7 +7,7 @@ describe("Test Orientation field", () => { value: 90, }; const orientation = new OrientationField({ prediction, pageId: 0 }); - expect(orientation.value).to.be.equal(90); + assert.strictEqual(orientation.value, 90); }); it("should create an Orientation field with an NaN value", () => { @@ -15,7 +15,7 @@ describe("Test Orientation field", () => { value: "aze", }; const orientation = new OrientationField({ prediction, pageId: 0 }); - expect(orientation.value).to.be.equal(0); + assert.strictEqual(orientation.value, 0); }); it("should create an Orientation field with an incorrect value", () => { @@ -23,6 +23,6 @@ describe("Test Orientation field", () => { value: 255, }; const orientation = new OrientationField({ prediction, pageId: 0 }); - expect(orientation.value).to.be.equal(0); + assert.strictEqual(orientation.value, 0); }); }); diff --git a/tests/v1/parsing/standard/paymentDetails.spec.ts b/tests/v1/parsing/standard/paymentDetails.spec.ts index 4506a35a9..2b94c6955 100644 --- a/tests/v1/parsing/standard/paymentDetails.spec.ts +++ b/tests/v1/parsing/standard/paymentDetails.spec.ts @@ -1,8 +1,9 @@ import { PaymentDetailsField } from "@/v1/parsing/standard/index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; describe("Test PaymentDetailsField field", () => { it("should create a PaymentDetailsField field", () => { + /* eslint-disable @typescript-eslint/naming-convention,camelcase */ const prediction = { account_number: "account_number", iban: "iban", @@ -16,17 +17,17 @@ describe("Test PaymentDetailsField field", () => { [0.016, 0.831], ], }; + /* eslint-enable @typescript-eslint/naming-convention,camelcase */ const paymentDetail = new PaymentDetailsField({ prediction }); - expect(paymentDetail.accountNumber).to.be.equal(prediction.account_number); - expect(paymentDetail.iban).to.be.equal(prediction.iban); - expect(paymentDetail.routingNumber).to.be.equal(prediction.routing_number); - expect(paymentDetail.swift).to.be.equal(prediction.swift); - expect(paymentDetail.toString()).to.be.equal( - "account_number; iban; routing_number; swift; " - ); + assert.strictEqual(paymentDetail.accountNumber, prediction.account_number); + assert.strictEqual(paymentDetail.iban, prediction.iban); + assert.strictEqual(paymentDetail.routingNumber, prediction.routing_number); + assert.strictEqual(paymentDetail.swift, prediction.swift); + assert.strictEqual(paymentDetail.toString(), "account_number; iban; routing_number; swift; "); }); it("should create a PaymentDetailsField field with N/A inputs", () => { + /* eslint-disable @typescript-eslint/naming-convention,camelcase */ const prediction = { account_number: "N/A", iban: "N/A", @@ -40,15 +41,17 @@ describe("Test PaymentDetailsField field", () => { [0.016, 0.831], ], }; + /* eslint-enable @typescript-eslint/naming-convention,camelcase */ const paymentDetail = new PaymentDetailsField({ prediction }); - expect(paymentDetail.accountNumber).to.be.undefined; - expect(paymentDetail.iban).to.be.undefined; - expect(paymentDetail.routingNumber).to.be.undefined; - expect(paymentDetail.swift).to.be.undefined; - expect(paymentDetail.toString()).to.be.equal(""); + assert.strictEqual(paymentDetail.accountNumber, undefined); + assert.strictEqual(paymentDetail.iban, undefined); + assert.strictEqual(paymentDetail.routingNumber, undefined); + assert.strictEqual(paymentDetail.swift, undefined); + assert.strictEqual(paymentDetail.toString(), ""); }); it("should create a PaymentDetailsField field with empty inputs", () => { + /* eslint-disable @typescript-eslint/naming-convention,camelcase */ const prediction = { account_number: {}, iban: {}, @@ -62,11 +65,12 @@ describe("Test PaymentDetailsField field", () => { [0.016, 0.831], ], }; + /* eslint-enable @typescript-eslint/naming-convention,camelcase */ const paymentDetail = new PaymentDetailsField({ prediction }); - expect(paymentDetail.accountNumber).to.be.undefined; - expect(paymentDetail.iban).to.be.undefined; - expect(paymentDetail.routingNumber).to.be.undefined; - expect(paymentDetail.swift).to.be.undefined; - expect(paymentDetail.toString()).to.be.equal(""); + assert.strictEqual(paymentDetail.accountNumber, undefined); + assert.strictEqual(paymentDetail.iban, undefined); + assert.strictEqual(paymentDetail.routingNumber, undefined); + assert.strictEqual(paymentDetail.swift, undefined); + assert.strictEqual(paymentDetail.toString(), ""); }); }); diff --git a/tests/v1/parsing/standard/position.spec.ts b/tests/v1/parsing/standard/position.spec.ts index 64ef3e8f5..313ac168f 100644 --- a/tests/v1/parsing/standard/position.spec.ts +++ b/tests/v1/parsing/standard/position.spec.ts @@ -1,9 +1,10 @@ import { PositionField } from "@/v1/parsing/standard/index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; describe("Test Position field", () => { it("Should create a Position field", () => { const prediction = { + /* eslint-disable-next-line @typescript-eslint/naming-convention,camelcase */ bounding_box: [ [0, 0], [1, 0], @@ -50,8 +51,8 @@ describe("Test Position field", () => { ], }; const field = new PositionField({ prediction, pageId: 0 }); - expect(field.boundingBox.length).to.be.equal(4); - expect(field.polygon.length).to.be.equal(24); - expect(field.toString()).to.be.equal("Polygon with 24 points."); + assert.strictEqual(field.boundingBox.length, 4); + assert.strictEqual(field.polygon.length, 24); + assert.strictEqual(field.toString(), "Polygon with 24 points."); }); }); diff --git a/tests/v1/parsing/standard/tax.spec.ts b/tests/v1/parsing/standard/tax.spec.ts index d5c124bb3..fcbac2924 100644 --- a/tests/v1/parsing/standard/tax.spec.ts +++ b/tests/v1/parsing/standard/tax.spec.ts @@ -1,5 +1,5 @@ import { TaxField } from "@/v1/parsing/standard/index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; describe("Test Tax field", () => { it("should create a Tax field", () => { @@ -17,11 +17,11 @@ describe("Test Tax field", () => { ], }; const tax = new TaxField({ prediction, valueKey: "value" }); - expect(tax.value).to.be.equal(2); - expect(tax.confidence).to.be.equal(0.1); - expect(tax.rate).to.be.equal(0.2); - expect(tax.boundingBox.length).to.be.equal(4); - expect(tax.toString()).to.be.equal("Base: 5.00, Code: QST, Rate (%): 0.20, Amount: 2.00"); + assert.strictEqual(tax.value, 2); + assert.strictEqual(tax.confidence, 0.1); + assert.strictEqual(tax.rate, 0.2); + assert.strictEqual(tax.boundingBox.length, 4); + assert.strictEqual(tax.toString(), "Base: 5.00, Code: QST, Rate (%): 0.20, Amount: 2.00"); }); it("should create a Tax with rate not valid", () => { @@ -31,9 +31,9 @@ describe("Test Tax field", () => { confidence: 0.1, }; const tax = new TaxField({ prediction }); - expect(tax.rate).to.be.undefined; - expect(tax.polygon.length).to.be.equal(0); - expect(tax.toString()).to.be.equal("Base: , Code: , Rate (%): , Amount: 2.00"); + assert.strictEqual(tax.rate, undefined); + assert.strictEqual(tax.polygon.length, 0); + assert.strictEqual(tax.toString(), "Base: , Code: , Rate (%): , Amount: 2.00"); }); it("should create a Tax with amount not valid", () => { @@ -44,7 +44,7 @@ describe("Test Tax field", () => { confidence: 0.1, }; const tax = new TaxField({ prediction }); - expect(tax.value).to.be.undefined; - expect(tax.toString()).to.be.equal("Base: , Code: , Rate (%): , Amount:"); + assert.strictEqual(tax.value, undefined); + assert.strictEqual(tax.toString(), "Base: , Code: , Rate (%): , Amount:"); }); }); diff --git a/tests/v1/parsing/standard/text.spec.ts b/tests/v1/parsing/standard/text.spec.ts index 53986db6b..2bc3b2627 100644 --- a/tests/v1/parsing/standard/text.spec.ts +++ b/tests/v1/parsing/standard/text.spec.ts @@ -1,5 +1,6 @@ import { StringField } from "@/v1/parsing/standard/index.js"; -import { expect } from "chai"; +import { BoundingBox } from "@/geometry/index.js"; +import assert from "node:assert/strict"; describe("Test String field", () => { it("Should create a String field", () => { @@ -14,14 +15,18 @@ describe("Test String field", () => { ], }; const field = new StringField({ prediction }); - expect(field.value).to.be.equal(prediction.value); - expect(field.rawValue).to.be.undefined; - expect(field.boundingBox).to.have.deep.members(prediction["polygon"]); + assert.strictEqual(field.value, prediction.value); + assert.strictEqual(field.rawValue, undefined); + assert.deepStrictEqual( + // @ts-expect-error: prediction polygon is not typed + field.boundingBox, new BoundingBox(...prediction["polygon"]) + ); }); it("Should create a String field with a Raw Value", () => { const prediction = { value: "hellow world", + /* eslint-disable-next-line @typescript-eslint/naming-convention,camelcase */ raw_value: "HelLo WorlD", confidence: 0.1, polygon: [ @@ -32,8 +37,11 @@ describe("Test String field", () => { ], }; const field = new StringField({ prediction }); - expect(field.value).to.be.equal(prediction.value); - expect(field.rawValue).to.be.equal(prediction.raw_value); - expect(field.boundingBox).to.have.deep.members(prediction["polygon"]); + assert.strictEqual(field.value, prediction.value); + assert.strictEqual(field.rawValue, prediction.raw_value); + assert.deepStrictEqual( + // @ts-expect-error: prediction polygon is not typed + field.boundingBox, new BoundingBox(...prediction["polygon"]) + ); }); }); diff --git a/tests/v1/product/barcodeReader/barcodeReaderV1.spec.ts b/tests/v1/product/barcodeReader/barcodeReaderV1.spec.ts index 623524c8f..8ed13739d 100644 --- a/tests/v1/product/barcodeReader/barcodeReaderV1.spec.ts +++ b/tests/v1/product/barcodeReader/barcodeReaderV1.spec.ts @@ -1,10 +1,9 @@ import { promises as fs } from "fs"; import path from "path"; import { V1_PRODUCT_PATH } from "../../../index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as mindee from "@/index.js"; - const dataPath = { complete: path.join(V1_PRODUCT_PATH, "barcode_reader/response_v1/complete.json"), empty: path.join(V1_PRODUCT_PATH, "barcode_reader/response_v1/empty.json"), @@ -18,8 +17,8 @@ describe("MindeeV1 - BarcodeReaderV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.BarcodeReaderV1, response.document); const docPrediction = doc.inference.prediction; - expect(docPrediction.codes1D.length).to.be.equals(0); - expect(docPrediction.codes2D.length).to.be.equals(0); + assert.strictEqual(docPrediction.codes1D.length, 0); + assert.strictEqual(docPrediction.codes2D.length, 0); }); it("should load a complete document prediction", async () => { @@ -27,6 +26,6 @@ describe("MindeeV1 - BarcodeReaderV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.BarcodeReaderV1, response.document); const docString = await fs.readFile(path.join(dataPath.docString)); - expect(doc.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); }); diff --git a/tests/v1/product/cropper/cropperV1.spec.ts b/tests/v1/product/cropper/cropperV1.spec.ts index 1fc19cf48..eb39171c7 100644 --- a/tests/v1/product/cropper/cropperV1.spec.ts +++ b/tests/v1/product/cropper/cropperV1.spec.ts @@ -1,10 +1,9 @@ import { promises as fs } from "fs"; import path from "path"; import { V1_PRODUCT_PATH } from "../../../index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as mindee from "@/index.js"; - const dataPath = { complete: path.join(V1_PRODUCT_PATH, "cropper/response_v1/complete.json"), empty: path.join(V1_PRODUCT_PATH, "cropper/response_v1/empty.json"), @@ -18,7 +17,7 @@ describe("MindeeV1 - CropperV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.CropperV1, response.document); const pagePrediction = doc.inference.pages[0].prediction; - expect(pagePrediction.cropping.length).to.be.equals(0); + assert.strictEqual(pagePrediction.cropping.length, 0); }); it("should load a complete document prediction", async () => { @@ -26,14 +25,15 @@ describe("MindeeV1 - CropperV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.CropperV1, response.document); const docString = await fs.readFile(path.join(dataPath.docString)); - expect(doc.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); + it("should load a complete page 0 prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.complete)); const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.CropperV1, response.document); const page0 = doc.inference.pages[0]; const docString = await fs.readFile(path.join(dataPath.page0String)); - expect(page0.toString()).to.be.equals(docString.toString()); + assert.strictEqual(page0.toString(), docString.toString()); }); }); diff --git a/tests/v1/product/driverLicense/driverLicenseV1.spec.ts b/tests/v1/product/driverLicense/driverLicenseV1.spec.ts index e91827295..83053e0aa 100644 --- a/tests/v1/product/driverLicense/driverLicenseV1.spec.ts +++ b/tests/v1/product/driverLicense/driverLicenseV1.spec.ts @@ -1,10 +1,9 @@ import { promises as fs } from "fs"; import path from "path"; import { V1_PRODUCT_PATH } from "../../../index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as mindee from "@/index.js"; - const dataPath = { complete: path.join(V1_PRODUCT_PATH, "driver_license/response_v1/complete.json"), empty: path.join(V1_PRODUCT_PATH, "driver_license/response_v1/empty.json"), @@ -18,19 +17,19 @@ describe("MindeeV1 - DriverLicenseV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.DriverLicenseV1, response.document); const docPrediction = doc.inference.prediction; - expect(docPrediction.countryCode.value).to.be.undefined; - expect(docPrediction.state.value).to.be.undefined; - expect(docPrediction.id.value).to.be.undefined; - expect(docPrediction.category.value).to.be.undefined; - expect(docPrediction.lastName.value).to.be.undefined; - expect(docPrediction.firstName.value).to.be.undefined; - expect(docPrediction.dateOfBirth.value).to.be.undefined; - expect(docPrediction.placeOfBirth.value).to.be.undefined; - expect(docPrediction.expiryDate.value).to.be.undefined; - expect(docPrediction.issuedDate.value).to.be.undefined; - expect(docPrediction.issuingAuthority.value).to.be.undefined; - expect(docPrediction.mrz.value).to.be.undefined; - expect(docPrediction.ddNumber.value).to.be.undefined; + assert.strictEqual(docPrediction.countryCode.value, undefined); + assert.strictEqual(docPrediction.state.value, undefined); + assert.strictEqual(docPrediction.id.value, undefined); + assert.strictEqual(docPrediction.category.value, undefined); + assert.strictEqual(docPrediction.lastName.value, undefined); + assert.strictEqual(docPrediction.firstName.value, undefined); + assert.strictEqual(docPrediction.dateOfBirth.value, undefined); + assert.strictEqual(docPrediction.placeOfBirth.value, undefined); + assert.strictEqual(docPrediction.expiryDate.value, undefined); + assert.strictEqual(docPrediction.issuedDate.value, undefined); + assert.strictEqual(docPrediction.issuingAuthority.value, undefined); + assert.strictEqual(docPrediction.mrz.value, undefined); + assert.strictEqual(docPrediction.ddNumber.value, undefined); }); it("should load a complete document prediction", async () => { @@ -38,6 +37,6 @@ describe("MindeeV1 - DriverLicenseV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.DriverLicenseV1, response.document); const docString = await fs.readFile(path.join(dataPath.docString)); - expect(doc.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); }); diff --git a/tests/v1/product/financialDocument/financialDocumentV1.spec.ts b/tests/v1/product/financialDocument/financialDocumentV1.spec.ts index b819b4eb6..dbf4461c1 100644 --- a/tests/v1/product/financialDocument/financialDocumentV1.spec.ts +++ b/tests/v1/product/financialDocument/financialDocumentV1.spec.ts @@ -1,6 +1,6 @@ import { promises as fs } from "fs"; import * as path from "path"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as mindee from "@/index.js"; import { V1_PRODUCT_PATH } from "../../../index.js"; @@ -34,34 +34,34 @@ describe("Financial Document V1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.FinancialDocumentV1, response.document); const docPrediction = doc.inference.prediction; - expect(docPrediction.locale.value).to.be.undefined; - expect(docPrediction.totalAmount.value).to.be.undefined; - expect(docPrediction.totalNet.value).to.be.undefined; - expect(docPrediction.totalTax.value).to.be.undefined; - expect(docPrediction.date.value).to.be.undefined; - expect(docPrediction.invoiceNumber.value).to.be.undefined; - expect(docPrediction.billingAddress.value).to.be.undefined; - expect(docPrediction.dueDate.value).to.be.undefined; - expect(docPrediction.documentNumber.value).to.be.undefined; - expect(docPrediction.documentType.value).to.be.eq("EXPENSE RECEIPT"); - expect(docPrediction.documentTypeExtended.value).to.be.eq("EXPENSE RECEIPT"); - expect(docPrediction.supplierName.value).to.be.undefined; - expect(docPrediction.supplierAddress.value).to.be.undefined; - expect(docPrediction.customerId.value).to.be.undefined; - expect(docPrediction.customerName.value).to.be.undefined; - expect(docPrediction.customerAddress.value).to.be.undefined; - expect(docPrediction.customerCompanyRegistrations.length).to.be.eq(0); - expect(docPrediction.taxes.length).to.be.equal(0); - expect(docPrediction.supplierPaymentDetails.length).to.be.equal(0); - expect(docPrediction.supplierCompanyRegistrations.length).to.be.equal(0); - expect(docPrediction.tip.value).to.be.undefined; - expect(docPrediction.totalAmount.value).to.be.undefined; - expect(docPrediction.totalNet.value).to.be.undefined; - expect(docPrediction.totalTax.value).to.be.undefined; - expect(docPrediction.taxes.length).to.be.equal(0); - expect(docPrediction.date.value).to.be.undefined; - expect(docPrediction.time.value).to.be.undefined; - expect(docPrediction.supplierName.value).to.be.undefined; + assert.strictEqual(docPrediction.locale.value, undefined); + assert.strictEqual(docPrediction.totalAmount.value, undefined); + assert.strictEqual(docPrediction.totalNet.value, undefined); + assert.strictEqual(docPrediction.totalTax.value, undefined); + assert.strictEqual(docPrediction.date.value, undefined); + assert.strictEqual(docPrediction.invoiceNumber.value, undefined); + assert.strictEqual(docPrediction.billingAddress.value, undefined); + assert.strictEqual(docPrediction.dueDate.value, undefined); + assert.strictEqual(docPrediction.documentNumber.value, undefined); + assert.strictEqual(docPrediction.documentType.value, "EXPENSE RECEIPT"); + assert.strictEqual(docPrediction.documentTypeExtended.value, "EXPENSE RECEIPT"); + assert.strictEqual(docPrediction.supplierName.value, undefined); + assert.strictEqual(docPrediction.supplierAddress.value, undefined); + assert.strictEqual(docPrediction.customerId.value, undefined); + assert.strictEqual(docPrediction.customerName.value, undefined); + assert.strictEqual(docPrediction.customerAddress.value, undefined); + assert.strictEqual(docPrediction.customerCompanyRegistrations.length, 0); + assert.strictEqual(docPrediction.taxes.length, 0); + assert.strictEqual(docPrediction.supplierPaymentDetails.length, 0); + assert.strictEqual(docPrediction.supplierCompanyRegistrations.length, 0); + assert.strictEqual(docPrediction.tip.value, undefined); + assert.strictEqual(docPrediction.totalAmount.value, undefined); + assert.strictEqual(docPrediction.totalNet.value, undefined); + assert.strictEqual(docPrediction.totalTax.value, undefined); + assert.strictEqual(docPrediction.taxes.length, 0); + assert.strictEqual(docPrediction.date.value, undefined); + assert.strictEqual(docPrediction.time.value, undefined); + assert.strictEqual(docPrediction.supplierName.value, undefined); }); it("should initialize from an invoice object", async () => { @@ -69,7 +69,7 @@ describe("Financial Document V1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.FinancialDocumentV1, response.document); const docString = await fs.readFile(path.join(dataPath.invoiceDocString)); - expect(doc.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); it("should initialize from a receipt object", async () => { @@ -77,7 +77,7 @@ describe("Financial Document V1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.FinancialDocumentV1, response.document); const docString = await fs.readFile(path.join(dataPath.receiptDocString)); - expect(doc.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); it("should load a complete page 0 invoice prediction", async () => { @@ -86,8 +86,8 @@ describe("Financial Document V1 Object initialization", async () => { const doc = new mindee.v1.Document(mindee.v1.product.FinancialDocumentV1, response.document); const page0 = doc.inference.pages[0]; const docString = await fs.readFile(path.join(dataPath.page0InvoiceString)); - expect(page0.orientation?.value).to.be.equals(0); - expect(page0.toString()).to.be.equals(docString.toString()); + assert.strictEqual(page0.orientation?.value, 0); + assert.strictEqual(page0.toString(), docString.toString()); }); it("should load a complete page 0 receipt prediction", async () => { @@ -96,7 +96,7 @@ describe("Financial Document V1 Object initialization", async () => { const doc = new mindee.v1.Document(mindee.v1.product.FinancialDocumentV1, response.document); const page0 = doc.inference.pages[0]; const docString = await fs.readFile(path.join(dataPath.page0ReceiptString)); - expect(page0.orientation?.value).to.be.equals(0); - expect(page0.toString()).to.be.equals(docString.toString()); + assert.strictEqual(page0.orientation?.value, 0); + assert.strictEqual(page0.toString(), docString.toString()); }); }); diff --git a/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV1.spec.ts b/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV1.spec.ts index 23a1888d4..61bb3c40c 100644 --- a/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV1.spec.ts +++ b/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import path from "path"; import { V1_PRODUCT_PATH } from "../../../../index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as mindee from "@/index.js"; const dataPath = { @@ -17,9 +17,9 @@ describe("MindeeV1 - BankAccountDetailsV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.fr.BankAccountDetailsV1, response.document); const docPrediction = doc.inference.prediction; - expect(docPrediction.iban.value).to.be.undefined; - expect(docPrediction.accountHolderName.value).to.be.undefined; - expect(docPrediction.swift.value).to.be.undefined; + assert.strictEqual(docPrediction.iban.value, undefined); + assert.strictEqual(docPrediction.accountHolderName.value, undefined); + assert.strictEqual(docPrediction.swift.value, undefined); }); it("should load a complete document prediction", async () => { @@ -27,6 +27,6 @@ describe("MindeeV1 - BankAccountDetailsV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.fr.BankAccountDetailsV1, response.document); const docString = await fs.readFile(path.join(dataPath.docString)); - expect(doc.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); }); diff --git a/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV2.spec.ts b/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV2.spec.ts index 1f867bd77..f84b99f9b 100644 --- a/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV2.spec.ts +++ b/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV2.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import path from "path"; import { V1_PRODUCT_PATH } from "../../../../index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as mindee from "@/index.js"; @@ -18,13 +18,13 @@ describe("MindeeV1 - BankAccountDetailsV2 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.fr.BankAccountDetailsV2, response.document); const docPrediction = doc.inference.prediction; - expect(docPrediction.accountHoldersNames.value).to.be.undefined; - expect(docPrediction.bban.bbanBankCode).to.be.null; - expect(docPrediction.bban.bbanBranchCode).to.be.null; - expect(docPrediction.bban.bbanKey).to.be.null; - expect(docPrediction.bban.bbanNumber).to.be.null; - expect(docPrediction.iban.value).to.be.undefined; - expect(docPrediction.swiftCode.value).to.be.undefined; + assert.strictEqual(docPrediction.accountHoldersNames.value, undefined); + assert.ok(docPrediction.bban.bbanBankCode === null); + assert.ok(docPrediction.bban.bbanBranchCode === null); + assert.ok(docPrediction.bban.bbanKey === null); + assert.ok(docPrediction.bban.bbanNumber === null); + assert.strictEqual(docPrediction.iban.value, undefined); + assert.strictEqual(docPrediction.swiftCode.value, undefined); }); it("should load a complete document prediction", async () => { @@ -32,6 +32,6 @@ describe("MindeeV1 - BankAccountDetailsV2 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.fr.BankAccountDetailsV2, response.document); const docString = await fs.readFile(path.join(dataPath.docString)); - expect(doc.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); }); diff --git a/tests/v1/product/fr/carteGrise/carteGriseV1.spec.ts b/tests/v1/product/fr/carteGrise/carteGriseV1.spec.ts index 4e57f7268..e912fe429 100644 --- a/tests/v1/product/fr/carteGrise/carteGriseV1.spec.ts +++ b/tests/v1/product/fr/carteGrise/carteGriseV1.spec.ts @@ -1,8 +1,8 @@ import { promises as fs } from "fs"; import path from "path"; -import { V1_PRODUCT_PATH } from "../../../../index"; -import { expect } from "chai"; -import * as mindee from "../../../../../src"; +import { V1_PRODUCT_PATH } from "../../../../index.js"; +import assert from "node:assert/strict"; +import * as mindee from "@/index.js"; const dataPath = { @@ -18,47 +18,47 @@ describe("MindeeV1 - CarteGriseV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.fr.CarteGriseV1, response.document); const docPrediction = doc.inference.prediction; - expect(docPrediction.a.value).to.be.undefined; - expect(docPrediction.b.value).to.be.undefined; - expect(docPrediction.c1.value).to.be.undefined; - expect(docPrediction.c3.value).to.be.undefined; - expect(docPrediction.c41.value).to.be.undefined; - expect(docPrediction.c4A.value).to.be.undefined; - expect(docPrediction.d1.value).to.be.undefined; - expect(docPrediction.d3.value).to.be.undefined; - expect(docPrediction.e.value).to.be.undefined; - expect(docPrediction.f1.value).to.be.undefined; - expect(docPrediction.f2.value).to.be.undefined; - expect(docPrediction.f3.value).to.be.undefined; - expect(docPrediction.g.value).to.be.undefined; - expect(docPrediction.g1.value).to.be.undefined; - expect(docPrediction.i.value).to.be.undefined; - expect(docPrediction.j.value).to.be.undefined; - expect(docPrediction.j1.value).to.be.undefined; - expect(docPrediction.j2.value).to.be.undefined; - expect(docPrediction.j3.value).to.be.undefined; - expect(docPrediction.p1.value).to.be.undefined; - expect(docPrediction.p2.value).to.be.undefined; - expect(docPrediction.p3.value).to.be.undefined; - expect(docPrediction.p6.value).to.be.undefined; - expect(docPrediction.q.value).to.be.undefined; - expect(docPrediction.s1.value).to.be.undefined; - expect(docPrediction.s2.value).to.be.undefined; - expect(docPrediction.u1.value).to.be.undefined; - expect(docPrediction.u2.value).to.be.undefined; - expect(docPrediction.v7.value).to.be.undefined; - expect(docPrediction.x1.value).to.be.undefined; - expect(docPrediction.y1.value).to.be.undefined; - expect(docPrediction.y2.value).to.be.undefined; - expect(docPrediction.y3.value).to.be.undefined; - expect(docPrediction.y4.value).to.be.undefined; - expect(docPrediction.y5.value).to.be.undefined; - expect(docPrediction.y6.value).to.be.undefined; - expect(docPrediction.formulaNumber.value).to.be.undefined; - expect(docPrediction.ownerFirstName.value).to.be.undefined; - expect(docPrediction.ownerSurname.value).to.be.undefined; - expect(docPrediction.mrz1.value).to.be.undefined; - expect(docPrediction.mrz2.value).to.be.undefined; + assert.strictEqual(docPrediction.a.value, undefined); + assert.strictEqual(docPrediction.b.value, undefined); + assert.strictEqual(docPrediction.c1.value, undefined); + assert.strictEqual(docPrediction.c3.value, undefined); + assert.strictEqual(docPrediction.c41.value, undefined); + assert.strictEqual(docPrediction.c4A.value, undefined); + assert.strictEqual(docPrediction.d1.value, undefined); + assert.strictEqual(docPrediction.d3.value, undefined); + assert.strictEqual(docPrediction.e.value, undefined); + assert.strictEqual(docPrediction.f1.value, undefined); + assert.strictEqual(docPrediction.f2.value, undefined); + assert.strictEqual(docPrediction.f3.value, undefined); + assert.strictEqual(docPrediction.g.value, undefined); + assert.strictEqual(docPrediction.g1.value, undefined); + assert.strictEqual(docPrediction.i.value, undefined); + assert.strictEqual(docPrediction.j.value, undefined); + assert.strictEqual(docPrediction.j1.value, undefined); + assert.strictEqual(docPrediction.j2.value, undefined); + assert.strictEqual(docPrediction.j3.value, undefined); + assert.strictEqual(docPrediction.p1.value, undefined); + assert.strictEqual(docPrediction.p2.value, undefined); + assert.strictEqual(docPrediction.p3.value, undefined); + assert.strictEqual(docPrediction.p6.value, undefined); + assert.strictEqual(docPrediction.q.value, undefined); + assert.strictEqual(docPrediction.s1.value, undefined); + assert.strictEqual(docPrediction.s2.value, undefined); + assert.strictEqual(docPrediction.u1.value, undefined); + assert.strictEqual(docPrediction.u2.value, undefined); + assert.strictEqual(docPrediction.v7.value, undefined); + assert.strictEqual(docPrediction.x1.value, undefined); + assert.strictEqual(docPrediction.y1.value, undefined); + assert.strictEqual(docPrediction.y2.value, undefined); + assert.strictEqual(docPrediction.y3.value, undefined); + assert.strictEqual(docPrediction.y4.value, undefined); + assert.strictEqual(docPrediction.y5.value, undefined); + assert.strictEqual(docPrediction.y6.value, undefined); + assert.strictEqual(docPrediction.formulaNumber.value, undefined); + assert.strictEqual(docPrediction.ownerFirstName.value, undefined); + assert.strictEqual(docPrediction.ownerSurname.value, undefined); + assert.strictEqual(docPrediction.mrz1.value, undefined); + assert.strictEqual(docPrediction.mrz2.value, undefined); }); it("should load a complete document prediction", async () => { @@ -66,6 +66,6 @@ describe("MindeeV1 - CarteGriseV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.fr.CarteGriseV1, response.document); const docString = await fs.readFile(path.join(dataPath.docString)); - expect(doc.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); }); diff --git a/tests/v1/product/fr/idCard/idCardV2.spec.ts b/tests/v1/product/fr/idCard/idCardV2.spec.ts index bf72915e2..2ee4566af 100644 --- a/tests/v1/product/fr/idCard/idCardV2.spec.ts +++ b/tests/v1/product/fr/idCard/idCardV2.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import path from "path"; import { V1_PRODUCT_PATH } from "../../../../index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as mindee from "@/index.js"; @@ -18,21 +18,21 @@ describe("MindeeV1 - IdCardV2 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.fr.IdCardV2, response.document); const docPrediction = doc.inference.prediction; - expect(docPrediction.nationality.value).to.be.undefined; - expect(docPrediction.cardAccessNumber.value).to.be.undefined; - expect(docPrediction.documentNumber.value).to.be.undefined; - expect(docPrediction.givenNames.length).to.be.equals(0); - expect(docPrediction.surname.value).to.be.undefined; - expect(docPrediction.alternateName.value).to.be.undefined; - expect(docPrediction.birthDate.value).to.be.undefined; - expect(docPrediction.birthPlace.value).to.be.undefined; - expect(docPrediction.gender.value).to.be.undefined; - expect(docPrediction.expiryDate.value).to.be.undefined; - expect(docPrediction.mrz1.value).to.be.undefined; - expect(docPrediction.mrz2.value).to.be.undefined; - expect(docPrediction.mrz3.value).to.be.undefined; - expect(docPrediction.issueDate.value).to.be.undefined; - expect(docPrediction.authority.value).to.be.undefined; + assert.strictEqual(docPrediction.nationality.value, undefined); + assert.strictEqual(docPrediction.cardAccessNumber.value, undefined); + assert.strictEqual(docPrediction.documentNumber.value, undefined); + assert.strictEqual(docPrediction.givenNames.length, 0); + assert.strictEqual(docPrediction.surname.value, undefined); + assert.strictEqual(docPrediction.alternateName.value, undefined); + assert.strictEqual(docPrediction.birthDate.value, undefined); + assert.strictEqual(docPrediction.birthPlace.value, undefined); + assert.strictEqual(docPrediction.gender.value, undefined); + assert.strictEqual(docPrediction.expiryDate.value, undefined); + assert.strictEqual(docPrediction.mrz1.value, undefined); + assert.strictEqual(docPrediction.mrz2.value, undefined); + assert.strictEqual(docPrediction.mrz3.value, undefined); + assert.strictEqual(docPrediction.issueDate.value, undefined); + assert.strictEqual(docPrediction.authority.value, undefined); }); it("should load a complete document prediction", async () => { @@ -40,7 +40,7 @@ describe("MindeeV1 - IdCardV2 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.fr.IdCardV2, response.document); const docString = await fs.readFile(path.join(dataPath.docString)); - expect(doc.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); it("should load a complete page 0 prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.complete)); @@ -48,6 +48,6 @@ describe("MindeeV1 - IdCardV2 Object initialization", async () => { const doc = new mindee.v1.Document(mindee.v1.product.fr.IdCardV2, response.document); const page0 = doc.inference.pages[0]; const docString = await fs.readFile(path.join(dataPath.page0String)); - expect(page0.toString()).to.be.equals(docString.toString()); + assert.strictEqual(page0.toString(), docString.toString()); }); }); diff --git a/tests/v1/product/generated/generatedList.spec.ts b/tests/v1/product/generated/generatedList.spec.ts index 8f41be181..9ff722d65 100644 --- a/tests/v1/product/generated/generatedList.spec.ts +++ b/tests/v1/product/generated/generatedList.spec.ts @@ -1,11 +1,11 @@ -import { expect } from "chai"; +import assert from "node:assert/strict"; import { GeneratedListField } from "@/v1/parsing/generated/index.js"; describe("Generated List Field Objects", async () => { it("should properly format floats.", async () => { const dummyValue = [{ value: "123.40" }, { value: 567.8 }]; const genListField = new GeneratedListField({ prediction: dummyValue }); - expect((genListField.values[0] as any).value).to.equals("123.40"); - expect((genListField.values[1] as any).value).to.equals("567.8"); + assert.strictEqual((genListField.values[0] as any).value, "123.40"); + assert.strictEqual((genListField.values[1] as any).value, "567.8"); }); }); diff --git a/tests/v1/product/generated/generatedObject.spec.ts b/tests/v1/product/generated/generatedObject.spec.ts index 976b21786..d4c64065c 100644 --- a/tests/v1/product/generated/generatedObject.spec.ts +++ b/tests/v1/product/generated/generatedObject.spec.ts @@ -1,13 +1,13 @@ -import { expect } from "chai"; +import assert from "node:assert/strict"; import { GeneratedObjectField } from "@/v1/parsing/generated/index.js"; describe("Generated Object Field", async () => { it("should properly format booleans.", async () => { const dummyValue = { value: false, toto: true, hello: "false", other: "true" }; const genObjectField = new GeneratedObjectField({ prediction: dummyValue }); - expect(genObjectField.toto).to.be.true; - expect(genObjectField.hello).to.be.equals("false"); - expect(genObjectField.other).to.be.equals("true"); - expect(genObjectField.value).to.be.false; + assert.ok(genObjectField.toto); + assert.strictEqual(genObjectField.hello, "false"); + assert.strictEqual(genObjectField.other, "true"); + assert.strictEqual(genObjectField.value, false); }); }); diff --git a/tests/v1/product/generated/generatedV1.spec.ts b/tests/v1/product/generated/generatedV1.spec.ts index 1950ee421..7a0cbcc2c 100644 --- a/tests/v1/product/generated/generatedV1.spec.ts +++ b/tests/v1/product/generated/generatedV1.spec.ts @@ -1,6 +1,6 @@ import { promises as fs } from "fs"; import * as path from "path"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as mindee from "@/index.js"; import { Page } from "@/v1/index.js"; import { GeneratedV1 } from "@/v1/product/index.js"; @@ -31,118 +31,118 @@ describe("Generated Document Object initialization on an OTS invoice", async () const jsonDataNA = await fs.readFile(dataPathInvoice.empty); const response = JSON.parse(jsonDataNA.toString()); const doc = new mindee.v1.Document(GeneratedV1, response.document); - expect(doc.inference.prediction.fields.get("customer_address").value).to.be.undefined; - expect(doc.inference.prediction.fields.get("customer_company_registrations").values.length).to.equals(0); - expect(doc.inference.prediction.fields.get("customer_name").value).to.be.undefined; - expect(doc.inference.prediction.fields.get("date").value).to.be.undefined; - expect(doc.inference.prediction.fields.get("document_type").value).to.equals("INVOICE"); - expect(doc.inference.prediction.fields.get("due_date").value).be.undefined; - expect(doc.inference.prediction.fields.get("invoice_number").value).be.undefined; - expect(doc.inference.prediction.fields.get("line_items")).to.be.an.instanceOf(GeneratedListField); - expect(doc.inference.prediction.fields.get("line_items").values.length).to.equals(0); - expect(doc.inference.prediction.fields.get("locale")).to.be.an.instanceOf(GeneratedObjectField); - expect(doc.inference.prediction.fields.get("locale").currency).to.be.null; - expect(doc.inference.prediction.fields.get("locale").language).to.be.null; - expect(doc.inference.prediction.fields.get("reference_numbers").values.length).to.equals(0); - expect(doc.inference.prediction.fields.get("supplier_address").value).to.be.undefined; - expect(doc.inference.prediction.fields.get("supplier_company_registrations").values.length).to.equals(0); - expect(doc.inference.prediction.fields.get("supplier_name").value).to.be.undefined; - expect(doc.inference.prediction.fields.get("supplier_payment_details").values.length).to.equals(0); - expect(doc.inference.prediction.fields.get("taxes").values.length).to.equals(0); - expect(doc.inference.prediction.fields.get("total_amount").value).to.be.undefined; - expect(doc.inference.prediction.fields.get("total_net").value).to.be.undefined; + assert.strictEqual(doc.inference.prediction.fields.get("customer_address").value, undefined); + assert.strictEqual(doc.inference.prediction.fields.get("customer_company_registrations").values.length, 0); + assert.strictEqual(doc.inference.prediction.fields.get("customer_name").value, undefined); + assert.strictEqual(doc.inference.prediction.fields.get("date").value, undefined); + assert.strictEqual(doc.inference.prediction.fields.get("document_type").value, "INVOICE"); + assert.strictEqual(doc.inference.prediction.fields.get("due_date").value, undefined); + assert.strictEqual(doc.inference.prediction.fields.get("invoice_number").value, undefined); + assert.ok(doc.inference.prediction.fields.get("line_items") instanceof GeneratedListField); + assert.strictEqual(doc.inference.prediction.fields.get("line_items").values.length, 0); + assert.ok(doc.inference.prediction.fields.get("locale") instanceof GeneratedObjectField); + assert.ok(doc.inference.prediction.fields.get("locale").currency === null); + assert.ok(doc.inference.prediction.fields.get("locale").language === null); + assert.strictEqual(doc.inference.prediction.fields.get("reference_numbers").values.length, 0); + assert.strictEqual(doc.inference.prediction.fields.get("supplier_address").value, undefined); + assert.strictEqual(doc.inference.prediction.fields.get("supplier_company_registrations").values.length, 0); + assert.strictEqual(doc.inference.prediction.fields.get("supplier_name").value, undefined); + assert.strictEqual(doc.inference.prediction.fields.get("supplier_payment_details").values.length, 0); + assert.strictEqual(doc.inference.prediction.fields.get("taxes").values.length, 0); + assert.strictEqual(doc.inference.prediction.fields.get("total_amount").value, undefined); + assert.strictEqual(doc.inference.prediction.fields.get("total_net").value, undefined); const docString = await fs.readFile(path.join(dataPathInvoice.emptyDocString)); - expect(doc.toString()).to.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); it("should load a single page prediction", async () => { const jsonDataNA = await fs.readFile(path.resolve(dataPathInvoice.complete)); const response = JSON.parse(jsonDataNA.toString()); const page = new Page(GeneratedV1Page, response.document.inference.pages[0], 0); - expect(page.prediction.fields.get("customer_address").value).to.be.undefined; - expect(page.prediction.fields.get("customer_company_registrations").values.length).to.equals(0); - expect(page.prediction.fields.get("customer_name").value).to.be.undefined; - expect(page.prediction.fields.get("date").value).to.equals("2020-02-17"); - expect(page.prediction.fields.get("document_type").value).to.equals("INVOICE"); - expect(page.prediction.fields.get("due_date").value).to.equals("2020-02-17"); - expect(page.prediction.fields.get("invoice_number").value).to.equals("0042004801351"); - expect(page.prediction.fields.get("line_items")).to.be.an.instanceOf(GeneratedListField); - expect(page.prediction.fields.get("line_items").values[0]).to.be.an.instanceOf(GeneratedObjectField); - expect(page.prediction.fields.get("line_items").values[0].description).to.equals("S)BOIE 5X500 FEUILLES A4"); - expect(page.prediction.fields.get("line_items").values[0].product_code).to.be.null; - expect(page.prediction.fields.get("line_items").values[0].quantity).to.be.null; - expect(page.prediction.fields.get("line_items").values[0].tax_amount).to.be.null; - expect(page.prediction.fields.get("line_items").values[0].tax_rate).to.be.null; - expect(page.prediction.fields.get("line_items").values[0].total_amount).to.equals("2.63"); - expect(page.prediction.fields.get("line_items").values[0].unit_price).to.be.null; - expect(page.prediction.fields.get("locale")).to.be.an.instanceOf(GeneratedObjectField); - expect(page.prediction.fields.get("locale").currency).to.equals("EUR"); - expect(page.prediction.fields.get("locale").language).to.equals("fr"); - expect(page.prediction.fields.get("reference_numbers").values.length).to.equals(0); - expect(page.prediction.fields.get("supplier_address").value).to.be.undefined; - expect(page.prediction.fields.get("supplier_company_registrations").values.length).to.equals(0); - expect(page.prediction.fields.get("supplier_name").value).to.be.undefined; - expect(page.prediction.fields.get("supplier_payment_details").values[0].iban).to.equals( + assert.strictEqual(page.prediction.fields.get("customer_address").value, undefined); + assert.strictEqual(page.prediction.fields.get("customer_company_registrations").values.length, 0); + assert.strictEqual(page.prediction.fields.get("customer_name").value, undefined); + assert.strictEqual(page.prediction.fields.get("date").value, "2020-02-17"); + assert.strictEqual(page.prediction.fields.get("document_type").value, "INVOICE"); + assert.strictEqual(page.prediction.fields.get("due_date").value, "2020-02-17"); + assert.strictEqual(page.prediction.fields.get("invoice_number").value, "0042004801351"); + assert.ok(page.prediction.fields.get("line_items") instanceof GeneratedListField); + assert.ok(page.prediction.fields.get("line_items").values[0] instanceof GeneratedObjectField); + assert.strictEqual(page.prediction.fields.get("line_items").values[0].description, "S)BOIE 5X500 FEUILLES A4"); + assert.ok(page.prediction.fields.get("line_items").values[0].product_code === null); + assert.ok(page.prediction.fields.get("line_items").values[0].quantity === null); + assert.ok(page.prediction.fields.get("line_items").values[0].tax_amount === null); + assert.ok(page.prediction.fields.get("line_items").values[0].tax_rate === null); + assert.strictEqual(page.prediction.fields.get("line_items").values[0].total_amount, "2.63"); + assert.ok(page.prediction.fields.get("line_items").values[0].unit_price === null); + assert.ok(page.prediction.fields.get("locale") instanceof GeneratedObjectField); + assert.strictEqual(page.prediction.fields.get("locale").currency, "EUR"); + assert.strictEqual(page.prediction.fields.get("locale").language, "fr"); + assert.strictEqual(page.prediction.fields.get("reference_numbers").values.length, 0); + assert.strictEqual(page.prediction.fields.get("supplier_address").value, undefined); + assert.strictEqual(page.prediction.fields.get("supplier_company_registrations").values.length, 0); + assert.strictEqual(page.prediction.fields.get("supplier_name").value, undefined); + assert.strictEqual(page.prediction.fields.get("supplier_payment_details").values[0].iban, "FR7640254025476501124705368" ); - expect(page.prediction.fields.get("taxes").values[0].polygon.polygon).to.have.deep.members( + assert.deepStrictEqual(page.prediction.fields.get("taxes").values[0].polygon.polygon, [[0.292, 0.749], [0.543, 0.749], [0.543, 0.763], [0.292, 0.763]] ); - expect(page.prediction.fields.get("taxes").values[0].rate).to.equals("20.0"); - expect(page.prediction.fields.get("taxes").values[0].value).to.equals("97.98"); - expect(page.prediction.fields.get("total_amount").value).to.equals("587.95"); - expect(page.prediction.fields.get("total_net").value).to.equals("489.97"); + assert.strictEqual(page.prediction.fields.get("taxes").values[0].rate, "20.0"); + assert.strictEqual(page.prediction.fields.get("taxes").values[0].value, "97.98"); + assert.strictEqual(page.prediction.fields.get("total_amount").value, "587.95"); + assert.strictEqual(page.prediction.fields.get("total_net").value, "489.97"); const page0String = await fs.readFile(path.join(dataPathInvoice.page0String)); - expect(page.toString()).to.equals(page0String.toString()); + assert.strictEqual(page.toString(), page0String.toString()); }); it("should load a complete document prediction", async () => { const jsonDataNA = await fs.readFile(path.resolve(dataPathInvoice.complete)); const response = JSON.parse(jsonDataNA.toString()); const doc = new mindee.v1.Document(GeneratedV1, response.document); - expect(doc.inference.prediction.fields.get("customer_address").value).to.equals( + assert.strictEqual(doc.inference.prediction.fields.get("customer_address").value, "1954 Bloon Street West Toronto, ON, M6P 3K9 Canada" ); - expect(doc.inference.prediction.fields.get("customer_company_registrations").values.length).to.equals(0); - expect(doc.inference.prediction.fields.get("customer_name").value).to.equals("JIRO DOI"); - expect(doc.inference.prediction.fields.get("date").value).to.equals("2020-02-17"); - expect(doc.inference.prediction.fields.get("document_type").value).to.equals("INVOICE"); - expect(doc.inference.prediction.fields.get("due_date").value).to.equals("2020-02-17"); - expect(doc.inference.prediction.fields.get("invoice_number").value).to.equals("0042004801351"); - expect(doc.inference.prediction.fields.get("line_items")).to.be.an.instanceOf(GeneratedListField); - expect(doc.inference.prediction.fields.get("line_items").values[0]).to.be.an.instanceOf(GeneratedObjectField); - expect(doc.inference.prediction.fields.get("line_items").values[0].description).to.equals( + assert.strictEqual(doc.inference.prediction.fields.get("customer_company_registrations").values.length, 0); + assert.strictEqual(doc.inference.prediction.fields.get("customer_name").value, "JIRO DOI"); + assert.strictEqual(doc.inference.prediction.fields.get("date").value, "2020-02-17"); + assert.strictEqual(doc.inference.prediction.fields.get("document_type").value, "INVOICE"); + assert.strictEqual(doc.inference.prediction.fields.get("due_date").value, "2020-02-17"); + assert.strictEqual(doc.inference.prediction.fields.get("invoice_number").value, "0042004801351"); + assert.ok(doc.inference.prediction.fields.get("line_items") instanceof GeneratedListField); + assert.ok(doc.inference.prediction.fields.get("line_items").values[0] instanceof GeneratedObjectField); + assert.strictEqual(doc.inference.prediction.fields.get("line_items").values[0].description, "S)BOIE 5X500 FEUILLES A4" ); - expect(doc.inference.prediction.fields.get("line_items").values[0].product_code).to.be.null; - expect(doc.inference.prediction.fields.get("line_items").values[0].quantity).to.be.null; - expect(doc.inference.prediction.fields.get("line_items").values[0].tax_amount).to.be.null; - expect(doc.inference.prediction.fields.get("line_items").values[0].tax_rate).to.be.null; - expect(doc.inference.prediction.fields.get("line_items").values[0].total_amount).to.equals("2.63"); - expect(doc.inference.prediction.fields.get("line_items").values[0].unit_price).to.be.null; - expect(doc.inference.prediction.fields.get("line_items").values[6].unit_price).to.equals("65.0"); - expect(doc.inference.prediction.fields.get("line_items").values[6].quantity).to.equals("1.0"); - expect(doc.inference.prediction.fields.get("locale")).to.be.an.instanceOf(GeneratedObjectField); - expect(doc.inference.prediction.fields.get("locale").currency).to.equals("EUR"); - expect(doc.inference.prediction.fields.get("locale").language).to.equals("fr"); - expect(doc.inference.prediction.fields.get("reference_numbers").values[0].value).to.equals("AD29094"); - expect(doc.inference.prediction.fields.get("supplier_address").value).to.equals( + assert.ok(doc.inference.prediction.fields.get("line_items").values[0].product_code === null); + assert.ok(doc.inference.prediction.fields.get("line_items").values[0].quantity === null); + assert.ok(doc.inference.prediction.fields.get("line_items").values[0].tax_amount === null); + assert.ok(doc.inference.prediction.fields.get("line_items").values[0].tax_rate === null); + assert.strictEqual(doc.inference.prediction.fields.get("line_items").values[0].total_amount, "2.63"); + assert.ok(doc.inference.prediction.fields.get("line_items").values[0].unit_price === null); + assert.strictEqual(doc.inference.prediction.fields.get("line_items").values[6].unit_price, "65.0"); + assert.strictEqual(doc.inference.prediction.fields.get("line_items").values[6].quantity, "1.0"); + assert.ok(doc.inference.prediction.fields.get("locale") instanceof GeneratedObjectField); + assert.strictEqual(doc.inference.prediction.fields.get("locale").currency, "EUR"); + assert.strictEqual(doc.inference.prediction.fields.get("locale").language, "fr"); + assert.strictEqual(doc.inference.prediction.fields.get("reference_numbers").values[0].value, "AD29094"); + assert.strictEqual(doc.inference.prediction.fields.get("supplier_address").value, "156 University Ave, Toronto ON, Canada M5H 2H7" ); - expect(doc.inference.prediction.fields.get("supplier_company_registrations").values.length).to.equals(0); - expect(doc.inference.prediction.fields.get("supplier_name").value).to.equals("TURNPIKE DESIGNS CO."); - expect(doc.inference.prediction.fields.get("supplier_payment_details").values[0].iban).to.equals( + assert.strictEqual(doc.inference.prediction.fields.get("supplier_company_registrations").values.length, 0); + assert.strictEqual(doc.inference.prediction.fields.get("supplier_name").value, "TURNPIKE DESIGNS CO."); + assert.strictEqual(doc.inference.prediction.fields.get("supplier_payment_details").values[0].iban, "FR7640254025476501124705368" ); - expect(doc.inference.prediction.fields.get("taxes").values[0].polygon.polygon).to.have.deep.members( + assert.deepStrictEqual(doc.inference.prediction.fields.get("taxes").values[0].polygon.polygon, [[0.292, 0.749], [0.543, 0.749], [0.543, 0.763], [0.292, 0.763]] ); - expect(doc.inference.prediction.fields.get("taxes").values[0].rate).to.equals("20.0"); - expect(doc.inference.prediction.fields.get("taxes").values[0].value).to.equals("97.98"); - expect(doc.inference.prediction.fields.get("total_amount").value).to.equals("587.95"); - expect(doc.inference.prediction.fields.get("total_net").value).to.equals("489.97"); + assert.strictEqual(doc.inference.prediction.fields.get("taxes").values[0].rate, "20.0"); + assert.strictEqual(doc.inference.prediction.fields.get("taxes").values[0].value, "97.98"); + assert.strictEqual(doc.inference.prediction.fields.get("total_amount").value, "587.95"); + assert.strictEqual(doc.inference.prediction.fields.get("total_net").value, "489.97"); const docString = await fs.readFile(path.join(dataPathInvoice.docString)); - expect(doc.toString()).to.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); }); @@ -154,76 +154,76 @@ describe("Generated Document Object initialization on an International ID", asyn const response = JSON.parse(jsonDataNA.toString()); const doc = new mindee.v1.Document(GeneratedV1, response.document); const docString = await fs.readFile(path.join(dataPathInternationalId.emptyDocString)); - expect(doc.inference.prediction.fields.get("document_type")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("document_type").value).to.be.undefined; - expect(doc.inference.prediction.fields.get("document_number")).be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("document_number").value).be.undefined; - expect(doc.inference.prediction.fields.get("country_of_issue")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("country_of_issue").value).to.be.undefined; - expect(doc.inference.prediction.fields.get("surnames")).to.be.an.instanceOf(GeneratedListField); - expect(doc.inference.prediction.fields.get("surnames").values.length).to.equals(0); - expect(doc.inference.prediction.fields.get("given_names")).to.be.an.instanceOf(GeneratedListField); - expect(doc.inference.prediction.fields.get("given_names").values.length).to.equals(0); - expect(doc.inference.prediction.fields.get("sex")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("sex").value).to.be.undefined; - expect(doc.inference.prediction.fields.get("birth_date")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("birth_date").value).to.be.undefined; - expect(doc.inference.prediction.fields.get("birth_place")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("birth_place").value).to.be.undefined; - expect(doc.inference.prediction.fields.get("nationality")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("nationality").value).to.be.undefined; - expect(doc.inference.prediction.fields.get("issue_date")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("issue_date").value).to.be.undefined; - expect(doc.inference.prediction.fields.get("expiry_date")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("expiry_date").value).to.be.undefined; - expect(doc.inference.prediction.fields.get("address")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("address").value).to.be.undefined; - expect(doc.inference.prediction.fields.get("mrz1")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("mrz1").value).to.be.undefined; - expect(doc.inference.prediction.fields.get("mrz2")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("mrz2").value).to.be.undefined; - expect(doc.inference.prediction.fields.get("mrz3")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("mrz3").value).to.be.undefined; + assert.ok(doc.inference.prediction.fields.get("document_type") instanceof StringField); + assert.strictEqual(doc.inference.prediction.fields.get("document_type").value, undefined); + assert.ok(doc.inference.prediction.fields.get("document_number") instanceof StringField); + assert.strictEqual(doc.inference.prediction.fields.get("document_number").value, undefined); + assert.ok(doc.inference.prediction.fields.get("country_of_issue") instanceof StringField); + assert.strictEqual(doc.inference.prediction.fields.get("country_of_issue").value, undefined); + assert.ok(doc.inference.prediction.fields.get("surnames") instanceof GeneratedListField); + assert.strictEqual(doc.inference.prediction.fields.get("surnames").values.length, 0); + assert.ok(doc.inference.prediction.fields.get("given_names") instanceof GeneratedListField); + assert.strictEqual(doc.inference.prediction.fields.get("given_names").values.length, 0); + assert.ok(doc.inference.prediction.fields.get("sex") instanceof StringField); + assert.strictEqual(doc.inference.prediction.fields.get("sex").value, undefined); + assert.ok(doc.inference.prediction.fields.get("birth_date") instanceof StringField); + assert.strictEqual(doc.inference.prediction.fields.get("birth_date").value, undefined); + assert.ok(doc.inference.prediction.fields.get("birth_place") instanceof StringField); + assert.strictEqual(doc.inference.prediction.fields.get("birth_place").value, undefined); + assert.ok(doc.inference.prediction.fields.get("nationality") instanceof StringField); + assert.strictEqual(doc.inference.prediction.fields.get("nationality").value, undefined); + assert.ok(doc.inference.prediction.fields.get("issue_date") instanceof StringField); + assert.strictEqual(doc.inference.prediction.fields.get("issue_date").value, undefined); + assert.ok(doc.inference.prediction.fields.get("expiry_date") instanceof StringField); + assert.strictEqual(doc.inference.prediction.fields.get("expiry_date").value, undefined); + assert.ok(doc.inference.prediction.fields.get("address") instanceof StringField); + assert.strictEqual(doc.inference.prediction.fields.get("address").value, undefined); + assert.ok(doc.inference.prediction.fields.get("mrz1") instanceof StringField); + assert.strictEqual(doc.inference.prediction.fields.get("mrz1").value, undefined); + assert.ok(doc.inference.prediction.fields.get("mrz2") instanceof StringField); + assert.strictEqual(doc.inference.prediction.fields.get("mrz2").value, undefined); + assert.ok(doc.inference.prediction.fields.get("mrz3") instanceof StringField); + assert.strictEqual(doc.inference.prediction.fields.get("mrz3").value, undefined); - expect(doc.toString()).to.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); it("should load a complete document prediction", async () => { const jsonDataNA = await fs.readFile(path.resolve(dataPathInternationalId.complete)); const response = JSON.parse(jsonDataNA.toString()); const doc = new mindee.v1.Document(GeneratedV1, response.document); - expect(doc.inference.prediction.fields.get("document_type")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("document_type").value).to.equals("NATIONAL_ID_CARD"); - expect(doc.inference.prediction.fields.get("document_number")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("document_number").value).to.equals("99999999R"); - expect(doc.inference.prediction.fields.get("country_of_issue")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("country_of_issue").value).to.equals("ESP"); - expect(doc.inference.prediction.fields.get("surnames")).to.be.an.instanceOf(GeneratedListField); - expect(doc.inference.prediction.fields.get("surnames").values[0].value).to.equals("ESPAÑOLA"); - expect(doc.inference.prediction.fields.get("surnames").values[1].value).to.equals("ESPAÑOLA"); - expect(doc.inference.prediction.fields.get("given_names")).to.be.an.instanceOf(GeneratedListField); - expect(doc.inference.prediction.fields.get("given_names").values[0].value).to.equals("CARMEN"); - expect(doc.inference.prediction.fields.get("sex")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("sex").value).to.equals("F"); - expect(doc.inference.prediction.fields.get("birth_date")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("birth_date").value).to.equals("1980-01-01"); - expect(doc.inference.prediction.fields.get("birth_place")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("birth_place").value).to.equals("MADRID"); - expect(doc.inference.prediction.fields.get("nationality")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("nationality").value).to.equals("ESP"); - expect(doc.inference.prediction.fields.get("issue_date")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("issue_date").value).to.equals("2015-01-01"); - expect(doc.inference.prediction.fields.get("expiry_date")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("expiry_date").value).to.equals("2025-01-01"); - expect(doc.inference.prediction.fields.get("address")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("address").value).to.equals("AVDA DE MADRID S-N MADRID MADRID"); - expect(doc.inference.prediction.fields.get("mrz1")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("mrz1").value).to.equals("IDESPBAA000589599999999R<<<<<<"); - expect(doc.inference.prediction.fields.get("mrz2")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("mrz2").value).to.equals("8001014F2501017ESP<<<<<<<<<<<7"); - expect(doc.inference.prediction.fields.get("mrz3")).to.be.an.instanceOf(StringField); - expect(doc.inference.prediction.fields.get("mrz3").value).to.equals("ESPANOLA { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.InternationalIdV2, response.document); const docPrediction = doc.inference.prediction; - expect(docPrediction.documentNumber.value).to.be.undefined; - expect(docPrediction.surnames.length).to.be.equals(0); - expect(docPrediction.givenNames.length).to.be.equals(0); - expect(docPrediction.sex.value).to.be.undefined; - expect(docPrediction.birthDate.value).to.be.undefined; - expect(docPrediction.birthPlace.value).to.be.undefined; - expect(docPrediction.nationality.value).to.be.undefined; - expect(docPrediction.personalNumber.value).to.be.undefined; - expect(docPrediction.countryOfIssue.value).to.be.undefined; - expect(docPrediction.stateOfIssue.value).to.be.undefined; - expect(docPrediction.issueDate.value).to.be.undefined; - expect(docPrediction.expiryDate.value).to.be.undefined; - expect(docPrediction.address.value).to.be.undefined; - expect(docPrediction.mrzLine1.value).to.be.undefined; - expect(docPrediction.mrzLine2.value).to.be.undefined; - expect(docPrediction.mrzLine3.value).to.be.undefined; + assert.strictEqual(docPrediction.documentNumber.value, undefined); + assert.strictEqual(docPrediction.surnames.length, 0); + assert.strictEqual(docPrediction.givenNames.length, 0); + assert.strictEqual(docPrediction.sex.value, undefined); + assert.strictEqual(docPrediction.birthDate.value, undefined); + assert.strictEqual(docPrediction.birthPlace.value, undefined); + assert.strictEqual(docPrediction.nationality.value, undefined); + assert.strictEqual(docPrediction.personalNumber.value, undefined); + assert.strictEqual(docPrediction.countryOfIssue.value, undefined); + assert.strictEqual(docPrediction.stateOfIssue.value, undefined); + assert.strictEqual(docPrediction.issueDate.value, undefined); + assert.strictEqual(docPrediction.expiryDate.value, undefined); + assert.strictEqual(docPrediction.address.value, undefined); + assert.strictEqual(docPrediction.mrzLine1.value, undefined); + assert.strictEqual(docPrediction.mrzLine2.value, undefined); + assert.strictEqual(docPrediction.mrzLine3.value, undefined); }); it("should load a complete document prediction", async () => { @@ -41,6 +41,6 @@ describe("MindeeV1 - InternationalIdV2 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.InternationalIdV2, response.document); const docString = await fs.readFile(path.join(dataPath.docString)); - expect(doc.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); }); diff --git a/tests/v1/product/invoice/invoiceV4.spec.ts b/tests/v1/product/invoice/invoiceV4.spec.ts index cd7bb5543..e6acd6e53 100644 --- a/tests/v1/product/invoice/invoiceV4.spec.ts +++ b/tests/v1/product/invoice/invoiceV4.spec.ts @@ -1,10 +1,9 @@ import { promises as fs } from "fs"; import path from "path"; import { V1_PRODUCT_PATH } from "../../../index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as mindee from "@/index.js"; - const dataPath = { complete: path.join(V1_PRODUCT_PATH, "invoices/response_v4/complete.json"), empty: path.join(V1_PRODUCT_PATH, "invoices/response_v4/empty.json"), @@ -18,31 +17,31 @@ describe("MindeeV1 - InvoiceV4 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.InvoiceV4, response.document); const docPrediction = doc.inference.prediction; - expect(docPrediction.locale.value).to.be.undefined; - expect(docPrediction.invoiceNumber.value).to.be.undefined; - expect(docPrediction.poNumber.value).to.be.undefined; - expect(docPrediction.referenceNumbers.length).to.be.equals(0); - expect(docPrediction.date.value).to.be.undefined; - expect(docPrediction.dueDate.value).to.be.undefined; - expect(docPrediction.paymentDate.value).to.be.undefined; - expect(docPrediction.totalNet.value).to.be.undefined; - expect(docPrediction.totalAmount.value).to.be.undefined; - expect(docPrediction.totalTax.value).to.be.undefined; - expect(docPrediction.taxes.length).to.be.equals(0); - expect(docPrediction.supplierPaymentDetails.length).to.be.equals(0); - expect(docPrediction.supplierName.value).to.be.undefined; - expect(docPrediction.supplierCompanyRegistrations.length).to.be.equals(0); - expect(docPrediction.supplierAddress.value).to.be.undefined; - expect(docPrediction.supplierPhoneNumber.value).to.be.undefined; - expect(docPrediction.supplierWebsite.value).to.be.undefined; - expect(docPrediction.supplierEmail.value).to.be.undefined; - expect(docPrediction.customerName.value).to.be.undefined; - expect(docPrediction.customerCompanyRegistrations.length).to.be.equals(0); - expect(docPrediction.customerAddress.value).to.be.undefined; - expect(docPrediction.customerId.value).to.be.undefined; - expect(docPrediction.shippingAddress.value).to.be.undefined; - expect(docPrediction.billingAddress.value).to.be.undefined; - expect(docPrediction.lineItems.length).to.be.equals(0); + assert.strictEqual(docPrediction.locale.value, undefined); + assert.strictEqual(docPrediction.invoiceNumber.value, undefined); + assert.strictEqual(docPrediction.poNumber.value, undefined); + assert.strictEqual(docPrediction.referenceNumbers.length, 0); + assert.strictEqual(docPrediction.date.value, undefined); + assert.strictEqual(docPrediction.dueDate.value, undefined); + assert.strictEqual(docPrediction.paymentDate.value, undefined); + assert.strictEqual(docPrediction.totalNet.value, undefined); + assert.strictEqual(docPrediction.totalAmount.value, undefined); + assert.strictEqual(docPrediction.totalTax.value, undefined); + assert.strictEqual(docPrediction.taxes.length, 0); + assert.strictEqual(docPrediction.supplierPaymentDetails.length, 0); + assert.strictEqual(docPrediction.supplierName.value, undefined); + assert.strictEqual(docPrediction.supplierCompanyRegistrations.length, 0); + assert.strictEqual(docPrediction.supplierAddress.value, undefined); + assert.strictEqual(docPrediction.supplierPhoneNumber.value, undefined); + assert.strictEqual(docPrediction.supplierWebsite.value, undefined); + assert.strictEqual(docPrediction.supplierEmail.value, undefined); + assert.strictEqual(docPrediction.customerName.value, undefined); + assert.strictEqual(docPrediction.customerCompanyRegistrations.length, 0); + assert.strictEqual(docPrediction.customerAddress.value, undefined); + assert.strictEqual(docPrediction.customerId.value, undefined); + assert.strictEqual(docPrediction.shippingAddress.value, undefined); + assert.strictEqual(docPrediction.billingAddress.value, undefined); + assert.strictEqual(docPrediction.lineItems.length, 0); }); it("should load a complete document prediction", async () => { @@ -50,6 +49,6 @@ describe("MindeeV1 - InvoiceV4 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.InvoiceV4, response.document); const docString = await fs.readFile(path.join(dataPath.docString)); - expect(doc.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); }); diff --git a/tests/v1/product/invoiceSplitter/invoiceSplitter.integration.ts b/tests/v1/product/invoiceSplitter/invoiceSplitter.integration.ts index 7a1023647..5e546cbdc 100644 --- a/tests/v1/product/invoiceSplitter/invoiceSplitter.integration.ts +++ b/tests/v1/product/invoiceSplitter/invoiceSplitter.integration.ts @@ -1,6 +1,6 @@ import * as mindee from "@/index.js"; import { InvoiceSplitterV1 } from "@/v1/product/index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import { levenshteinRatio } from "../../../testingUtilities.js"; import { promises as fs } from "fs"; import path from "path"; @@ -22,14 +22,14 @@ describe("MindeeV1 - InvoiceSplitterV1 Integration Tests #includeOptionalDeps", mindee.v1.product.InvoiceSplitterV1, sample ); const invoiceSplitterInference = response.document?.inference; - expect(invoiceSplitterInference).to.be.an.instanceof(InvoiceSplitterV1); + assert.ok(invoiceSplitterInference instanceof InvoiceSplitterV1); const invoices = await mindee.v1.extraction.extractInvoices( sample, invoiceSplitterInference as InvoiceSplitterV1 ); - expect(invoices.length).to.be.eq(2); - expect(invoices[0].asSource().filename).to.eq("invoice_p_0-0.pdf"); - expect(invoices[1].asSource().filename).to.eq("invoice_p_1-1.pdf"); + assert.strictEqual(invoices.length, 2); + assert.strictEqual(invoices[0].asSource().filename, "invoice_p_0-0.pdf"); + assert.strictEqual(invoices[1].asSource().filename, "invoice_p_1-1.pdf"); const invoiceResult = await client.parse( mindee.v1.product.InvoiceV4, invoices[0].asSource() @@ -38,11 +38,11 @@ describe("MindeeV1 - InvoiceSplitterV1 Integration Tests #includeOptionalDeps", path.join(V1_PRODUCT_PATH, "invoices/response_v4/summary_full_invoice_p1.rst") ); - expect( + assert.ok( levenshteinRatio( invoiceResult.document.toString(), testStringRstInvoice.toString() - ) - ).to.be.greaterThanOrEqual(0.90); + ) >= 0.90 + ); }).timeout(60000); }); diff --git a/tests/v1/product/invoiceSplitter/invoiceSplitterV1.spec.ts b/tests/v1/product/invoiceSplitter/invoiceSplitterV1.spec.ts index 8075affee..760df3dc7 100644 --- a/tests/v1/product/invoiceSplitter/invoiceSplitterV1.spec.ts +++ b/tests/v1/product/invoiceSplitter/invoiceSplitterV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import path from "path"; import { V1_PRODUCT_PATH } from "../../../index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as mindee from "@/index.js"; @@ -18,7 +18,7 @@ describe("MindeeV1 - InvoiceSplitterV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.InvoiceSplitterV1, response.document); const docPrediction = doc.inference.prediction; - expect(docPrediction.invoicePageGroups.length).to.be.equals(0); + assert.strictEqual(docPrediction.invoicePageGroups.length, 0); }); it("should load a complete document prediction", async () => { @@ -26,6 +26,6 @@ describe("MindeeV1 - InvoiceSplitterV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.InvoiceSplitterV1, response.document); const docString = await fs.readFile(path.join(dataPath.docString)); - expect(doc.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); }); diff --git a/tests/v1/product/multiReceiptsDetector/multiReceiptsDetectorV1.spec.ts b/tests/v1/product/multiReceiptsDetector/multiReceiptsDetectorV1.spec.ts index cae5ef4fc..ddb416a12 100644 --- a/tests/v1/product/multiReceiptsDetector/multiReceiptsDetectorV1.spec.ts +++ b/tests/v1/product/multiReceiptsDetector/multiReceiptsDetectorV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import path from "path"; import { V1_PRODUCT_PATH } from "../../../index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as mindee from "@/index.js"; @@ -18,7 +18,7 @@ describe("MindeeV1 - MultiReceiptsDetectorV1 Object initialization", async () => const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.MultiReceiptsDetectorV1, response.document); const docPrediction = doc.inference.prediction; - expect(docPrediction.receipts.length).to.be.equals(0); + assert.strictEqual(docPrediction.receipts.length, 0); }); it("should load a complete document prediction", async () => { @@ -26,6 +26,6 @@ describe("MindeeV1 - MultiReceiptsDetectorV1 Object initialization", async () => const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.MultiReceiptsDetectorV1, response.document); const docString = await fs.readFile(path.join(dataPath.docString)); - expect(doc.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); }); diff --git a/tests/v1/product/passport/passportV1.spec.ts b/tests/v1/product/passport/passportV1.spec.ts index 20b54b5d7..336717160 100644 --- a/tests/v1/product/passport/passportV1.spec.ts +++ b/tests/v1/product/passport/passportV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import path from "path"; import { V1_PRODUCT_PATH } from "../../../index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as mindee from "@/index.js"; @@ -18,17 +18,17 @@ describe("MindeeV1 - PassportV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.PassportV1, response.document); const docPrediction = doc.inference.prediction; - expect(docPrediction.country.value).to.be.undefined; - expect(docPrediction.idNumber.value).to.be.undefined; - expect(docPrediction.givenNames.length).to.be.equals(0); - expect(docPrediction.surname.value).to.be.undefined; - expect(docPrediction.birthDate.value).to.be.undefined; - expect(docPrediction.birthPlace.value).to.be.undefined; - expect(docPrediction.gender.value).to.be.undefined; - expect(docPrediction.issuanceDate.value).to.be.undefined; - expect(docPrediction.expiryDate.value).to.be.undefined; - expect(docPrediction.mrz1.value).to.be.undefined; - expect(docPrediction.mrz2.value).to.be.undefined; + assert.strictEqual(docPrediction.country.value, undefined); + assert.strictEqual(docPrediction.idNumber.value, undefined); + assert.strictEqual(docPrediction.givenNames.length, 0); + assert.strictEqual(docPrediction.surname.value, undefined); + assert.strictEqual(docPrediction.birthDate.value, undefined); + assert.strictEqual(docPrediction.birthPlace.value, undefined); + assert.strictEqual(docPrediction.gender.value, undefined); + assert.strictEqual(docPrediction.issuanceDate.value, undefined); + assert.strictEqual(docPrediction.expiryDate.value, undefined); + assert.strictEqual(docPrediction.mrz1.value, undefined); + assert.strictEqual(docPrediction.mrz2.value, undefined); }); it("should load a complete document prediction", async () => { @@ -36,6 +36,6 @@ describe("MindeeV1 - PassportV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.PassportV1, response.document); const docString = await fs.readFile(path.join(dataPath.docString)); - expect(doc.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); }); diff --git a/tests/v1/product/receipt/receiptV5.spec.ts b/tests/v1/product/receipt/receiptV5.spec.ts index 87c8e8c06..689df8e63 100644 --- a/tests/v1/product/receipt/receiptV5.spec.ts +++ b/tests/v1/product/receipt/receiptV5.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import path from "path"; import { V1_PRODUCT_PATH } from "../../../index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as mindee from "@/index.js"; @@ -18,20 +18,20 @@ describe("MindeeV1 - ReceiptV5 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.ReceiptV5, response.document); const docPrediction = doc.inference.prediction; - expect(docPrediction.locale.value).to.be.undefined; - expect(docPrediction.date.value).to.be.undefined; - expect(docPrediction.time.value).to.be.undefined; - expect(docPrediction.totalAmount.value).to.be.undefined; - expect(docPrediction.totalNet.value).to.be.undefined; - expect(docPrediction.totalTax.value).to.be.undefined; - expect(docPrediction.tip.value).to.be.undefined; - expect(docPrediction.taxes.length).to.be.equals(0); - expect(docPrediction.supplierName.value).to.be.undefined; - expect(docPrediction.supplierCompanyRegistrations.length).to.be.equals(0); - expect(docPrediction.supplierAddress.value).to.be.undefined; - expect(docPrediction.supplierPhoneNumber.value).to.be.undefined; - expect(docPrediction.receiptNumber.value).to.be.undefined; - expect(docPrediction.lineItems.length).to.be.equals(0); + assert.strictEqual(docPrediction.locale.value, undefined); + assert.strictEqual(docPrediction.date.value, undefined); + assert.strictEqual(docPrediction.time.value, undefined); + assert.strictEqual(docPrediction.totalAmount.value, undefined); + assert.strictEqual(docPrediction.totalNet.value, undefined); + assert.strictEqual(docPrediction.totalTax.value, undefined); + assert.strictEqual(docPrediction.tip.value, undefined); + assert.strictEqual(docPrediction.taxes.length, 0); + assert.strictEqual(docPrediction.supplierName.value, undefined); + assert.strictEqual(docPrediction.supplierCompanyRegistrations.length, 0); + assert.strictEqual(docPrediction.supplierAddress.value, undefined); + assert.strictEqual(docPrediction.supplierPhoneNumber.value, undefined); + assert.strictEqual(docPrediction.receiptNumber.value, undefined); + assert.strictEqual(docPrediction.lineItems.length, 0); }); it("should load a complete document prediction", async () => { @@ -39,6 +39,6 @@ describe("MindeeV1 - ReceiptV5 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.ReceiptV5, response.document); const docString = await fs.readFile(path.join(dataPath.docString)); - expect(doc.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); }); diff --git a/tests/v1/product/resume/resumeV1.spec.ts b/tests/v1/product/resume/resumeV1.spec.ts index 7635a48ee..6ffbd1f04 100644 --- a/tests/v1/product/resume/resumeV1.spec.ts +++ b/tests/v1/product/resume/resumeV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import path from "path"; import { V1_PRODUCT_PATH } from "../../../index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as mindee from "@/index.js"; @@ -18,22 +18,22 @@ describe("MindeeV1 - ResumeV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.ResumeV1, response.document); const docPrediction = doc.inference.prediction; - expect(docPrediction.documentLanguage.value).to.be.undefined; - expect(docPrediction.givenNames.length).to.be.equals(0); - expect(docPrediction.surnames.length).to.be.equals(0); - expect(docPrediction.nationality.value).to.be.undefined; - expect(docPrediction.emailAddress.value).to.be.undefined; - expect(docPrediction.phoneNumber.value).to.be.undefined; - expect(docPrediction.address.value).to.be.undefined; - expect(docPrediction.socialNetworksUrls.length).to.be.equals(0); - expect(docPrediction.profession.value).to.be.undefined; - expect(docPrediction.jobApplied.value).to.be.undefined; - expect(docPrediction.languages.length).to.be.equals(0); - expect(docPrediction.hardSkills.length).to.be.equals(0); - expect(docPrediction.softSkills.length).to.be.equals(0); - expect(docPrediction.education.length).to.be.equals(0); - expect(docPrediction.professionalExperiences.length).to.be.equals(0); - expect(docPrediction.certificates.length).to.be.equals(0); + assert.strictEqual(docPrediction.documentLanguage.value, undefined); + assert.strictEqual(docPrediction.givenNames.length, 0); + assert.strictEqual(docPrediction.surnames.length, 0); + assert.strictEqual(docPrediction.nationality.value, undefined); + assert.strictEqual(docPrediction.emailAddress.value, undefined); + assert.strictEqual(docPrediction.phoneNumber.value, undefined); + assert.strictEqual(docPrediction.address.value, undefined); + assert.strictEqual(docPrediction.socialNetworksUrls.length, 0); + assert.strictEqual(docPrediction.profession.value, undefined); + assert.strictEqual(docPrediction.jobApplied.value, undefined); + assert.strictEqual(docPrediction.languages.length, 0); + assert.strictEqual(docPrediction.hardSkills.length, 0); + assert.strictEqual(docPrediction.softSkills.length, 0); + assert.strictEqual(docPrediction.education.length, 0); + assert.strictEqual(docPrediction.professionalExperiences.length, 0); + assert.strictEqual(docPrediction.certificates.length, 0); }); it("should load a complete document prediction", async () => { @@ -41,6 +41,6 @@ describe("MindeeV1 - ResumeV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.ResumeV1, response.document); const docString = await fs.readFile(path.join(dataPath.docString)); - expect(doc.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); }); diff --git a/tests/v1/product/us/bankCheck/bankCheckV1.spec.ts b/tests/v1/product/us/bankCheck/bankCheckV1.spec.ts index eaeca7952..8a434c73f 100644 --- a/tests/v1/product/us/bankCheck/bankCheckV1.spec.ts +++ b/tests/v1/product/us/bankCheck/bankCheckV1.spec.ts @@ -1,7 +1,7 @@ import { promises as fs } from "fs"; import path from "path"; import { V1_PRODUCT_PATH } from "../../../../index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import * as mindee from "@/index.js"; @@ -18,12 +18,12 @@ describe("MindeeV1 - BankCheckV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.us.BankCheckV1, response.document); const docPrediction = doc.inference.prediction; - expect(docPrediction.date.value).to.be.undefined; - expect(docPrediction.amount.value).to.be.undefined; - expect(docPrediction.payees.length).to.be.equals(0); - expect(docPrediction.routingNumber.value).to.be.undefined; - expect(docPrediction.accountNumber.value).to.be.undefined; - expect(docPrediction.checkNumber.value).to.be.undefined; + assert.strictEqual(docPrediction.date.value, undefined); + assert.strictEqual(docPrediction.amount.value, undefined); + assert.strictEqual(docPrediction.payees.length, 0); + assert.strictEqual(docPrediction.routingNumber.value, undefined); + assert.strictEqual(docPrediction.accountNumber.value, undefined); + assert.strictEqual(docPrediction.checkNumber.value, undefined); }); it("should load a complete document prediction", async () => { @@ -31,7 +31,7 @@ describe("MindeeV1 - BankCheckV1 Object initialization", async () => { const response = JSON.parse(jsonData.toString()); const doc = new mindee.v1.Document(mindee.v1.product.us.BankCheckV1, response.document); const docString = await fs.readFile(path.join(dataPath.docString)); - expect(doc.toString()).to.be.equals(docString.toString()); + assert.strictEqual(doc.toString(), docString.toString()); }); it("should load a complete page 0 prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.complete)); @@ -39,6 +39,6 @@ describe("MindeeV1 - BankCheckV1 Object initialization", async () => { const doc = new mindee.v1.Document(mindee.v1.product.us.BankCheckV1, response.document); const page0 = doc.inference.pages[0]; const docString = await fs.readFile(path.join(dataPath.page0String)); - expect(page0.toString()).to.be.equals(docString.toString()); + assert.strictEqual(page0.toString(), docString.toString()); }); }); diff --git a/tests/v1/workflows/workflow.integration.ts b/tests/v1/workflows/workflow.integration.ts index 1167af9bd..8f0464174 100644 --- a/tests/v1/workflows/workflow.integration.ts +++ b/tests/v1/workflows/workflow.integration.ts @@ -1,6 +1,6 @@ import * as mindee from "@/index.js"; import { ExecutionPriority } from "@/v1/parsing/common/index.js"; -import { expect } from "chai"; +import assert from "node:assert"; import { LocalInputSource } from "@/input/index.js"; import { OptionalAsyncOptions } from "@/v1/index.js"; import { FinancialDocumentV1 } from "@/v1/product/index.js"; @@ -23,13 +23,16 @@ describe("MindeeV1 - Workflow calls", () => { }); it("should retrieve a correct response from the API.", async () => { - const currentDateTime = new Date().toISOString().replace(/T/, "-").replace(/\..+/, ""); + const currentDateTime = new Date() + .toISOString() + .replace(/T/, "-") + .replace(/\..+/, ""); const response = await client.executeWorkflow( sample, workflowId, { alias: `node-${currentDateTime}`, priority: ExecutionPriority.low, rag: true }); - expect(response.execution.priority).to.equal(ExecutionPriority.low); - expect(response.execution.file.alias).to.equal(`node-${currentDateTime}`); + assert.strictEqual(response.execution.priority, ExecutionPriority.low); + assert.strictEqual(response.execution.file.alias, `node-${currentDateTime}`); }).timeout(60000); it("should poll with RAG disabled", async () => { @@ -41,8 +44,8 @@ describe("MindeeV1 - Workflow calls", () => { sample, asyncParams ); - expect(response.document?.toString()).to.not.be.empty; - expect(response.document?.inference.extras?.rag).to.be.undefined; + assert.ok(response.document?.toString()); + assert.strictEqual(response.document?.inference.extras?.rag, undefined); }).timeout(60000); it("should poll with RAG disabled and OCR words", async () => { @@ -55,10 +58,10 @@ describe("MindeeV1 - Workflow calls", () => { sample, asyncParams ); - expect(response.document?.toString()).to.not.be.empty; - expect(response.document?.inference.extras?.rag).to.be.undefined; - expect(response.document?.ocr).to.exist; - expect(response.document?.ocr?.toString()).to.not.be.empty; + assert.ok(response.document?.toString()); + assert.strictEqual(response.document?.inference.extras?.rag, undefined); + assert.ok(response.document?.ocr); + assert.ok(response.document?.ocr?.toString()); }).timeout(60000); it("should poll with RAG enabled", async () => { @@ -72,8 +75,8 @@ describe("MindeeV1 - Workflow calls", () => { asyncParams ); - expect(response.document?.toString()).to.not.be.empty; - expect(((response.document?.inference.extras?.rag) as RAGExtra).matchingDocumentId).to.not.be.empty; + assert.ok(response.document?.toString()); + assert.ok(((response.document?.inference.extras?.rag) as RAGExtra).matchingDocumentId); }).timeout(60000); it("should poll with RAG enabled and OCR words", async () => { @@ -87,9 +90,9 @@ describe("MindeeV1 - Workflow calls", () => { sample, asyncParams ); - expect(response.document?.toString()).to.not.be.empty; - expect(((response.document?.inference.extras?.rag) as RAGExtra).matchingDocumentId).to.not.be.empty; - expect(response.document?.ocr).to.exist; - expect(response.document?.ocr?.toString()).to.not.be.empty; + assert.ok(response.document?.toString()); + assert.ok(((response.document?.inference.extras?.rag) as RAGExtra).matchingDocumentId); + assert.ok(response.document?.ocr); + assert.ok(response.document?.ocr?.toString()); }).timeout(60000); }); diff --git a/tests/v1/workflows/workflow.spec.ts b/tests/v1/workflows/workflow.spec.ts index edda1c516..3ef884f6c 100644 --- a/tests/v1/workflows/workflow.spec.ts +++ b/tests/v1/workflows/workflow.spec.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import assert from "node:assert"; import { MockAgent, setGlobalDispatcher } from "undici"; import { promises as fs } from "fs"; import path from "path"; @@ -41,21 +41,21 @@ describe("MindeeV1 - Workflow executions", () => { const mockedExecution = await executeWorkflow( doc, "07ebf237-ff27-4eee-b6a2-425df4a5cca6" ); - expect(mockedExecution).to.not.be.null; - expect(mockedExecution.apiRequest).to.not.be.null; - expect(mockedExecution.execution.batchName).to.be.null; - expect(mockedExecution.execution.createdAt).to.be.null; - expect(mockedExecution.execution.file.alias).to.be.null; - expect(mockedExecution.execution.file.name).to.equal("default_sample.jpg"); - expect(mockedExecution.execution.id).to.equal("8c75c035-e083-4e77-ba3b-7c3598bd1d8a"); - expect(mockedExecution.execution.inference).to.be.null; - expect(mockedExecution.execution.priority).to.equal("medium"); - expect(mockedExecution.execution.reviewedAt).to.be.null; - expect(mockedExecution.execution.reviewedPrediction).to.be.null; - expect(mockedExecution.execution.status).to.equal("processing"); - expect(mockedExecution.execution.type).to.equal("manual"); - expect(mockedExecution.execution.uploadedAt?.toISOString()).to.equal("2024-11-13T13:02:31.699Z"); - expect(mockedExecution.execution.workflowId).to.equal("07ebf237-ff27-4eee-b6a2-425df4a5cca6"); + assert.notStrictEqual(mockedExecution, null); + assert.notStrictEqual(mockedExecution.apiRequest, null); + assert.strictEqual(mockedExecution.execution.batchName, null); + assert.strictEqual(mockedExecution.execution.createdAt, null); + assert.strictEqual(mockedExecution.execution.file.alias, null); + assert.strictEqual(mockedExecution.execution.file.name, "default_sample.jpg"); + assert.strictEqual(mockedExecution.execution.id, "8c75c035-e083-4e77-ba3b-7c3598bd1d8a"); + assert.strictEqual(mockedExecution.execution.inference, null); + assert.strictEqual(mockedExecution.execution.priority, "medium"); + assert.strictEqual(mockedExecution.execution.reviewedAt, null); + assert.strictEqual(mockedExecution.execution.reviewedPrediction, null); + assert.strictEqual(mockedExecution.execution.status, "processing"); + assert.strictEqual(mockedExecution.execution.type, "manual"); + assert.strictEqual(mockedExecution.execution.uploadedAt?.toISOString(), "2024-11-13T13:02:31.699Z"); + assert.strictEqual(mockedExecution.execution.workflowId, "07ebf237-ff27-4eee-b6a2-425df4a5cca6"); }); it("should deserialize response correctly when sending a document to an execution with priority and alias", @@ -65,20 +65,20 @@ describe("MindeeV1 - Workflow executions", () => { const mockedExecution = await executeWorkflow( doc, "07ebf237-ff27-4eee-b6a2-425df4a5cca6" ); - expect(mockedExecution).to.not.be.null; - expect(mockedExecution.apiRequest).to.not.be.null; - expect(mockedExecution.execution.batchName).to.be.null; - expect(mockedExecution.execution.createdAt).to.be.null; - expect(mockedExecution.execution.file.alias).to.equal("low-priority-sample-test"); - expect(mockedExecution.execution.file.name).to.equal("default_sample.jpg"); - expect(mockedExecution.execution.id).to.equal("b743e123-e18c-4b62-8a07-811a4f72afd3"); - expect(mockedExecution.execution.inference).to.be.null; - expect(mockedExecution.execution.priority).to.equal("low"); - expect(mockedExecution.execution.reviewedAt).to.be.null; - expect(mockedExecution.execution.reviewedPrediction).to.be.null; - expect(mockedExecution.execution.status).to.equal("processing"); - expect(mockedExecution.execution.type).to.equal("manual"); - expect(mockedExecution.execution.uploadedAt?.toISOString()).to.equal("2024-11-13T13:17:01.315Z"); - expect(mockedExecution.execution.workflowId).to.equal("07ebf237-ff27-4eee-b6a2-425df4a5cca6"); + assert.notStrictEqual(mockedExecution, null); + assert.notStrictEqual(mockedExecution.apiRequest, null); + assert.strictEqual(mockedExecution.execution.batchName, null); + assert.strictEqual(mockedExecution.execution.createdAt, null); + assert.strictEqual(mockedExecution.execution.file.alias, "low-priority-sample-test"); + assert.strictEqual(mockedExecution.execution.file.name, "default_sample.jpg"); + assert.strictEqual(mockedExecution.execution.id, "b743e123-e18c-4b62-8a07-811a4f72afd3"); + assert.strictEqual(mockedExecution.execution.inference, null); + assert.strictEqual(mockedExecution.execution.priority, "low"); + assert.strictEqual(mockedExecution.execution.reviewedAt, null); + assert.strictEqual(mockedExecution.execution.reviewedPrediction, null); + assert.strictEqual(mockedExecution.execution.status, "processing"); + assert.strictEqual(mockedExecution.execution.type, "manual"); + assert.strictEqual(mockedExecution.execution.uploadedAt?.toISOString(), "2024-11-13T13:17:01.315Z"); + assert.strictEqual(mockedExecution.execution.workflowId, "07ebf237-ff27-4eee-b6a2-425df4a5cca6"); }); }); diff --git a/tests/v2/client.integration.ts b/tests/v2/client.integration.ts index e98d7f3c6..c14626f31 100644 --- a/tests/v2/client.integration.ts +++ b/tests/v2/client.integration.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import assert from "node:assert/strict"; import path from "node:path"; import { @@ -19,22 +19,22 @@ import { RESOURCE_PATH, V2_PRODUCT_PATH } from "../index.js"; import { Extraction } from "@/v2/product/index.js"; function check422(err: unknown) { - expect(err).to.be.instanceOf(MindeeHttpErrorV2); + assert.ok(err instanceof MindeeHttpErrorV2); const errObj = err as MindeeHttpErrorV2; - expect(errObj.status).to.equal(422); - expect(errObj.code.startsWith("422-")).to.be.true; - expect(errObj.title).to.be.a("string"); - expect(errObj.detail).to.be.a("string"); - expect(errObj.errors).to.be.instanceOf(Array); + assert.equal(errObj.status, 422); + assert.ok(errObj.code.startsWith("422-")); + assert.equal(typeof errObj.title, "string"); + assert.equal(typeof errObj.detail, "string"); + assert.ok(Array.isArray(errObj.errors)); } function checkEmptyActiveOptions(inference: ExtractionInference) { - expect(inference.activeOptions).to.not.be.null; - expect(inference.activeOptions?.rag).to.be.false; - expect(inference.activeOptions?.rawText).to.be.false; - expect(inference.activeOptions?.polygon).to.be.false; - expect(inference.activeOptions?.confidence).to.be.false; - expect(inference.activeOptions?.textContext).to.be.false; + assert.notStrictEqual(inference.activeOptions, null); + assert.equal(inference.activeOptions?.rag, false); + assert.equal(inference.activeOptions?.rawText, false); + assert.equal(inference.activeOptions?.polygon, false); + assert.equal(inference.activeOptions?.confidence, false); + assert.equal(inference.activeOptions?.textContext, false); } describe("MindeeV2 – Client Integration Tests", () => { @@ -87,16 +87,16 @@ describe("MindeeV2 – Client Integration Tests", () => { const response = await client.enqueueAndGetResult( Extraction, source, params ); - expect(response).to.exist; - expect(response.inference).to.be.instanceOf(ExtractionInference); + assert.ok(response); + assert.ok(response.inference instanceof ExtractionInference); const inference: ExtractionInference = response.inference; - expect(inference.file?.name).to.equal("multipage_cut-2.pdf"); - expect(inference.file.pageCount).to.equal(2); - expect(inference.model?.id).to.equal(modelId); + assert.equal(inference.file?.name, "multipage_cut-2.pdf"); + assert.equal(inference.file.pageCount, 2); + assert.equal(inference.model?.id, modelId); - expect(inference.result).to.exist; - expect(inference.result.rawText).to.be.undefined; + assert.ok(inference.result); + assert.equal(inference.result.rawText, undefined); checkEmptyActiveOptions(inference); }).timeout(60000); @@ -116,27 +116,27 @@ describe("MindeeV2 – Client Integration Tests", () => { const response = await client.enqueueAndGetResult( Extraction, source, params ); - expect(response.inference).to.be.instanceOf(ExtractionInference); + assert.ok(response.inference instanceof ExtractionInference); const inference: ExtractionInference = response.inference; - expect(inference.file?.name).to.equal("default_sample.jpg"); - expect(inference.model?.id).to.equal(modelId); + assert.equal(inference.file?.name, "default_sample.jpg"); + assert.equal(inference.model?.id, modelId); - expect(inference.result).to.exist; - expect(inference.result.rawText).to.exist; + assert.ok(inference.result); + assert.ok(inference.result.rawText); const supplierField = inference.result.fields.get("supplier_name") as SimpleField; - expect(supplierField).to.be.instanceOf(SimpleField); - expect(supplierField.value).to.equal("John Smith"); - - expect(inference.result.rawText).to.exist; - expect(inference.activeOptions).to.not.be.null; - expect(inference.activeOptions?.rag).to.be.false; - expect(inference.activeOptions?.rawText).to.be.true; - expect(inference.activeOptions?.polygon).to.be.true; - expect(inference.activeOptions?.confidence).to.be.false; - expect(inference.activeOptions?.textContext).to.be.true; - - expect(inference.result.rawText?.pages).to.have.lengthOf(1); + assert.ok(supplierField instanceof SimpleField); + assert.equal(supplierField.value, "John Smith"); + + assert.ok(inference.result.rawText); + assert.notStrictEqual(inference.activeOptions, null); + assert.equal(inference.activeOptions?.rag, false); + assert.equal(inference.activeOptions?.rawText, true); + assert.equal(inference.activeOptions?.polygon, true); + assert.equal(inference.activeOptions?.confidence, false); + assert.equal(inference.activeOptions?.textContext, true); + + assert.equal(inference.result.rawText?.pages.length, 1); }).timeout(120000); it("Filled, single-page image – Base64Input - enqueueAndGetResult must succeed", async () => { @@ -155,17 +155,17 @@ describe("MindeeV2 – Client Integration Tests", () => { const response = await client.enqueueAndGetResult( Extraction, source, params ); - expect(response.inference).to.be.instanceOf(ExtractionInference); + assert.ok(response.inference instanceof ExtractionInference); const inference: ExtractionInference = response.inference; - expect(inference.file?.name).to.equal("receipt.jpg"); - expect(inference.model?.id).to.equal(modelId); + assert.equal(inference.file?.name, "receipt.jpg"); + assert.equal(inference.model?.id, modelId); - expect(inference.result).to.exist; - expect(inference.result.rawText).to.be.undefined; + assert.ok(inference.result); + assert.equal(inference.result.rawText, undefined); const supplierField = inference.result.fields.get("supplier_name") as SimpleField; - expect(supplierField).to.be.instanceOf(SimpleField); - expect(supplierField.value).to.equal("Clachan"); + assert.ok(supplierField instanceof SimpleField); + assert.equal(supplierField.value, "Clachan"); checkEmptyActiveOptions(inference); }).timeout(120000); @@ -176,7 +176,7 @@ describe("MindeeV2 – Client Integration Tests", () => { try { await client.enqueue(Extraction, source, badParams); - expect.fail("Expected the call to throw, but it succeeded."); + assert.fail("Expected the call to throw, but it succeeded."); } catch (err) { check422(err); } @@ -188,7 +188,7 @@ describe("MindeeV2 – Client Integration Tests", () => { Extraction, "00000000-0000-0000-0000-000000000000" ); - expect.fail("Expected the call to throw, but it succeeded."); + assert.fail("Expected the call to throw, but it succeeded."); } catch (err) { check422(err); } @@ -209,8 +209,8 @@ describe("MindeeV2 – Client Integration Tests", () => { const response: ExtractionResponse = await client.enqueueAndGetResult( Extraction, source, params ); - expect(response).to.exist; - expect(response.inference).to.be.instanceOf(ExtractionInference); + assert.ok(response); + assert.ok(response.inference instanceof ExtractionInference); }).timeout(60000); it("Data Schema Override - Overrides the data schema successfully", async () => { @@ -228,10 +228,10 @@ describe("MindeeV2 – Client Integration Tests", () => { const response = await client.enqueueAndGetResult( Extraction, source, params ); - expect(response).to.exist; - expect(response.inference).to.be.instanceOf(ExtractionInference); - expect(response.inference.result.fields.get("test_replace")).to.exist; - expect((response.inference.result.fields.get("test_replace") as SimpleField).value).to.be.equals("a test value"); + assert.ok(response); + assert.ok(response.inference instanceof ExtractionInference); + assert.ok(response.inference.result.fields.get("test_replace")); + assert.equal((response.inference.result.fields.get("test_replace") as SimpleField).value, "a test value"); }).timeout(60000); diff --git a/tests/v2/client.spec.ts b/tests/v2/client.spec.ts index 9db91a6a6..b20f62aae 100644 --- a/tests/v2/client.spec.ts +++ b/tests/v2/client.spec.ts @@ -1,4 +1,3 @@ -import { expect } from "chai"; import { MockAgent, setGlobalDispatcher } from "undici"; import path from "node:path"; import { Client, PathInput } from "@/index.js"; @@ -63,10 +62,10 @@ describe("MindeeV2 - ClientV2", () => { it("inherits base URL, token & headers from the env / options", () => { const api = (client as any).mindeeApi; - expect(api.settings.apiKey).to.equal("dummy"); - expect(api.settings.hostname).to.equal("v2-client-host"); - expect(api.settings.baseHeaders.Authorization).to.equal("dummy"); - expect(api.settings.baseHeaders["User-Agent"]).to.match(/mindee/i); + assert.strictEqual(api.settings.apiKey, "dummy"); + assert.strictEqual(api.settings.hostname, "v2-client-host"); + assert.strictEqual(api.settings.baseHeaders.Authorization, "dummy"); + assert.match(api.settings.baseHeaders["User-Agent"], /mindee/i); }); it("enqueue(path) on extraction rejects with MindeeHttpErrorV2 on 400", async () => { @@ -127,9 +126,9 @@ describe("MindeeV2 - ClientV2", () => { await assert.rejects( client.enqueue(Extraction, input, { modelId: "dummy-model" }), (error: any) => { - expect(error).to.be.instanceOf(MindeeHttpErrorV2); - expect(error.status).to.equal(400); - expect(error.detail).to.equal("forced failure from test"); + assert.ok(error instanceof MindeeHttpErrorV2); + assert.strictEqual(error.status, 400); + assert.strictEqual(error.detail, "forced failure from test"); return true; } ); @@ -140,18 +139,18 @@ describe("MindeeV2 - ClientV2", () => { "12345678-1234-1234-1234-123456789ABC" ); const job = resp.job; - expect(job.id).to.equal("12345678-1234-1234-1234-123456789ABC"); - expect(job.modelId).to.equal("87654321-4321-4321-4321-CBA987654321"); - expect(job.filename).to.equal("default_sample.jpg"); - expect(job.alias).to.equal("dummy-alias.jpg"); - expect(job.createdAt?.toISOString()).to.equal("2025-07-03T14:27:58.974Z"); - expect(job.status).to.equal("Processing"); - expect(job.pollingUrl).to.equal( + assert.strictEqual(job.id, "12345678-1234-1234-1234-123456789ABC"); + assert.strictEqual(job.modelId, "87654321-4321-4321-4321-CBA987654321"); + assert.strictEqual(job.filename, "default_sample.jpg"); + assert.strictEqual(job.alias, "dummy-alias.jpg"); + assert.strictEqual(job.createdAt?.toISOString(), "2025-07-03T14:27:58.974Z"); + assert.strictEqual(job.status, "Processing"); + assert.strictEqual(job.pollingUrl, "https://api-v2.mindee.net/v2/jobs/12345678-1234-1234-1234-123456789ABC" ); - expect(job.resultUrl).to.be.null; - expect(job.webhooks).to.have.length(0); - expect(job.error).to.be.undefined; + assert.strictEqual(job.resultUrl, null); + assert.strictEqual(job.webhooks.length, 0); + assert.strictEqual(job.error, undefined); }); }); }); diff --git a/tests/v2/parsing/job.spec.ts b/tests/v2/parsing/job.spec.ts index 81d4f41ac..6311825f5 100644 --- a/tests/v2/parsing/job.spec.ts +++ b/tests/v2/parsing/job.spec.ts @@ -1,11 +1,11 @@ +import assert from "node:assert/strict"; +import path from "node:path"; import { JobResponse, LocalResponse, ErrorResponse, } from "@/v2/index.js"; -import path from "node:path"; import { V2_RESOURCE_PATH } from "../../index.js"; -import { expect } from "chai"; const jobPath = path.join(V2_RESOURCE_PATH, "job"); @@ -21,8 +21,8 @@ describe("MindeeV2 - Job Response", async () => { const response = await loadV2Job( path.join(jobPath, "ok_processing.json") ); - expect(response.job).to.be.not.empty; - expect(response.job.error).to.be.undefined; + assert.ok(response.job); + assert.strictEqual(response.job.error, undefined); }); }); describe("Fail", async () => { @@ -30,11 +30,11 @@ describe("MindeeV2 - Job Response", async () => { const response = await loadV2Job( path.join(jobPath, "fail_422.json") ); - expect(response.job).to.be.not.empty; - expect(response.job.error).to.be.instanceOf(ErrorResponse); - expect(response.job.error?.status).to.eq(422); - expect(response.job.error?.code.startsWith("422-")).to.be.true; - expect(response.job.error?.errors).to.be.instanceOf(Array); + assert.ok(response.job); + assert.ok(response.job.error instanceof ErrorResponse); + assert.strictEqual(response.job.error?.status, 422); + assert.ok(response.job.error?.code.startsWith("422-")); + assert.ok(Array.isArray(response.job.error?.errors)); }); }); }); diff --git a/tests/v2/parsing/localResponse.spec.ts b/tests/v2/parsing/localResponse.spec.ts index fd6184686..e873f55e4 100644 --- a/tests/v2/parsing/localResponse.spec.ts +++ b/tests/v2/parsing/localResponse.spec.ts @@ -1,5 +1,5 @@ import * as fs from "node:fs/promises"; -import { expect } from "chai"; +import assert from "node:assert"; import { LocalResponse } from "@/v2/index.js"; import path from "path"; @@ -13,13 +13,13 @@ const filePath: string = path.join(V2_PRODUCT_PATH, "extraction/standard_field_t async function assertLocalResponse(localResponse: LocalResponse) { await localResponse.init(); - expect(localResponse.asDict()).to.not.be.null; - expect(localResponse.isValidHmacSignature(dummySecretKey, "invalid signature")).to.be.false; - expect(localResponse.getHmacSignature(dummySecretKey)).to.eq(signature); - expect(localResponse.isValidHmacSignature(dummySecretKey, signature)).to.be.true; + assert.notStrictEqual(localResponse.asDict(), null); + assert.strictEqual(localResponse.isValidHmacSignature(dummySecretKey, "invalid signature"), false); + assert.strictEqual(localResponse.getHmacSignature(dummySecretKey), signature); + assert.ok(localResponse.isValidHmacSignature(dummySecretKey, signature)); const inferenceResponse = await localResponse.deserializeResponse(ExtractionResponse); - expect(inferenceResponse).to.be.an.instanceof(ExtractionResponse); - expect(inferenceResponse.inference).to.not.be.null; + assert.ok(inferenceResponse instanceof ExtractionResponse); + assert.notStrictEqual(inferenceResponse.inference, null); } describe("MindeeV2 - Load Local Response", () => { @@ -42,9 +42,9 @@ describe("MindeeV2 - Load Local Response", () => { const fileObj = await fs.readFile(filePath, { encoding: "utf-8" }); const localResponse = new LocalResponse(fileObj); const response = await localResponse.deserializeResponse(ExtractionResponse); - expect(response).to.be.an.instanceof(ExtractionResponse); + assert.ok(response instanceof ExtractionResponse); - expect(JSON.stringify(response.getRawHttp())).to.eq(JSON.stringify(JSON.parse(fileObj))); + assert.strictEqual(JSON.stringify(response.getRawHttp()), JSON.stringify(JSON.parse(fileObj))); }); it("loading an inference works on catalog model", async () => { @@ -56,8 +56,6 @@ describe("MindeeV2 - Load Local Response", () => { ); const localResponse = new LocalResponse(jsonPath); const response: ExtractionResponse = await localResponse.deserializeResponse(ExtractionResponse); - expect(response.inference.model.id).to.equal( - "12345678-1234-1234-1234-123456789abc" - ); + assert.strictEqual(response.inference.model.id, "12345678-1234-1234-1234-123456789abc"); }); }); diff --git a/tests/v2/product/classification.spec.ts b/tests/v2/product/classification.spec.ts index a8c5e64be..d697d8972 100644 --- a/tests/v2/product/classification.spec.ts +++ b/tests/v2/product/classification.spec.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import assert from "node:assert/strict"; import path from "node:path"; import { ClassificationResponse } from "@/v2/product/index.js"; @@ -13,6 +13,6 @@ describe("MindeeV2 - Classification Response", async () => { path.join(V2_PRODUCT_PATH, "classification", "classification_single.json") ); const classification = response.inference.result.classification; - expect(classification.documentType).to.equal("invoice"); + assert.strictEqual(classification.documentType, "invoice"); }); }); diff --git a/tests/v2/product/crop.spec.ts b/tests/v2/product/crop.spec.ts index b0e7ca8ab..e9847ff6a 100644 --- a/tests/v2/product/crop.spec.ts +++ b/tests/v2/product/crop.spec.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import assert from "node:assert/strict"; import path from "node:path"; import { Polygon } from "@/geometry/index.js"; import { crop } from "@/v2/product/index.js"; @@ -13,33 +13,34 @@ describe("MindeeV2 - Crop Response", async () => { path.join(V2_PRODUCT_PATH, "crop", "crop_single.json") ); // Validate inference metadata - expect(response.inference.id).to.equal("12345678-1234-1234-1234-123456789abc"); - expect(response.inference.model.id).to.equal("test-model-id"); + assert.strictEqual(response.inference.id, "12345678-1234-1234-1234-123456789abc"); + assert.strictEqual(response.inference.model.id, "test-model-id"); // Validate file metadata - expect(response.inference.file.name).to.equal("sample.jpeg"); - expect(response.inference.file.pageCount).to.equal(1); - expect(response.inference.file.mimeType).to.equal("image/jpeg"); + assert.strictEqual(response.inference.file.name, "sample.jpeg"); + assert.strictEqual(response.inference.file.pageCount, 1); + assert.strictEqual(response.inference.file.mimeType, "image/jpeg"); // Validate crops const crops: crop.CropItem[] = response.inference.result.crops; - expect(crops).to.be.an("array").that.has.lengthOf(1); + assert.ok(Array.isArray(crops)); + assert.strictEqual(crops.length, 1); const firstCrop = crops[0]; - expect(firstCrop.objectType).to.equal("invoice"); - expect(firstCrop.location.page).to.equal(0); + assert.strictEqual(firstCrop.objectType, "invoice"); + assert.strictEqual(firstCrop.location.page, 0); const polygon: Polygon = firstCrop.location.polygon!; - expect(polygon.length).to.equal(4); - expect(polygon.length).to.equal(4); - expect(polygon[0][0]).to.equal(0.15); - expect(polygon[0][1]).to.equal(0.254); - expect(polygon[1][0]).to.equal(0.85); - expect(polygon[1][1]).to.equal(0.254); - expect(polygon[2][0]).to.equal(0.85); - expect(polygon[2][1]).to.equal(0.947); - expect(polygon[3][0]).to.equal(0.15); - expect(polygon[3][1]).to.equal(0.947); + assert.strictEqual(polygon.length, 4); + assert.strictEqual(polygon.length, 4); + assert.strictEqual(polygon[0][0], 0.15); + assert.strictEqual(polygon[0][1], 0.254); + assert.strictEqual(polygon[1][0], 0.85); + assert.strictEqual(polygon[1][1], 0.254); + assert.strictEqual(polygon[2][0], 0.85); + assert.strictEqual(polygon[2][1], 0.947); + assert.strictEqual(polygon[3][0], 0.15); + assert.strictEqual(polygon[3][1], 0.947); }); it("should load multiple results", async () => { @@ -48,45 +49,46 @@ describe("MindeeV2 - Crop Response", async () => { path.join(V2_PRODUCT_PATH, "crop", "crop_multiple.json") ); // Validate inference metadata - expect(response.inference.id).to.equal("12345678-1234-1234-1234-123456789abc"); - expect(response.inference.model.id).to.equal("test-model-id"); + assert.strictEqual(response.inference.id, "12345678-1234-1234-1234-123456789abc"); + assert.strictEqual(response.inference.model.id, "test-model-id"); // Validate file metadata - expect(response.inference.file.name).to.equal("default_sample.jpg"); - expect(response.inference.file.pageCount).to.equal(1); - expect(response.inference.file.mimeType).to.equal("image/jpeg"); + assert.strictEqual(response.inference.file.name, "default_sample.jpg"); + assert.strictEqual(response.inference.file.pageCount, 1); + assert.strictEqual(response.inference.file.mimeType, "image/jpeg"); const crops: crop.CropItem[] = response.inference.result.crops; - expect(crops).to.be.an("array").that.has.lengthOf(2); + assert.ok(Array.isArray(crops)); + assert.strictEqual(crops.length, 2); // Validate first crop item const firstCrop: crop.CropItem = crops[0]; - expect(firstCrop.objectType).to.equal("invoice"); - expect(firstCrop.location.page).to.equal(0); + assert.strictEqual(firstCrop.objectType, "invoice"); + assert.strictEqual(firstCrop.location.page, 0); const firstPolygon: Polygon = firstCrop.location.polygon!; - expect(firstPolygon.length).to.equal(4); - expect(firstPolygon[0][0]).to.equal(0.214); - expect(firstPolygon[0][1]).to.equal(0.079); - expect(firstPolygon[1][0]).to.equal(0.476); - expect(firstPolygon[1][1]).to.equal(0.079); - expect(firstPolygon[2][0]).to.equal(0.476); - expect(firstPolygon[2][1]).to.equal(0.979); - expect(firstPolygon[3][0]).to.equal(0.214); - expect(firstPolygon[3][1]).to.equal(0.979); + assert.strictEqual(firstPolygon.length, 4); + assert.strictEqual(firstPolygon[0][0], 0.214); + assert.strictEqual(firstPolygon[0][1], 0.079); + assert.strictEqual(firstPolygon[1][0], 0.476); + assert.strictEqual(firstPolygon[1][1], 0.079); + assert.strictEqual(firstPolygon[2][0], 0.476); + assert.strictEqual(firstPolygon[2][1], 0.979); + assert.strictEqual(firstPolygon[3][0], 0.214); + assert.strictEqual(firstPolygon[3][1], 0.979); // Validate second crop item const secondCrop: crop.CropItem = crops[1]; - expect(secondCrop.objectType).to.equal("invoice"); - expect(secondCrop.location.page).to.equal(0); + assert.strictEqual(secondCrop.objectType, "invoice"); + assert.strictEqual(secondCrop.location.page, 0); const secondPolygon: Polygon = secondCrop.location.polygon!; - expect(secondPolygon.length).to.equal(4); - expect(secondPolygon[0][0]).to.equal(0.547); - expect(secondPolygon[0][1]).to.equal(0.15); - expect(secondPolygon[1][0]).to.equal(0.862); - expect(secondPolygon[1][1]).to.equal(0.15); - expect(secondPolygon[2][0]).to.equal(0.862); - expect(secondPolygon[2][1]).to.equal(0.97); - expect(secondPolygon[3][0]).to.equal(0.547); - expect(secondPolygon[3][1]).to.equal(0.97); + assert.strictEqual(secondPolygon.length, 4); + assert.strictEqual(secondPolygon[0][0], 0.547); + assert.strictEqual(secondPolygon[0][1], 0.15); + assert.strictEqual(secondPolygon[1][0], 0.862); + assert.strictEqual(secondPolygon[1][1], 0.15); + assert.strictEqual(secondPolygon[2][0], 0.862); + assert.strictEqual(secondPolygon[2][1], 0.97); + assert.strictEqual(secondPolygon[3][0], 0.547); + assert.strictEqual(secondPolygon[3][1], 0.97); }); }); diff --git a/tests/v2/product/extraction.spec.ts b/tests/v2/product/extraction.spec.ts index 977c966bd..56eb87938 100644 --- a/tests/v2/product/extraction.spec.ts +++ b/tests/v2/product/extraction.spec.ts @@ -1,6 +1,6 @@ import path from "node:path"; import { promises as fs } from "node:fs"; -import { expect } from "chai"; +import assert from "node:assert"; import { Polygon } from "@/geometry/index.js"; import { FieldConfidence, @@ -30,27 +30,27 @@ describe("MindeeV2 - Extraction Response", async () => { ); const fields = response.inference.result.fields; - expect(fields).to.be.not.empty; - expect(fields.size).to.be.eq(21); - expect(fields.has("taxes")).to.be.true; - expect(fields.get("taxes")).to.not.be.null; - expect(fields.get("taxes")).to.be.an.instanceof(ListField); + assert.ok(fields); + assert.strictEqual(fields.size, 21); + assert.ok(fields.has("taxes")); + assert.notStrictEqual(fields.get("taxes"), null); + assert.ok(fields.get("taxes") instanceof ListField); - expect(fields.get("supplier_address")).to.not.be.null; - expect(fields.get("supplier_address")).to.be.an.instanceof(ObjectField); + assert.notStrictEqual(fields.get("supplier_address"), null); + assert.ok(fields.get("supplier_address") instanceof ObjectField); for (const entry of fields.values()) { if (entry instanceof SimpleField && entry.value === null) { continue; } switch (entry.constructor.name) { case "SimpleField": - expect((entry as SimpleField).value).to.not.be.null; + assert.notStrictEqual((entry as SimpleField).value, null); break; case "ObjectField": - expect((entry as ObjectField).fields).to.not.be.null; + assert.notStrictEqual((entry as ObjectField).fields, null); break; case "ListField": - expect((entry as ListField).items).to.not.be.null; + assert.notStrictEqual((entry as ListField).items, null); break; } } @@ -63,61 +63,61 @@ describe("MindeeV2 - Extraction Response", async () => { ); const inference = response.inference; - expect(inference).to.not.be.undefined; - expect(inference.model.id).to.eq("12345678-1234-1234-1234-123456789abc"); + assert.notStrictEqual(inference, undefined); + assert.strictEqual(inference.model.id, "12345678-1234-1234-1234-123456789abc"); const model = inference.model; - expect(model).to.not.be.undefined; - expect(model.id).to.eq("12345678-1234-1234-1234-123456789abc"); + assert.notStrictEqual(model, undefined); + assert.strictEqual(model.id, "12345678-1234-1234-1234-123456789abc"); const file = inference.file; - expect(file).to.not.be.undefined; - expect(file.name).to.eq("complete.jpg"); - expect(file.alias ?? null).to.be.null; - expect(file.pageCount).to.eq(1); - expect(file.mimeType).to.eq("image/jpeg"); + assert.notStrictEqual(file, undefined); + assert.strictEqual(file.name, "complete.jpg"); + assert.strictEqual(file.alias ?? null, null); + assert.strictEqual(file.pageCount, 1); + assert.strictEqual(file.mimeType, "image/jpeg"); const fields = inference.result.fields; - expect(fields).to.be.not.empty; - expect(fields.size).to.be.eq(21); + assert.ok(fields); + assert.strictEqual(fields.size, 21); const dateField = fields.getSimpleField("date"); - expect(dateField).to.not.be.undefined; - expect(dateField.value).to.eq("2019-11-02"); + assert.notStrictEqual(dateField, undefined); + assert.strictEqual(dateField.value, "2019-11-02"); - expect(fields.has("taxes")).to.be.true; + assert.ok(fields.has("taxes")); const taxes = fields.get("taxes"); - expect(taxes).to.be.instanceOf(ListField); + assert.ok(taxes instanceof ListField); const taxesList = fields.getListField("taxes"); - expect(taxesList.items).to.have.lengthOf(1); - expect(taxesList.objectItems).to.have.lengthOf(1); - expect(taxes?.toString()).to.be.a("string").and.not.be.empty; + assert.strictEqual(taxesList.items.length, 1); + assert.strictEqual(taxesList.objectItems.length, 1); + assert.ok(typeof taxes?.toString() === "string" && taxes.toString().length > 0); const firstTaxItem = taxesList.items[0]; - expect(firstTaxItem).to.be.instanceOf(ObjectField); + assert.ok(firstTaxItem instanceof ObjectField); const taxItemObj = firstTaxItem as ObjectField; - expect(taxItemObj.fields.size).to.eq(3); + assert.strictEqual(taxItemObj.fields.size, 3); const baseField = taxItemObj.fields.getSimpleField("base"); - expect(baseField.value).to.eq(31.5); + assert.strictEqual(baseField.value, 31.5); - expect(fields.has("supplier_address")).to.be.true; + assert.ok(fields.has("supplier_address")); const supplierAddress = fields.get("supplier_address"); - expect(supplierAddress).to.be.instanceOf(ObjectField); + assert.ok(supplierAddress instanceof ObjectField); const supplierObj = fields.getObjectField("supplier_address"); const countryField = supplierObj.fields.getSimpleField("country"); - expect(countryField.value).to.eq("USA"); - expect(countryField.toString()).to.eq("USA"); - expect(supplierAddress?.toString()).to.be.a("string").and.not.be.empty; + assert.strictEqual(countryField.value, "USA"); + assert.strictEqual(countryField.toString(), "USA"); + assert.ok(typeof supplierAddress?.toString() === "string" && supplierAddress.toString().length > 0); const customerAddr = fields.getObjectField("customer_address"); const cityField = customerAddr.fields.getSimpleField("city"); - expect(cityField.value).to.eq("New York"); + assert.strictEqual(cityField.value, "New York"); - expect(inference.result.rawText).to.be.undefined; + assert.strictEqual(inference.result.rawText, undefined); }); }); @@ -127,41 +127,39 @@ describe("MindeeV2 - Extraction Response", async () => { ExtractionResponse, deepNestedFieldPath ); const fields = response.inference.result.fields; - expect(fields.get("field_simple")).to.be.an.instanceof(SimpleField); - expect(fields.get("field_object")).to.be.an.instanceof(ObjectField); + assert.ok(fields.get("field_simple") instanceof SimpleField); + assert.ok(fields.get("field_object") instanceof ObjectField); const fieldObject = fields.getObjectField("field_object"); - expect(fieldObject.getSimpleField("sub_object_simple")).to.be.an.instanceof(SimpleField); - expect(fieldObject.getListField("sub_object_list")).to.be.an.instanceof(ListField); - expect(fieldObject.getObjectField("sub_object_object")).to.be.an.instanceof(ObjectField); - expect(fieldObject.simpleFields.size).to.eq(1); - expect(fieldObject.listFields.size).to.eq(1); - expect(fieldObject.objectFields.size).to.eq(1); + assert.ok(fieldObject.getSimpleField("sub_object_simple") instanceof SimpleField); + assert.ok(fieldObject.getListField("sub_object_list") instanceof ListField); + assert.ok(fieldObject.getObjectField("sub_object_object") instanceof ObjectField); + assert.strictEqual(fieldObject.simpleFields.size, 1); + assert.strictEqual(fieldObject.listFields.size, 1); + assert.strictEqual(fieldObject.objectFields.size, 1); const lvl1 = fieldObject.fields; - expect(lvl1.get("sub_object_list")).to.be.an.instanceof(ListField); - expect(lvl1.get("sub_object_object")).to.be.an.instanceof(ObjectField); + assert.ok(lvl1.get("sub_object_list") instanceof ListField); + assert.ok(lvl1.get("sub_object_object") instanceof ObjectField); const subObjectObject = lvl1.getObjectField("sub_object_object"); const lvl2 = subObjectObject.fields; - expect( - lvl2.get("sub_object_object_sub_object_list") - ).to.be.an.instanceof(ListField); + assert.ok(lvl2.get("sub_object_object_sub_object_list") instanceof ListField); const nestedList = lvl2.getListField( "sub_object_object_sub_object_list" ); - expect(nestedList.items).to.not.be.empty; - expect(nestedList.items[0]).to.be.an.instanceof(ObjectField); + assert.ok(nestedList.items.length > 0); + assert.ok(nestedList.items[0] instanceof ObjectField); const firstItemObj = nestedList.items[0] as ObjectField; const deepSimple = firstItemObj.fields.get( "sub_object_object_sub_object_list_simple" ) as SimpleField; - expect(deepSimple).to.not.be.undefined; - expect(deepSimple.value).to.eq("value_9"); + assert.notStrictEqual(deepSimple, undefined); + assert.strictEqual(deepSimple.value, "value_9"); }); }); @@ -172,46 +170,46 @@ describe("MindeeV2 - Extraction Response", async () => { ); const fields = response.inference.result.fields; - expect(fields.get("field_simple_string")).to.be.instanceOf(SimpleField); + assert.ok(fields.get("field_simple_string") instanceof SimpleField); const simpleFieldStr = fields.getSimpleField("field_simple_string"); - expect(simpleFieldStr.value).to.be.eq("field_simple_string-value"); - expect(simpleFieldStr.stringValue).to.be.eq("field_simple_string-value"); - expect(simpleFieldStr.confidence).to.be.eq(FieldConfidence.Certain); - expect(() => simpleFieldStr.numberValue).to.throw("Value is not a number"); - expect(() => simpleFieldStr.booleanValue).to.throw("Value is not a boolean"); + assert.strictEqual(simpleFieldStr.value, "field_simple_string-value"); + assert.strictEqual(simpleFieldStr.stringValue, "field_simple_string-value"); + assert.strictEqual(simpleFieldStr.confidence, FieldConfidence.Certain); + assert.throws(() => simpleFieldStr.numberValue, /Value is not a number/); + assert.throws(() => simpleFieldStr.booleanValue, /Value is not a boolean/); - expect(fields.get("field_simple_float")).to.be.instanceOf(SimpleField); + assert.ok(fields.get("field_simple_float") instanceof SimpleField); const simpleFieldFloat = fields.getSimpleField("field_simple_float"); - expect(simpleFieldFloat.value).to.be.eq(1.1); - expect(simpleFieldFloat.numberValue).to.be.eq(1.1); - expect(simpleFieldFloat.confidence).to.be.eq(FieldConfidence.High); - expect(() => simpleFieldFloat.stringValue).to.throw("Value is not a string"); - expect(() => simpleFieldFloat.booleanValue).to.throw("Value is not a boolean"); + assert.strictEqual(simpleFieldFloat.value, 1.1); + assert.strictEqual(simpleFieldFloat.numberValue, 1.1); + assert.strictEqual(simpleFieldFloat.confidence, FieldConfidence.High); + assert.throws(() => simpleFieldFloat.stringValue, /Value is not a string/); + assert.throws(() => simpleFieldFloat.booleanValue, /Value is not a boolean/); - expect(fields.get("field_simple_int")).to.be.instanceOf(SimpleField); + assert.ok(fields.get("field_simple_int") instanceof SimpleField); const simpleFieldInt = fields.getSimpleField("field_simple_int"); - expect(simpleFieldInt.confidence).to.be.eq(FieldConfidence.Medium); - expect(simpleFieldInt.value).to.be.eq(12.0); + assert.strictEqual(simpleFieldInt.confidence, FieldConfidence.Medium); + assert.strictEqual(simpleFieldInt.value, 12.0); - expect(fields.get("field_simple_zero")).to.be.instanceOf(SimpleField); + assert.ok(fields.get("field_simple_zero") instanceof SimpleField); const simpleFieldZero = fields.getSimpleField("field_simple_zero"); - expect(simpleFieldZero.confidence).to.be.eq(FieldConfidence.Low); - expect(simpleFieldZero.value).to.be.eq(0); - expect(simpleFieldZero.numberValue).to.be.eq(0); + assert.strictEqual(simpleFieldZero.confidence, FieldConfidence.Low); + assert.strictEqual(simpleFieldZero.value, 0); + assert.strictEqual(simpleFieldZero.numberValue, 0); - expect(fields.get("field_simple_bool")).to.be.instanceOf(SimpleField); + assert.ok(fields.get("field_simple_bool") instanceof SimpleField); const simpleFieldBool = fields.getSimpleField("field_simple_bool"); - expect(simpleFieldBool.value).to.be.eq(true); - expect(simpleFieldBool.booleanValue).to.be.eq(true); - expect(() => simpleFieldBool.stringValue).to.throw("Value is not a string"); - expect(() => simpleFieldBool.numberValue).to.throw("Value is not a number"); + assert.strictEqual(simpleFieldBool.value, true); + assert.strictEqual(simpleFieldBool.booleanValue, true); + assert.throws(() => simpleFieldBool.stringValue, /Value is not a string/); + assert.throws(() => simpleFieldBool.numberValue, /Value is not a number/); - expect(fields.get("field_simple_null")).to.be.instanceOf(SimpleField); + assert.ok(fields.get("field_simple_null") instanceof SimpleField); const simpleFieldNull = fields.getSimpleField("field_simple_null"); - expect(simpleFieldNull.value).to.be.eq(null); - expect(simpleFieldNull.stringValue).to.be.eq(null); - expect(simpleFieldNull.numberValue).to.be.eq(null); - expect(simpleFieldNull.booleanValue).to.be.eq(null); + assert.strictEqual(simpleFieldNull.value, null); + assert.strictEqual(simpleFieldNull.stringValue, null); + assert.strictEqual(simpleFieldNull.numberValue, null); + assert.strictEqual(simpleFieldNull.booleanValue, null); }); it("should recognize simple list fields", async () => { @@ -220,14 +218,14 @@ describe("MindeeV2 - Extraction Response", async () => { ); const fields = response.inference.result.fields; - expect(fields.get("field_simple_list")).to.be.instanceOf(ListField); + assert.ok(fields.get("field_simple_list") instanceof ListField); const fieldSimpleList = fields.getListField("field_simple_list"); - expect(fieldSimpleList.items.length).to.be.eq(2); + assert.strictEqual(fieldSimpleList.items.length, 2); const subFields = fieldSimpleList.simpleItems; - expect(subFields.length).to.be.eq(2); + assert.strictEqual(subFields.length, 2); for (const subField of subFields) { - expect(subField.value).to.be.not.null; + assert.notStrictEqual(subField.value, null); } }); @@ -237,19 +235,19 @@ describe("MindeeV2 - Extraction Response", async () => { ); const fields = response.inference.result.fields; - expect(fields.get("field_object")).to.be.instanceOf(ObjectField); + assert.ok(fields.get("field_object") instanceof ObjectField); const objectField = fields.getObjectField("field_object"); - expect(objectField.fields.size).to.be.eq(2); + assert.strictEqual(objectField.fields.size, 2); const subFields = objectField.simpleFields; - expect(subFields.size).to.be.eq(2); + assert.strictEqual(subFields.size, 2); const subField1 = subFields.get("subfield_1"); - expect(subField1?.value).to.be.not.null; - expect(subField1?.confidence).to.be.eq(FieldConfidence.High); + assert.notStrictEqual(subField1?.value, null); + assert.strictEqual(subField1?.confidence, FieldConfidence.High); subFields.forEach((subField, fieldName) => { - expect(fieldName.startsWith("subfield_")).to.be.true; - expect(subField.value).to.be.not.null; + assert.ok(fieldName.startsWith("subfield_")); + assert.notStrictEqual(subField.value, null); }); }); @@ -259,22 +257,22 @@ describe("MindeeV2 - Extraction Response", async () => { ); const fields = response.inference.result.fields; - expect(fields.get("field_object_list")).to.be.instanceOf(ListField); + assert.ok(fields.get("field_object_list") instanceof ListField); const fieldObjectList = fields.getListField("field_object_list"); - expect(fieldObjectList.items.length).to.be.eq(2); + assert.strictEqual(fieldObjectList.items.length, 2); const objectItems = fieldObjectList.objectItems; - expect(objectItems.length).to.be.eq(2); + assert.strictEqual(objectItems.length, 2); for (const itemField of objectItems) { const subFields = itemField.simpleFields; - expect(subFields).to.be.not.null; + assert.notStrictEqual(subFields, null); const subField1 = subFields.get("subfield_1"); - expect(subField1?.value).to.be.not.null; + assert.notStrictEqual(subField1?.value, null); subFields.forEach((subField, fieldName) => { - expect(fieldName.startsWith("subfield_")).to.be.true; - expect(subField.value).to.be.not.null; + assert.ok(fieldName.startsWith("subfield_")); + assert.notStrictEqual(subField.value, null); }); } }); @@ -285,17 +283,17 @@ describe("MindeeV2 - Extraction Response", async () => { const response = await loadV2Response( ExtractionResponse, path.join(extractionPath, "raw_texts.json") ); - expect(response.inference.result.rag).to.be.undefined; + assert.strictEqual(response.inference.result.rag, undefined); const rawText = response.inference.result.rawText; - expect(rawText).to.be.instanceOf(field.RawText); + assert.ok(rawText instanceof field.RawText); const pages = rawText?.pages; if (pages === undefined) throw new Error("pages is undefined"); - expect(pages).to.be.an("array").and.have.lengthOf(2); + assert.ok(Array.isArray(pages) && pages.length === 2); const first = pages[0]; - expect(first.content).to.eq("This is the raw text of the first page..."); + assert.strictEqual(first.content, "This is the raw text of the first page..."); }); }); @@ -305,8 +303,8 @@ describe("MindeeV2 - Extraction Response", async () => { ExtractionResponse, path.join(extractionPath, "rag_matched.json") ); const rag = response.inference.result.rag; - expect(rag).to.be.instanceOf(field.RagMetadata); - expect(rag?.retrievedDocumentId).to.eq("12345abc-1234-1234-1234-123456789abc"); + assert.ok(rag instanceof field.RagMetadata); + assert.strictEqual(rag?.retrievedDocumentId, "12345abc-1234-1234-1234-123456789abc"); }); it("RAG metadata when not matched", async () => { @@ -314,8 +312,8 @@ describe("MindeeV2 - Extraction Response", async () => { ExtractionResponse, path.join(extractionPath, "rag_not_matched.json") ); const rag = response.inference.result.rag; - expect(rag).to.be.instanceOf(field.RagMetadata); - expect(rag?.retrievedDocumentId).to.be.undefined; + assert.ok(rag instanceof field.RagMetadata); + assert.strictEqual(rag?.retrievedDocumentId, undefined); }); }); @@ -326,8 +324,8 @@ describe("MindeeV2 - Extraction Response", async () => { ); const rstString = await fs.readFile(standardFieldRstPath, "utf8"); - expect(response.inference).to.not.be.null; - expect(response.inference.toString()).to.be.eq(rstString); + assert.notStrictEqual(response.inference, null); + assert.strictEqual(response.inference.toString(), rstString); }).timeout(10000); }); @@ -336,41 +334,41 @@ describe("MindeeV2 - Extraction Response", async () => { const response = await loadV2Response( ExtractionResponse, locationFieldPath ); - expect(response.inference).to.not.be.null; + assert.notStrictEqual(response.inference, null); const dateField = response.inference.result.fields.get("date") as SimpleField; - expect(dateField.locations).to.exist; - expect(dateField.locations![0]).to.exist; - expect(dateField.locations![0].page).to.equal(0); + assert.ok(dateField.locations); + assert.ok(dateField.locations![0]); + assert.strictEqual(dateField.locations![0].page, 0); const polygon: Polygon = dateField.locations![0].polygon!; - expect(polygon[0].length).to.equal(2); + assert.strictEqual(polygon[0].length, 2); - expect(polygon[0][0]).to.equal(0.948979073166918); - expect(polygon[0][1]).to.equal(0.23097924535067715); + assert.strictEqual(polygon[0][0], 0.948979073166918); + assert.strictEqual(polygon[0][1], 0.23097924535067715); - expect(polygon[1][0]).to.equal(0.85422); - expect(polygon[1][1]).to.equal(0.230072); + assert.strictEqual(polygon[1][0], 0.85422); + assert.strictEqual(polygon[1][1], 0.230072); - expect(polygon[2][0]).to.equal(0.8540899268330819); - expect(polygon[2][1]).to.equal(0.24365775464932288); + assert.strictEqual(polygon[2][0], 0.8540899268330819); + assert.strictEqual(polygon[2][1], 0.24365775464932288); - expect(polygon[3][0]).to.equal(0.948849); - expect(polygon[3][1]).to.equal(0.244565); + assert.strictEqual(polygon[3][0], 0.948849); + assert.strictEqual(polygon[3][1], 0.244565); const eqConfidenceEnum = dateField.confidence === FieldConfidence.Medium; - expect(eqConfidenceEnum).to.be.true; + assert.ok(eqConfidenceEnum); - expect(dateField.confidence === "Medium").to.be.true; - expect(FieldConfidence.toInt(dateField.confidence) === 2).to.be.true; + assert.ok(dateField.confidence === "Medium"); + assert.ok(FieldConfidence.toInt(dateField.confidence) === 2); - expect(FieldConfidence.greaterThan(dateField.confidence, FieldConfidence.Low)).to.be.true; - expect(FieldConfidence.greaterThanOrEqual(dateField.confidence, FieldConfidence.Low)).to.be.true; - expect(FieldConfidence.greaterThanOrEqual(dateField.confidence, FieldConfidence.Medium)).to.be.true; - expect(FieldConfidence.lessThanOrEqual(dateField.confidence, FieldConfidence.Medium)).to.be.true; - expect(FieldConfidence.lessThanOrEqual(dateField.confidence, FieldConfidence.Certain)).to.be.true; - expect(FieldConfidence.lessThan(dateField.confidence, FieldConfidence.Certain)).to.be.true; + assert.ok(FieldConfidence.greaterThan(dateField.confidence, FieldConfidence.Low)); + assert.ok(FieldConfidence.greaterThanOrEqual(dateField.confidence, FieldConfidence.Low)); + assert.ok(FieldConfidence.greaterThanOrEqual(dateField.confidence, FieldConfidence.Medium)); + assert.ok(FieldConfidence.lessThanOrEqual(dateField.confidence, FieldConfidence.Medium)); + assert.ok(FieldConfidence.lessThanOrEqual(dateField.confidence, FieldConfidence.Certain)); + assert.ok(FieldConfidence.lessThan(dateField.confidence, FieldConfidence.Certain)); }).timeout(10000); }); diff --git a/tests/v2/product/extractionParameter.spec.ts b/tests/v2/product/extractionParameter.spec.ts index 3318210ff..33832b2f9 100644 --- a/tests/v2/product/extractionParameter.spec.ts +++ b/tests/v2/product/extractionParameter.spec.ts @@ -1,7 +1,7 @@ import { StringDict } from "@/parsing/index.js"; import path from "path"; import { V2_PRODUCT_PATH } from "../../index.js"; -import { expect } from "chai"; +import assert from "node:assert/strict"; import { promises as fs } from "fs"; import { extraction } from "@/v2/product/index.js"; @@ -18,8 +18,8 @@ describe("MindeeV2 - Extraction Parameter", () => { const paramsInstance = new extraction.ExtractionParameters({ modelId: modelIdValue, }); - expect(paramsInstance.modelId).to.equal(modelIdValue); - expect(paramsInstance.getValidatedPollingOptions()).to.deep.equal({ + assert.strictEqual(paramsInstance.modelId, modelIdValue); + assert.deepStrictEqual(paramsInstance.getValidatedPollingOptions(), { delaySec: 1.5, initialDelaySec: 2, maxRetries: 80 @@ -41,7 +41,7 @@ describe("MindeeV2 - Extraction Parameter", () => { const params = new extraction.ExtractionParameters({ modelId: modelIdValue, }); - expect(params.dataSchema).to.be.undefined; + assert.strictEqual(params.dataSchema, undefined); }); it("should equate no matter the type", () => { @@ -58,9 +58,9 @@ describe("MindeeV2 - Extraction Parameter", () => { dataSchema: expectedDataSchemaObject, }); - expect(JSON.stringify(paramsDict.dataSchema)).to.eq(expectedDataSchemaString); - expect(paramsObject.dataSchema?.toString()).to.eq(expectedDataSchemaString); - expect(paramsString.dataSchema?.toString()).to.eq(expectedDataSchemaString); + assert.strictEqual(JSON.stringify(paramsDict.dataSchema), expectedDataSchemaString); + assert.strictEqual(paramsObject.dataSchema?.toString(), expectedDataSchemaString); + assert.strictEqual(paramsString.dataSchema?.toString(), expectedDataSchemaString); }); }); }); diff --git a/tests/v2/product/ocr.spec.ts b/tests/v2/product/ocr.spec.ts index 4135024cc..2677963dc 100644 --- a/tests/v2/product/ocr.spec.ts +++ b/tests/v2/product/ocr.spec.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import assert from "node:assert/strict"; import path from "node:path"; import { ocr } from "@/v2/product/index.js"; import { Polygon } from "@/geometry/index.js"; @@ -14,33 +14,34 @@ describe("MindeeV2 - OCR Response", async () => { path.join(V2_PRODUCT_PATH, "ocr", "ocr_single.json") ); // Validate inference metadata - expect(response.inference.id).to.equal("12345678-1234-1234-1234-123456789abc"); - expect(response.inference.model.id).to.equal("test-model-id"); + assert.strictEqual(response.inference.id, "12345678-1234-1234-1234-123456789abc"); + assert.strictEqual(response.inference.model.id, "test-model-id"); // Validate file metadata - expect(response.inference.file.name).to.equal("default_sample.jpg"); - expect(response.inference.file.pageCount).to.equal(1); - expect(response.inference.file.mimeType).to.equal("image/jpeg"); + assert.strictEqual(response.inference.file.name, "default_sample.jpg"); + assert.strictEqual(response.inference.file.pageCount, 1); + assert.strictEqual(response.inference.file.mimeType, "image/jpeg"); // Validate pages const pages: ocr.OcrPage[] = response.inference.result.pages; - expect(pages).to.be.an("array").that.has.lengthOf(1); + assert.ok(Array.isArray(pages)); + assert.strictEqual(pages.length, 1); // Validate first page const firstPage: ocr.OcrPage = pages[0]; - expect(firstPage.words).to.be.an("array"); + assert.ok(Array.isArray(firstPage.words)); // Check first word const firstWord: ocr.OcrWord = firstPage.words[0]; - expect(firstWord.content).to.equal("Shipper:"); + assert.strictEqual(firstWord.content, "Shipper:"); const firstPolygon: Polygon = firstWord.polygon; - expect(firstPolygon.length).to.equal(4); + assert.strictEqual(firstPolygon.length, 4); // Check another word (5th word: "INC.") const fifthWord: ocr.OcrWord = firstPage.words[4]; - expect(fifthWord.content).to.equal("INC."); + assert.strictEqual(fifthWord.content, "INC."); const fifthPolygon: Polygon = fifthWord.polygon; - expect(fifthPolygon.length).to.equal(4); + assert.strictEqual(fifthPolygon.length, 4); }); it("should load multiple results", async () => { @@ -49,12 +50,13 @@ describe("MindeeV2 - OCR Response", async () => { path.join(V2_PRODUCT_PATH, "ocr", "ocr_multiple.json") ); const pages: ocr.OcrPage[] = response.inference.result.pages; - expect(pages).to.be.an("array").that.has.lengthOf(3); + assert.ok(Array.isArray(pages)); + assert.strictEqual(pages.length, 3); // Validate that each page has words and content pages.forEach((page: ocr.OcrPage): void => { - expect(page.words).to.be.an("array"); - expect(page.content).to.be.a("string"); + assert.ok(Array.isArray(page.words)); + assert.strictEqual(typeof page.content, "string"); }); }); }); diff --git a/tests/v2/product/split.spec.ts b/tests/v2/product/split.spec.ts index 270428654..7e8f0ed56 100644 --- a/tests/v2/product/split.spec.ts +++ b/tests/v2/product/split.spec.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import assert from "node:assert/strict"; import path from "node:path"; import { split } from "@/v2/product/index.js"; @@ -13,14 +13,16 @@ describe("MindeeV2 - Split Response", async () => { path.join(V2_PRODUCT_PATH, "split", "split_single.json") ); const splits: split.SplitRange[] = response.inference.result.splits; - expect(splits).to.be.an("array").that.has.lengthOf(1); + assert.ok(Array.isArray(splits)); + assert.strictEqual(splits.length, 1); const firstSplit: split.SplitRange = splits[0]; - expect(firstSplit.documentType).to.equal("receipt"); + assert.strictEqual(firstSplit.documentType, "receipt"); - expect(firstSplit.pageRange).to.be.an("array").that.has.lengthOf(2); - expect(firstSplit.pageRange[0]).to.equal(0); - expect(firstSplit.pageRange[1]).to.equal(0); + assert.ok(Array.isArray(firstSplit.pageRange)); + assert.strictEqual(firstSplit.pageRange.length, 2); + assert.strictEqual(firstSplit.pageRange[0], 0); + assert.strictEqual(firstSplit.pageRange[1], 0); }); it("should load multiple results", async () => { @@ -29,18 +31,21 @@ describe("MindeeV2 - Split Response", async () => { path.join(V2_PRODUCT_PATH, "split", "split_multiple.json") ); const splits: split.SplitRange[] = response.inference.result.splits; - expect(splits).to.be.an("array").that.has.lengthOf(3); + assert.ok(Array.isArray(splits)); + assert.strictEqual(splits.length, 3); const firstSplit: split.SplitRange = splits[0]; - expect(firstSplit.documentType).to.equal("invoice"); - expect(firstSplit.pageRange).to.be.an("array").that.has.lengthOf(2); - expect(firstSplit.pageRange[0]).to.equal(0); - expect(firstSplit.pageRange[1]).to.equal(0); + assert.strictEqual(firstSplit.documentType, "invoice"); + assert.ok(Array.isArray(firstSplit.pageRange)); + assert.strictEqual(firstSplit.pageRange.length, 2); + assert.strictEqual(firstSplit.pageRange[0], 0); + assert.strictEqual(firstSplit.pageRange[1], 0); const secondSplit: split.SplitRange = splits[1]; - expect(secondSplit.documentType).to.equal("invoice"); - expect(secondSplit.pageRange).to.be.an("array").that.has.lengthOf(2); - expect(secondSplit.pageRange[0]).to.equal(1); - expect(secondSplit.pageRange[1]).to.equal(3); + assert.strictEqual(secondSplit.documentType, "invoice"); + assert.ok(Array.isArray(secondSplit.pageRange)); + assert.strictEqual(secondSplit.pageRange.length, 2); + assert.strictEqual(secondSplit.pageRange[0], 1); + assert.strictEqual(secondSplit.pageRange[1], 3); }); }); diff --git a/tests/v2/product/splitParameter.spec.ts b/tests/v2/product/splitParameter.spec.ts index 83aee3dde..8d08e4660 100644 --- a/tests/v2/product/splitParameter.spec.ts +++ b/tests/v2/product/splitParameter.spec.ts @@ -1,4 +1,4 @@ -import { expect } from "chai"; +import assert from "node:assert/strict"; import { split } from "@/v2/product/index.js"; describe("MindeeV2 - Split Parameter", () => { @@ -10,8 +10,8 @@ describe("MindeeV2 - Split Parameter", () => { const paramsInstance = new split.SplitParameters({ modelId: modelIdValue, }); - expect(paramsInstance.modelId).to.equal(modelIdValue); - expect(paramsInstance.getValidatedPollingOptions()).to.deep.equal({ + assert.strictEqual(paramsInstance.modelId, modelIdValue); + assert.deepStrictEqual(paramsInstance.getValidatedPollingOptions(), { delaySec: 1.5, initialDelaySec: 2, maxRetries: 80 @@ -27,9 +27,9 @@ describe("MindeeV2 - Split Parameter", () => { // @ts-expect-error - rag is not a valid option rag: true, }); - expect(paramsInstance.modelId).to.equal(modelIdValue); + assert.strictEqual(paramsInstance.modelId, modelIdValue); // @ts-expect-error - rag is not a valid option - expect(paramsInstance.rag).to.be.undefined; + assert.strictEqual(paramsInstance.rag, undefined); }); });