From 8e165fa2573a1b2f81c86f6ce496f148134120dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Fri, 24 Oct 2025 12:33:29 +0200 Subject: [PATCH] :recycle: rework tests structure --- .github/workflows/_test-integrations.yml | 1 - .github/workflows/_test-units.yml | 1 - tests/data | 2 +- .../invoiceSplitterExtractor.spec.ts | 6 +- .../multiReceiptsExtractor.spec.ts | 10 +-- tests/in.js | 77 +++++++++++++++++++ tests/index.ts | 4 + tests/input/sources.spec.ts | 23 +++--- tests/pdf/pdfTypes.spec.ts | 2 +- tests/v1/api/asyncResponse.spec.ts | 10 +-- tests/v1/api/feedbackResponse.spec.ts | 4 +- .../api/invoiceSplitterReconstruction.spec.ts | 9 ++- .../api/multiReceiptsReconstruction.spec.ts | 6 +- tests/v1/api/response.spec.ts | 8 +- tests/v1/extras/extras.integration.ts | 10 +-- tests/v1/extras/fullTextOcr.spec.ts | 22 +----- tests/v1/{product/ocr => extras}/ocr.spec.ts | 11 +-- tests/{ => v1}/input/localResponse.spec.ts | 27 ++----- tests/v1/input/sources.integration.ts | 18 ++--- tests/v1/input/urlInputSource.integration.ts | 3 +- .../barcodeReader/barcodeReaderV1.spec.ts | 13 ++-- .../billOfLading/billOfLadingV1.spec.ts | 13 ++-- .../businessCard/businessCardV1.spec.ts | 13 ++-- tests/v1/product/cropper/cropperV1.spec.ts | 13 ++-- .../v1/product/custom/customDocument.spec.ts | 25 +++--- tests/v1/product/custom/lineItems.spec.ts | 6 +- .../deliveryNote/deliveryNoteV1.spec.ts | 13 ++-- .../driverLicense/driverLicenseV1.spec.ts | 13 ++-- .../financialDocumentV1.spec.ts | 35 +++++---- .../bankAccountDetailsV1.spec.ts | 13 ++-- .../bankAccountDetailsV2.spec.ts | 13 ++-- .../fr/carteGrise/carteGriseV1.spec.ts | 13 ++-- .../fr/energyBill/energyBillV1.spec.ts | 13 ++-- .../fr/healthCard/healthCardV1.spec.ts | 13 ++-- tests/v1/product/fr/idCard/idCardV1.spec.ts | 13 ++-- tests/v1/product/fr/idCard/idCardV2.spec.ts | 13 ++-- tests/v1/product/fr/payslip/payslipV2.spec.ts | 13 ++-- tests/v1/product/fr/payslip/payslipV3.spec.ts | 13 ++-- .../v1/product/generated/generatedV1.spec.ts | 51 +++++++----- .../indianPassport/indianPassportV1.spec.ts | 13 ++-- .../internationalId/internationalIdV2.spec.ts | 13 ++-- tests/v1/product/invoice/invoiceV4.spec.ts | 13 ++-- .../invoiceSplitter.integration.ts | 14 ++-- .../invoiceSplitter/invoiceSplitterV1.spec.ts | 13 ++-- .../multiReceiptsDetectorV1.spec.ts | 13 ++-- .../nutritionFactsLabelV1.spec.ts | 13 ++-- tests/v1/product/passport/passportV1.spec.ts | 13 ++-- tests/v1/product/receipt/receiptV5.spec.ts | 13 ++-- tests/v1/product/resume/resumeV1.spec.ts | 13 ++-- .../product/us/bankCheck/bankCheckV1.spec.ts | 13 ++-- .../healthcareCard/healthcareCardV1.spec.ts | 13 ++-- tests/v1/product/us/usMail/usMailV3.spec.ts | 13 ++-- tests/v1/workflows/workflow.integration.ts | 4 +- tests/v2/clientV2.integration.ts | 9 +-- tests/v2/input/localResponse.spec.ts | 51 ++++++++++++ 55 files changed, 478 insertions(+), 322 deletions(-) create mode 100644 tests/in.js rename tests/v1/{product/ocr => extras}/ocr.spec.ts (77%) rename tests/{ => v1}/input/localResponse.spec.ts (77%) rename tests/{imageOperations => v1/product/invoiceSplitter}/invoiceSplitter.integration.ts (73%) create mode 100644 tests/v2/input/localResponse.spec.ts diff --git a/.github/workflows/_test-integrations.yml b/.github/workflows/_test-integrations.yml index 81f28c25..b4cda798 100644 --- a/.github/workflows/_test-integrations.yml +++ b/.github/workflows/_test-integrations.yml @@ -12,7 +12,6 @@ jobs: name: Run Integration Tests timeout-minutes: 30 strategy: - max-parallel: 4 matrix: os: - "ubuntu-latest" diff --git a/.github/workflows/_test-units.yml b/.github/workflows/_test-units.yml index 76f45e76..3639ffee 100644 --- a/.github/workflows/_test-units.yml +++ b/.github/workflows/_test-units.yml @@ -10,7 +10,6 @@ jobs: run-tests: name: Run Tests strategy: - max-parallel: 4 matrix: os: - "ubuntu-latest" diff --git a/tests/data b/tests/data index 5038d188..020a880b 160000 --- a/tests/data +++ b/tests/data @@ -1 +1 @@ -Subproject commit 5038d188b670a7a9a874189df1c08b6720907f89 +Subproject commit 020a880b76cc471a9efb3bdcafb2027403fb0429 diff --git a/tests/imageOperations/invoiceSplitterExtractor.spec.ts b/tests/imageOperations/invoiceSplitterExtractor.spec.ts index a8149b54..4d2eaddd 100644 --- a/tests/imageOperations/invoiceSplitterExtractor.spec.ts +++ b/tests/imageOperations/invoiceSplitterExtractor.spec.ts @@ -4,11 +4,11 @@ import path from "path"; import { InvoiceSplitterV1 } from "../../src/product"; import { extractInvoices } from "../../src/imageOperations"; import { PathInput } from "../../src"; -import { RESOURCE_PATH } from "../index"; +import { V1_PRODUCT_PATH } from "../index"; const dataPath = { - complete: path.join(RESOURCE_PATH, "products/invoice_splitter/response_v1/complete.json"), - fileSample: path.join(RESOURCE_PATH, "products/invoice_splitter/invoice_5p.pdf"), + complete: path.join(V1_PRODUCT_PATH, "invoice_splitter/response_v1/complete.json"), + fileSample: path.join(V1_PRODUCT_PATH, "invoice_splitter/invoice_5p.pdf"), }; describe("A multi-page invoice document", () => { diff --git a/tests/imageOperations/multiReceiptsExtractor.spec.ts b/tests/imageOperations/multiReceiptsExtractor.spec.ts index 3bd9df9b..ea8c65b6 100644 --- a/tests/imageOperations/multiReceiptsExtractor.spec.ts +++ b/tests/imageOperations/multiReceiptsExtractor.spec.ts @@ -4,13 +4,13 @@ import path from "path"; import { MultiReceiptsDetectorV1 } from "../../src/product"; import { extractReceipts } from "../../src/imageOperations"; import { PathInput } from "../../src"; -import { RESOURCE_PATH } from "../index"; +import { V1_PRODUCT_PATH } from "../index"; const dataPath = { - complete: path.join(RESOURCE_PATH, "products/multi_receipts_detector/response_v1/complete.json"), - fileSample: path.join(RESOURCE_PATH, "products/multi_receipts_detector/default_sample.jpg"), - completeMultiPage: path.join(RESOURCE_PATH, "products/multi_receipts_detector/response_v1/multipage_sample.json"), - multiPageSample: path.join(RESOURCE_PATH, "products/multi_receipts_detector/multipage_sample.pdf"), + complete: path.join(V1_PRODUCT_PATH, "multi_receipts_detector/response_v1/complete.json"), + fileSample: path.join(V1_PRODUCT_PATH, "multi_receipts_detector/default_sample.jpg"), + completeMultiPage: path.join(V1_PRODUCT_PATH, "multi_receipts_detector/response_v1/multipage_sample.json"), + multiPageSample: path.join(V1_PRODUCT_PATH, "multi_receipts_detector/multipage_sample.pdf"), }; describe("A single-page multi-receipts document", () => { diff --git a/tests/in.js b/tests/in.js new file mode 100644 index 00000000..7311fd96 --- /dev/null +++ b/tests/in.js @@ -0,0 +1,77 @@ +const fs = require("fs"); +const path = require("path"); +const axios = require("axios"); +const FormData = require("form-data"); + +async function sendFileWithPolling( + filePath, + modelId, + apiKey, + maxRetries = 30, + pollingInterval = 2 +) { + const fileName = path.basename(filePath); + const headers = { + "Authorization": apiKey + }; + + const formData = new FormData(); + formData.append("model_id", modelId); + formData.append("rag", "false"); + formData.append("file", fs.createReadStream(filePath), { + filename: fileName, + contentType: "application/octet-stream" + }); + + console.log(`Enqueuing file: ${filePath}`); + const response = await axios.post( + "https://api-v2.mindee.net/v2/inferences/enqueue", + formData, + {headers: { ...headers, ...formData.getHeaders() }} + ); + + const jobData = response.data.job; + const pollingUrl = jobData.polling_url; + + await new Promise(resolve => setTimeout(resolve, 3000)); + + for (let attempt = 0; attempt < maxRetries; attempt++) { + console.log(`Polling on: ${pollingUrl}`); + + const pollResponse = await axios.get(pollingUrl, { + headers, + maxRedirects: 0, + validateStatus: status => status >= 200 && status < 400 + }); + + const pollData = pollResponse.data; + const jobStatus = pollData.job?.status; + + if (pollResponse.status === 302 || jobStatus === "Processed") { + const resultUrl = pollData.job?.result_url; + console.log(`Get result from: ${resultUrl}`); + + const resultResponse = await axios.get(resultUrl, { headers }); + return resultResponse.data; + } + + await new Promise(resolve => setTimeout(resolve, pollingInterval * 1000)); + } + + throw new Error(`Polling timed out after ${maxRetries} attempts`); +} + +async function main() { + try { + const result = await sendFileWithPolling( + "/home/ianardee/Downloads/Invoice-5Z69WRLL-0003.pdf", + "3b87142f-0eb4-4e6d-92a8-1ed01f097052", + "md_xcygjjg8ehfaf2jfeyzomxghvhzh4kzs" + ); + console.log(result); + } catch (error) { + console.error("Error:", error.message); + } +} + +main(); diff --git a/tests/index.ts b/tests/index.ts index 782d5e1e..20f6f125 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -1,5 +1,9 @@ import path from "node:path"; export const RESOURCE_PATH = path.join(__dirname, "data"); + export const V1_RESOURCE_PATH = path.join(RESOURCE_PATH, "v1"); +export const V1_PRODUCT_PATH = path.join(V1_RESOURCE_PATH, "products"); + export const V2_RESOURCE_PATH = path.join(RESOURCE_PATH, "v2"); +export const V2_PRODUCT_PATH = path.join(V2_RESOURCE_PATH, "products"); diff --git a/tests/input/sources.spec.ts b/tests/input/sources.spec.ts index 2104fe82..816cd662 100644 --- a/tests/input/sources.spec.ts +++ b/tests/input/sources.spec.ts @@ -19,7 +19,7 @@ import { compressImage } from "../../src/imageOperations"; import { compressPdf } from "../../src/pdf"; import { extractTextFromPdf } from "../../src/pdf/pdfUtils"; import { logger } from "../../src/logger"; -import { RESOURCE_PATH } from "../index"; +import { RESOURCE_PATH, V1_PRODUCT_PATH } from "../index"; describe("Test different types of input", () => { const outputPath = path.join(RESOURCE_PATH, "output"); @@ -55,12 +55,12 @@ describe("Test different types of input", () => { it("should accept JPEG files from a path", async () => { const inputSource = new PathInput({ - inputPath: path.join(RESOURCE_PATH, "products/expense_receipts/default_sample.jpg"), + inputPath: path.join(V1_PRODUCT_PATH, "expense_receipts/default_sample.jpg"), }); await inputSource.init(); const expectedResult = await fs.promises.readFile( - path.join(RESOURCE_PATH, "products/expense_receipts/default_sample.jpg") + 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"); @@ -103,7 +103,7 @@ describe("Test different types of input", () => { }); it("should accept read streams", async () => { - const filePath = path.join(RESOURCE_PATH, "products/expense_receipts/default_sample.jpg"); + const filePath = path.join(V1_PRODUCT_PATH, "expense_receipts/default_sample.jpg"); const stream = fs.createReadStream(filePath); const filename = "default_sample.jpg"; const inputSource = new StreamInput({ @@ -121,7 +121,7 @@ describe("Test different types of input", () => { }); it("should accept raw bytes", async () => { - const filePath = path.join(RESOURCE_PATH, "products/expense_receipts/default_sample.jpg"); + const filePath = path.join(V1_PRODUCT_PATH, "expense_receipts/default_sample.jpg"); const inputBytes = await fs.promises.readFile(filePath); // don't provide an extension to see if we can detect MIME // type based on contents @@ -144,7 +144,7 @@ describe("Test different types of input", () => { const filename = "invoice_01.pdf"; const buffer = Buffer.from( await fs.promises.readFile( - path.join(RESOURCE_PATH, "products/invoices/invoice_10p.pdf") + path.join(V1_PRODUCT_PATH, "invoices/invoice_10p.pdf") ) ); const inputSource = new BufferInput({ @@ -257,7 +257,7 @@ describe("Test different types of input", () => { it("PDF Compress From InputSource", async () => { const pdfResizeInput = new PathInput( - { inputPath: path.join(RESOURCE_PATH, "products/invoice_splitter/default_sample.pdf") } + { inputPath: path.join(V1_PRODUCT_PATH, "invoice_splitter/default_sample.pdf") } ); await pdfResizeInput.init(); @@ -267,10 +267,7 @@ describe("Test different types of input", () => { await fs.promises.writeFile(path.join(outputPath, "resize_indirect.pdf"), compressedPdf); const initialFileStats = await fs.promises.stat( - path.join( - RESOURCE_PATH, - "products/invoice_splitter/default_sample.pdf" - ) + path.join(V1_PRODUCT_PATH, "invoice_splitter/default_sample.pdf") ); const renderedFileStats = await fs.promises.stat( path.join(outputPath, "resize_indirect.pdf") @@ -280,7 +277,7 @@ describe("Test different types of input", () => { it("PDF Compress From Compressor", async () => { const pdfResizeInput = new PathInput( - { inputPath: path.join(RESOURCE_PATH, "products/invoice_splitter/default_sample.pdf") } + { inputPath: path.join(V1_PRODUCT_PATH, "invoice_splitter/default_sample.pdf") } ); await pdfResizeInput.init(); @@ -297,7 +294,7 @@ describe("Test different types of input", () => { } const initialFileStats = await fs.promises.stat( - path.join(RESOURCE_PATH, "products/invoice_splitter/default_sample.pdf") + path.join(V1_PRODUCT_PATH, "invoice_splitter/default_sample.pdf") ); const renderedFileStats = await Promise.all( fileNames.map(fileName => fs.promises.stat(path.join(outputPath, fileName))) diff --git a/tests/pdf/pdfTypes.spec.ts b/tests/pdf/pdfTypes.spec.ts index aec23ac5..0b04fe7c 100644 --- a/tests/pdf/pdfTypes.spec.ts +++ b/tests/pdf/pdfTypes.spec.ts @@ -5,7 +5,7 @@ import * as pdf from "../../src/pdf"; import { PageOptions } from "../../src/input"; import { PageOptionsOperation } from "../../src"; import * as fs from "node:fs"; -import {RESOURCE_PATH} from "../index"; +import { RESOURCE_PATH } from "../index"; describe("Test pdf lib", () => { let client: mindee.Client; diff --git a/tests/v1/api/asyncResponse.spec.ts b/tests/v1/api/asyncResponse.spec.ts index 026dbfda..9055791e 100644 --- a/tests/v1/api/asyncResponse.spec.ts +++ b/tests/v1/api/asyncResponse.spec.ts @@ -10,7 +10,7 @@ import { RESOURCE_PATH } from "../../index"; describe("MindeeV1 - Asynchronous API predict response", () => { it("should parse a successful enqueue", async () => { const jsonData = await fs.readFile( - path.join(RESOURCE_PATH, "async/post_success.json") + path.join(RESOURCE_PATH, "v1/async/post_success.json") ); const httpResponse: StringDict = { data: JSON.parse(jsonData.toString()), @@ -26,7 +26,7 @@ describe("MindeeV1 - Asynchronous API predict response", () => { it("should parse a failed enqueue", async () => { const jsonData = await fs.readFile( - path.join(RESOURCE_PATH, "async/post_fail_forbidden.json") + path.join(RESOURCE_PATH, "v1/async/post_fail_forbidden.json") ); const httpResponse: StringDict = { data: JSON.parse(jsonData.toString()), @@ -36,7 +36,7 @@ describe("MindeeV1 - Asynchronous API predict response", () => { it("should parse a failed job", async () => { const jsonData = await fs.readFile( - path.join(RESOURCE_PATH, "async/get_failed_job_error.json") + path.join(RESOURCE_PATH, "v1/async/get_failed_job_error.json") ); const httpResponse: StringDict = { data: JSON.parse(jsonData.toString()), @@ -46,7 +46,7 @@ describe("MindeeV1 - Asynchronous API predict response", () => { it("should parse a job in progress", async () => { const jsonData = await fs.readFile( - path.join(RESOURCE_PATH, "async/get_processing.json") + path.join(RESOURCE_PATH, "v1/async/get_processing.json") ); const httpResponse: StringDict = { data: JSON.parse(jsonData.toString()), @@ -62,7 +62,7 @@ describe("MindeeV1 - Asynchronous API predict response", () => { it("should parse a completed job", async () => { const jsonData = await fs.readFile( - path.join(RESOURCE_PATH, "async/get_completed.json") + path.join(RESOURCE_PATH, "v1/async/get_completed.json") ); const httpResponse: StringDict = { data: JSON.parse(jsonData.toString()), diff --git a/tests/v1/api/feedbackResponse.spec.ts b/tests/v1/api/feedbackResponse.spec.ts index e5303acc..bfa57fbb 100644 --- a/tests/v1/api/feedbackResponse.spec.ts +++ b/tests/v1/api/feedbackResponse.spec.ts @@ -2,12 +2,12 @@ import path from "path"; import { expect } from "chai"; import { promises as fs } from "fs"; import { FeedbackResponse } from "../../../src/parsing/common"; -import { RESOURCE_PATH } from "../../index"; +import { V1_PRODUCT_PATH } from "../../index"; describe("MindeeV1 - Feedback response", () => { it("should load an empty feedback response", async () => { const jsonData = await fs.readFile( - path.join(RESOURCE_PATH, "products/invoices/feedback_response/empty.json") + 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; diff --git a/tests/v1/api/invoiceSplitterReconstruction.spec.ts b/tests/v1/api/invoiceSplitterReconstruction.spec.ts index 09d019c1..435f7205 100644 --- a/tests/v1/api/invoiceSplitterReconstruction.spec.ts +++ b/tests/v1/api/invoiceSplitterReconstruction.spec.ts @@ -5,13 +5,14 @@ import { Document } from "../../../src"; import { InvoiceSplitterV1 } from "../../../src/product"; import { extractInvoices } from "../../../src/imageOperations"; import { PathInput } from "../../../src"; +import { V1_PRODUCT_PATH } from "../../index"; describe("MindeeV1 - A Multipage Invoice Document", () => { it("should be split into the proper invoices", async () => { const jsonData = await fs.readFile( - path.resolve("tests/data/products/invoice_splitter/response_v1/complete.json") + path.join(V1_PRODUCT_PATH, "invoice_splitter/response_v1/complete.json") ); - const sourceDoc = new PathInput({ inputPath: path.resolve("tests/data/products/invoice_splitter/invoice_5p.pdf") }); + const sourceDoc = new PathInput({ inputPath: path.join(V1_PRODUCT_PATH, "invoice_splitter/invoice_5p.pdf") }); await sourceDoc.init(); const response = JSON.parse(jsonData.toString()); const doc = new Document(InvoiceSplitterV1, response.document); @@ -30,9 +31,9 @@ describe("MindeeV1 - A Multipage Invoice Document", () => { }); it("should be split differently if confidences are taken into account.", async () => { const jsonData = await fs.readFile( - path.resolve("tests/data/products/invoice_splitter/response_v1/complete.json") + path.resolve(V1_PRODUCT_PATH, "invoice_splitter/response_v1/complete.json") ); - const sourceDoc = new PathInput({ inputPath: path.resolve("tests/data/products/invoice_splitter/invoice_5p.pdf") }); + const sourceDoc = new PathInput({ inputPath: path.join(V1_PRODUCT_PATH, "invoice_splitter/invoice_5p.pdf") }); await sourceDoc.init(); const response = JSON.parse(jsonData.toString()); const doc = new Document(InvoiceSplitterV1, response.document); diff --git a/tests/v1/api/multiReceiptsReconstruction.spec.ts b/tests/v1/api/multiReceiptsReconstruction.spec.ts index b23b11e6..a6150cd9 100644 --- a/tests/v1/api/multiReceiptsReconstruction.spec.ts +++ b/tests/v1/api/multiReceiptsReconstruction.spec.ts @@ -5,15 +5,15 @@ import { Document } from "../../../src"; import { MultiReceiptsDetectorV1 } from "../../../src/product"; import { extractReceipts } from "../../../src/imageOperations"; import { PathInput } from "../../../src"; -import { RESOURCE_PATH } from "../../index"; +import { V1_PRODUCT_PATH } from "../../index"; describe("MindeeV1 - A Multi-Receipt Document", () => { it("should be split into the proper receipts", async () => { const jsonData = await fs.readFile( - path.resolve("tests/data/products/multi_receipts_detector/response_v1/complete.json") + path.join(V1_PRODUCT_PATH, "multi_receipts_detector/response_v1/complete.json") ); const sourceDoc = new PathInput( - { inputPath: path.join(RESOURCE_PATH, "products/multi_receipts_detector/default_sample.jpg") } + { inputPath: path.join(V1_PRODUCT_PATH, "multi_receipts_detector/default_sample.jpg") } ); await sourceDoc.init(); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/api/response.spec.ts b/tests/v1/api/response.spec.ts index 293f502d..bc960f59 100644 --- a/tests/v1/api/response.spec.ts +++ b/tests/v1/api/response.spec.ts @@ -3,12 +3,12 @@ import * as path from "path"; import { expect } from "chai"; import { PredictResponse } from "../../../src"; import { CustomV1, InvoiceV4, ReceiptV5 } from "../../../src/product"; -import { RESOURCE_PATH } from "../../index"; +import { V1_PRODUCT_PATH } from "../../index"; const dataPath = { - receiptV5: path.join(RESOURCE_PATH, "products/expense_receipts/response_v5/complete.json"), - invoiceV4: path.join(RESOURCE_PATH, "products/invoices/response_v4/complete.json"), - customV1: path.join(RESOURCE_PATH, "products/custom/response_v1/complete.json"), + receiptV5: path.join(V1_PRODUCT_PATH, "expense_receipts/response_v5/complete.json"), + invoiceV4: path.join(V1_PRODUCT_PATH, "invoices/response_v4/complete.json"), + customV1: path.join(V1_PRODUCT_PATH, "custom/response_v1/complete.json"), }; describe("MindeeV1 - Synchronous API predict response", () => { diff --git a/tests/v1/extras/extras.integration.ts b/tests/v1/extras/extras.integration.ts index 36eade9f..d5abb2b0 100644 --- a/tests/v1/extras/extras.integration.ts +++ b/tests/v1/extras/extras.integration.ts @@ -1,7 +1,7 @@ import { expect } from "chai"; import * as mindee from "../../../src"; import path from "path"; -import { RESOURCE_PATH } from "../../index"; +import { V1_PRODUCT_PATH } from "../../index"; describe("MindeeV1 - Extras Integration Tests", async () => { @@ -13,7 +13,7 @@ describe("MindeeV1 - Extras Integration Tests", async () => { it("should send cropper extra", async () => { const sample = client.docFromPath( - path.join(RESOURCE_PATH, "products/invoices/default_sample.jpg") + path.join(V1_PRODUCT_PATH, "invoices/default_sample.jpg") ); await sample.init(); const response = await client.parse( @@ -24,7 +24,7 @@ describe("MindeeV1 - Extras Integration Tests", async () => { it("should send full text OCR extra", async () => { const sample = client.docFromPath( - path.join(RESOURCE_PATH, "products/international_id/default_sample.jpg") + path.join(V1_PRODUCT_PATH, "international_id/default_sample.jpg") ); await sample.init(); const response = await client.enqueueAndParse( @@ -36,7 +36,7 @@ describe("MindeeV1 - Extras Integration Tests", async () => { it("should send OCR words synchronously", async () => { const sample = client.docFromPath( - path.join(RESOURCE_PATH, "products/financial_document/default_sample.jpg") + path.join(V1_PRODUCT_PATH, "financial_document/default_sample.jpg") ); await sample.init(); const response = await client.parse( @@ -49,7 +49,7 @@ describe("MindeeV1 - Extras Integration Tests", async () => { it("should send OCR words asynchronously", async () => { const sample = client.docFromPath( - path.join(RESOURCE_PATH, "products/financial_document/default_sample.jpg") + path.join(V1_PRODUCT_PATH, "financial_document/default_sample.jpg") ); await sample.init(); const response = await client.enqueueAndParse( diff --git a/tests/v1/extras/fullTextOcr.spec.ts b/tests/v1/extras/fullTextOcr.spec.ts index 138e59a0..115c4777 100644 --- a/tests/v1/extras/fullTextOcr.spec.ts +++ b/tests/v1/extras/fullTextOcr.spec.ts @@ -5,35 +5,19 @@ import { AsyncPredictResponse } from "../../../src"; import { InternationalIdV2 } from "../../../src/product"; import { RESOURCE_PATH } from "../../index"; -const fullTextOcrDir = path.join(RESOURCE_PATH, "extras/full_text_ocr"); +const fullTextOcrDir = path.join(RESOURCE_PATH, "v1/extras/full_text_ocr"); async function loadDocument() { - const jsonData = await fs.readFile(path.resolve(fullTextOcrDir, "complete.json")); + const jsonData = await fs.readFile(path.join(fullTextOcrDir, "complete.json")); return new AsyncPredictResponse( InternationalIdV2, JSON.parse(jsonData.toString()) ).document?.extras?.fullTextOcr.toString(); } -async function loadPage() { - const jsonData = await fs.readFile(path.resolve(fullTextOcrDir, "complete.json")); - return new AsyncPredictResponse( - InternationalIdV2, JSON.parse(jsonData.toString()) - )?.document?.inference.pages[0]?.extras?.fullTextOcr.toString(); -} - describe("MindeeV1 - Full Text Ocr", async () => { it("should load a Full Text OCR prediction at document level", async () => { - const expectedText = (await fs.readFile(path.resolve(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()); }); - - // Not enabled due to the fact that pages without content aren't generated. Left here as a reminder to implement the - // test in the next major version. - // TODO: Add test in next major. - // it("should load a Full Text OCR prediction per page", async () => { - // const expectedText = (await fs.readFile(path.resolve(fullTextOcrDir, "full_text_ocr.txt"))).toString(); - // const fullTextOcr = await loadPage(); - // expect(fullTextOcr).to.be.equals(expectedText); - // }); }); diff --git a/tests/v1/product/ocr/ocr.spec.ts b/tests/v1/extras/ocr.spec.ts similarity index 77% rename from tests/v1/product/ocr/ocr.spec.ts rename to tests/v1/extras/ocr.spec.ts index 9462ba1a..95a3c6ba 100644 --- a/tests/v1/product/ocr/ocr.spec.ts +++ b/tests/v1/extras/ocr.spec.ts @@ -1,15 +1,16 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; -import { ReceiptV5 } from "../../../../src/product"; -import { Document } from "../../../../src"; +import { ReceiptV5 } from "../../../src/product"; +import { Document } from "../../../src"; +import { RESOURCE_PATH } from "../../index"; const dataPath = { - complete: "tests/data/extras/ocr/complete.json", - docString: "tests/data/extras/ocr/ocr.txt" + complete: path.join(RESOURCE_PATH, "v1/extras/ocr/complete.json"), + docString: path.join(RESOURCE_PATH, "v1/extras/ocr/ocr.txt"), }; -describe("When getting all lines in an OCR", () => { +describe("MindeeV1 - When getting all lines in an OCR", () => { it("should not affect word order", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.complete)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/input/localResponse.spec.ts b/tests/v1/input/localResponse.spec.ts similarity index 77% rename from tests/input/localResponse.spec.ts rename to tests/v1/input/localResponse.spec.ts index 3add0fe2..742c28b9 100644 --- a/tests/input/localResponse.spec.ts +++ b/tests/v1/input/localResponse.spec.ts @@ -1,23 +1,22 @@ -import { LocalResponse } from "../../src"; import * as fs from "node:fs/promises"; import { expect } from "chai"; -import { Client, PredictResponse, AsyncPredictResponse, InferenceResponse } from "../../src"; -import { InternationalIdV2, InvoiceV4, MultiReceiptsDetectorV1 } from "../../src/product"; +import { Client, PredictResponse, AsyncPredictResponse, LocalResponse } from "../../../src"; +import { InternationalIdV2, InvoiceV4, MultiReceiptsDetectorV1 } from "../../../src/product"; import path from "path"; -import { RESOURCE_PATH } from "../index"; +import { V1_RESOURCE_PATH, V1_PRODUCT_PATH } from "../../index"; const signature: string = "5ed1673e34421217a5dbfcad905ee62261a3dd66c442f3edd19302072bbf70d0"; const dummySecretKey: string = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH"; -const filePath: string = path.join(RESOURCE_PATH, "/async/get_completed_empty.json"); +const filePath: string = path.join(V1_RESOURCE_PATH, "async/get_completed_empty.json"); const multiReceiptsDetectorPath: string = path.join( - RESOURCE_PATH, "products/multi_receipts_detector/response_v1/complete.json" + V1_PRODUCT_PATH, "multi_receipts_detector/response_v1/complete.json" ); -const failedPath: string = path.join(RESOURCE_PATH, "async/get_failed_job_error.json"); +const failedPath: string = path.join(V1_RESOURCE_PATH, "async/get_failed_job_error.json"); const internationalIdPath: string = path.join( - RESOURCE_PATH, "products/international_id/response_v2/complete.json" + V1_PRODUCT_PATH, "international_id/response_v2/complete.json" ); -describe("A valid local response", () => { +describe("MindeeV1 - Load Local Response", () => { it("should load a string properly.", async () => { const fileObj = await fs.readFile(filePath, { encoding: "utf-8" }); const localResponse = new LocalResponse(fileObj); @@ -76,14 +75,4 @@ describe("A valid local response", () => { expect(JSON.stringify(prediction.getRawHttp())).to.eq(JSON.stringify(JSON.parse(fileObj))); }); - - it("should deserialize a prediction.", async () => { - const filePath = "tests/data/v2/inference/standard_field_types.json"; - const fileObj = await fs.readFile(filePath, { encoding: "utf-8" }); - const localResponse = new LocalResponse(fileObj); - const response = await localResponse.deserializeResponse(InferenceResponse); - expect(response).to.be.an.instanceof(InferenceResponse); - - expect(JSON.stringify(response.getRawHttp())).to.eq(JSON.stringify(JSON.parse(fileObj))); - }); }); diff --git a/tests/v1/input/sources.integration.ts b/tests/v1/input/sources.integration.ts index 7eed7050..33b8a6f0 100644 --- a/tests/v1/input/sources.integration.ts +++ b/tests/v1/input/sources.integration.ts @@ -4,7 +4,7 @@ import { expect } from "chai"; import { promises as fs } from "fs"; import { createReadStream } from "node:fs"; import path from "path"; -import { RESOURCE_PATH } from "../../index"; +import { V1_PRODUCT_PATH } from "../../index"; describe("MindeeV1 - File Input Integration Tests", async () => { let client: mindee.Client; @@ -12,17 +12,17 @@ describe("MindeeV1 - File Input Integration Tests", async () => { beforeEach(() => { client = new mindee.Client(); - filePath = path.join(RESOURCE_PATH, "products/invoices/default_sample.jpg"); + filePath = path.join(V1_PRODUCT_PATH, "invoices/default_sample.jpg"); }); - it("should send a document from a direct path.", async () => { + it("should send a document from a direct path", async () => { const pathInput = client.docFromPath(filePath); await pathInput.init(); const result = await client.parse(InvoiceV4, pathInput); expect(result.document.id).to.be.a("string"); }).timeout(60000); - it("should send a base64 document.", async () => { + it("should send a base64 document", async () => { const content = await fs.readFile(filePath); const base64Content = content.toString("base64"); const base64Input = client.docFromBase64(base64Content, "testFile.jpg"); @@ -30,7 +30,7 @@ describe("MindeeV1 - File Input Integration Tests", async () => { expect(result.document.id).to.be.a("string"); }).timeout(60000); - it("should send a document from a readable stream.", async () => { + it("should send a document from a readable stream", async () => { const fileStream = createReadStream(filePath); const chunks: Buffer[] = []; for await (const chunk of fileStream) { @@ -43,14 +43,14 @@ describe("MindeeV1 - File Input Integration Tests", async () => { }).timeout(60000); - it("should send a document from bytes.", async () => { + it("should send a document from bytes", async () => { const inputBytes = await fs.readFile(filePath); const bytesInput = client.docFromBytes(inputBytes, "testFile.jpg"); const result = await client.parse(InvoiceV4, bytesInput); expect(result.document.id).to.be.a("string"); }).timeout(60000); - it("should send a document from buffer.", async () => { + it("should send a document from buffer", async () => { const buffer = await fs.readFile(filePath); const bufferInput = client.docFromBuffer(buffer, "testFile.jpg"); await bufferInput.init(); @@ -58,9 +58,9 @@ describe("MindeeV1 - File Input Integration Tests", async () => { expect(result.document.id).to.be.a("string"); }).timeout(60000); - it("should send a document from url.", async () => { + it("should send a document from a URL", async () => { const url = "https://raw.githubusercontent.com/mindee/client-lib-test-data/" + - "refs/heads/main/products/invoice_splitter/invoice_5p.pdf"; + "refs/heads/main/v1/products/invoice_splitter/invoice_5p.pdf"; const urlInput = client.docFromUrl(url); await urlInput.init(); const result = await client.parse(InvoiceV4, urlInput); diff --git a/tests/v1/input/urlInputSource.integration.ts b/tests/v1/input/urlInputSource.integration.ts index 06c53527..431be394 100644 --- a/tests/v1/input/urlInputSource.integration.ts +++ b/tests/v1/input/urlInputSource.integration.ts @@ -11,7 +11,8 @@ describe("MindeeV1 - URL Input Integration Test", async () => { } const client = new Client({ apiKey }); const remoteInput = new UrlInput({ - url: "https://github.com/mindee/client-lib-test-data/blob/main/products/invoice_splitter/invoice_5p.pdf?raw=true" + url: "https://github.com/mindee/client-lib-test-data/blob/main/v1/" + + "products/invoice_splitter/invoice_5p.pdf?raw=true" }); await remoteInput.init(); const localInput = await remoteInput.asLocalInputSource(); diff --git a/tests/v1/product/barcodeReader/barcodeReaderV1.spec.ts b/tests/v1/product/barcodeReader/barcodeReaderV1.spec.ts index b8f79865..3aff7da7 100644 --- a/tests/v1/product/barcodeReader/barcodeReaderV1.spec.ts +++ b/tests/v1/product/barcodeReader/barcodeReaderV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../index"; import { expect } from "chai"; import * as mindee from "../../../../src"; const dataPath = { - complete: "tests/data/products/barcode_reader/response_v1/complete.json", - empty: "tests/data/products/barcode_reader/response_v1/empty.json", - docString: "tests/data/products/barcode_reader/response_v1/summary_full.rst", - page0String: "tests/data/products/barcode_reader/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "barcode_reader/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "barcode_reader/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "barcode_reader/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "barcode_reader/response_v1/summary_page0.rst"), }; -describe("BarcodeReaderV1 Object initialization", async () => { +describe("MindeeV1 - BarcodeReaderV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/billOfLading/billOfLadingV1.spec.ts b/tests/v1/product/billOfLading/billOfLadingV1.spec.ts index 0daada93..1934d741 100644 --- a/tests/v1/product/billOfLading/billOfLadingV1.spec.ts +++ b/tests/v1/product/billOfLading/billOfLadingV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../index"; import { expect } from "chai"; import * as mindee from "../../../../src"; const dataPath = { - complete: "tests/data/products/bill_of_lading/response_v1/complete.json", - empty: "tests/data/products/bill_of_lading/response_v1/empty.json", - docString: "tests/data/products/bill_of_lading/response_v1/summary_full.rst", - page0String: "tests/data/products/bill_of_lading/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "bill_of_lading/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "bill_of_lading/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "bill_of_lading/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "bill_of_lading/response_v1/summary_page0.rst"), }; -describe("BillOfLadingV1 Object initialization", async () => { +describe("MindeeV1 - BillOfLadingV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/businessCard/businessCardV1.spec.ts b/tests/v1/product/businessCard/businessCardV1.spec.ts index 166ff940..04e4c054 100644 --- a/tests/v1/product/businessCard/businessCardV1.spec.ts +++ b/tests/v1/product/businessCard/businessCardV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../index"; import { expect } from "chai"; import * as mindee from "../../../../src"; const dataPath = { - complete: "tests/data/products/business_card/response_v1/complete.json", - empty: "tests/data/products/business_card/response_v1/empty.json", - docString: "tests/data/products/business_card/response_v1/summary_full.rst", - page0String: "tests/data/products/business_card/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "business_card/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "business_card/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "business_card/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "business_card/response_v1/summary_page0.rst"), }; -describe("BusinessCardV1 Object initialization", async () => { +describe("MindeeV1 - BusinessCardV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/cropper/cropperV1.spec.ts b/tests/v1/product/cropper/cropperV1.spec.ts index cbf6b98c..d606b458 100644 --- a/tests/v1/product/cropper/cropperV1.spec.ts +++ b/tests/v1/product/cropper/cropperV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../index"; import { expect } from "chai"; import * as mindee from "../../../../src"; const dataPath = { - complete: "tests/data/products/cropper/response_v1/complete.json", - empty: "tests/data/products/cropper/response_v1/empty.json", - docString: "tests/data/products/cropper/response_v1/summary_full.rst", - page0String: "tests/data/products/cropper/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "cropper/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "cropper/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "cropper/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "cropper/response_v1/summary_page0.rst"), }; -describe("CropperV1 Object initialization", async () => { +describe("MindeeV1 - CropperV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/custom/customDocument.spec.ts b/tests/v1/product/custom/customDocument.spec.ts index 8b40024a..8de7b43d 100644 --- a/tests/v1/product/custom/customDocument.spec.ts +++ b/tests/v1/product/custom/customDocument.spec.ts @@ -3,24 +3,25 @@ import * as path from "path"; import { expect } from "chai"; import * as mindee from "../../../../src"; import { CustomV1Document } from "../../../../src/product/custom/customV1Document"; -import { Page } from "../../../../src/parsing/common"; -import { CropperExtra } from "../../../../src/parsing/common/extras/cropperExtra"; +import { Page } from "../../../../src"; +import { CropperExtra } from "../../../../src/parsing/common/extras"; import { CustomV1 } from "../../../../src/product"; +import { V1_PRODUCT_PATH } from "../../../index"; const dataPath = { - complete: "tests/data/products/custom/response_v1/complete.json", - empty: "tests/data/products/custom/response_v1/empty.json", - docString: "tests/data/products/custom/response_v1/summary_full.rst", - page0String: "tests/data/products/custom/response_v1/summary_page0.rst", - page1String: "tests/data/products/custom/response_v1/summary_page1.rst", + complete: path.join(V1_PRODUCT_PATH, "custom/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "custom/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "custom/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "custom/response_v1/summary_page0.rst"), + page1String: path.join(V1_PRODUCT_PATH, "custom/response_v1/summary_page1.rst"), }; const dataPathV2 = { - complete: "tests/data/products/custom/response_v2/complete.json", - empty: "tests/data/products/custom/response_v2/empty.json", - docString: "tests/data/products/custom/response_v2/summary_full.rst", - page0String: "tests/data/products/custom/response_v2/summary_page0.rst", - page1String: "tests/data/products/custom/response_v2/summary_page1.rst", + complete: path.join(V1_PRODUCT_PATH, "custom/response_v2/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "custom/response_v2/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "custom/response_v2/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "custom/response_v2/summary_page0.rst"), + page1String: path.join(V1_PRODUCT_PATH, "custom/response_v2/summary_page1.rst"), }; describe("Custom Document Object initialization", async () => { diff --git a/tests/v1/product/custom/lineItems.spec.ts b/tests/v1/product/custom/lineItems.spec.ts index f767e118..c9b8b209 100644 --- a/tests/v1/product/custom/lineItems.spec.ts +++ b/tests/v1/product/custom/lineItems.spec.ts @@ -2,14 +2,16 @@ import { promises as fs } from "fs"; import { expect } from "chai"; import { CustomV1 } from "../../../../src/product"; import { CustomLine } from "../../../../src/parsing/custom"; +import { V1_PRODUCT_PATH } from "../../../index"; +import path from "node:path"; const dataPath = { singleTable01: - "tests/data/products/custom/response_v1/line_items/single_table_01.json", + path.join(V1_PRODUCT_PATH, "custom/response_v1/line_items/single_table_01.json"), }; const dataPathV2 = { singleTable01: - "tests/data/products/custom/response_v2/line_items/single_table_01.json", + path.join(V1_PRODUCT_PATH, "custom/response_v2/line_items/single_table_01.json"), }; describe("Custom Document Line Items", async () => { diff --git a/tests/v1/product/deliveryNote/deliveryNoteV1.spec.ts b/tests/v1/product/deliveryNote/deliveryNoteV1.spec.ts index ef6f66e8..4291a0ac 100644 --- a/tests/v1/product/deliveryNote/deliveryNoteV1.spec.ts +++ b/tests/v1/product/deliveryNote/deliveryNoteV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../index"; import { expect } from "chai"; import * as mindee from "../../../../src"; const dataPath = { - complete: "tests/data/products/delivery_notes/response_v1/complete.json", - empty: "tests/data/products/delivery_notes/response_v1/empty.json", - docString: "tests/data/products/delivery_notes/response_v1/summary_full.rst", - page0String: "tests/data/products/delivery_notes/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "delivery_notes/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "delivery_notes/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "delivery_notes/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "delivery_notes/response_v1/summary_page0.rst"), }; -describe("DeliveryNoteV1 Object initialization", async () => { +describe("MindeeV1 - DeliveryNoteV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/driverLicense/driverLicenseV1.spec.ts b/tests/v1/product/driverLicense/driverLicenseV1.spec.ts index eb692110..46205bc3 100644 --- a/tests/v1/product/driverLicense/driverLicenseV1.spec.ts +++ b/tests/v1/product/driverLicense/driverLicenseV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../index"; import { expect } from "chai"; import * as mindee from "../../../../src"; const dataPath = { - complete: "tests/data/products/driver_license/response_v1/complete.json", - empty: "tests/data/products/driver_license/response_v1/empty.json", - docString: "tests/data/products/driver_license/response_v1/summary_full.rst", - page0String: "tests/data/products/driver_license/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "driver_license/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "driver_license/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "driver_license/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "driver_license/response_v1/summary_page0.rst"), }; -describe("DriverLicenseV1 Object initialization", async () => { +describe("MindeeV1 - DriverLicenseV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/financialDocument/financialDocumentV1.spec.ts b/tests/v1/product/financialDocument/financialDocumentV1.spec.ts index e44c4b6c..0abeed70 100644 --- a/tests/v1/product/financialDocument/financialDocumentV1.spec.ts +++ b/tests/v1/product/financialDocument/financialDocumentV1.spec.ts @@ -2,21 +2,30 @@ import { promises as fs } from "fs"; import * as path from "path"; import { expect } from "chai"; import * as mindee from "../../../../src"; +import { V1_PRODUCT_PATH } from "../../../index"; const dataPath = { - receiptComplete: - "tests/data/products/financial_document/response_v1/complete_receipt.json", - invoiceComplete: - "tests/data/products/financial_document/response_v1/complete_invoice.json", - empty: "tests/data/products/financial_document/response_v1/empty.json", - invoiceDocString: - "tests/data/products/financial_document/response_v1/summary_full_invoice.rst", - receiptDocString: - "tests/data/products/financial_document/response_v1/summary_full_receipt.rst", - page0InvoiceString: - "tests/data/products/financial_document/response_v1/summary_page0_invoice.rst", - page0ReceiptString: - "tests/data/products/financial_document/response_v1/summary_page0_receipt.rst", + receiptComplete: path.join( + V1_PRODUCT_PATH, "financial_document/response_v1/complete_receipt.json" + ), + invoiceComplete: path.join( + V1_PRODUCT_PATH, "financial_document/response_v1/complete_invoice.json" + ), + empty: path.join( + V1_PRODUCT_PATH, "financial_document/response_v1/empty.json" + ), + invoiceDocString: path.join( + V1_PRODUCT_PATH, "financial_document/response_v1/summary_full_invoice.rst" + ), + receiptDocString: path.join( + V1_PRODUCT_PATH, "financial_document/response_v1/summary_full_receipt.rst" + ), + page0InvoiceString: path.join( + V1_PRODUCT_PATH, "financial_document/response_v1/summary_page0_invoice.rst" + ), + page0ReceiptString: path.join( + V1_PRODUCT_PATH, "financial_document/response_v1/summary_page0_receipt.rst" + ), }; describe("Financial Document V1 Object initialization", async () => { diff --git a/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV1.spec.ts b/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV1.spec.ts index 184696e9..3e531615 100644 --- a/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV1.spec.ts +++ b/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../../index"; import { expect } from "chai"; import * as mindee from "../../../../../src"; const dataPath = { - complete: "tests/data/products/bank_account_details/response_v1/complete.json", - empty: "tests/data/products/bank_account_details/response_v1/empty.json", - docString: "tests/data/products/bank_account_details/response_v1/summary_full.rst", - page0String: "tests/data/products/bank_account_details/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "bank_account_details/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "bank_account_details/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "bank_account_details/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "bank_account_details/response_v1/summary_page0.rst"), }; -describe("BankAccountDetailsV1 Object initialization", async () => { +describe("MindeeV1 - BankAccountDetailsV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV2.spec.ts b/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV2.spec.ts index 850d80f4..1c68c183 100644 --- a/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV2.spec.ts +++ b/tests/v1/product/fr/bankAccountDetails/bankAccountDetailsV2.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../../index"; import { expect } from "chai"; import * as mindee from "../../../../../src"; const dataPath = { - complete: "tests/data/products/bank_account_details/response_v2/complete.json", - empty: "tests/data/products/bank_account_details/response_v2/empty.json", - docString: "tests/data/products/bank_account_details/response_v2/summary_full.rst", - page0String: "tests/data/products/bank_account_details/response_v2/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "bank_account_details/response_v2/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "bank_account_details/response_v2/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "bank_account_details/response_v2/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "bank_account_details/response_v2/summary_page0.rst"), }; -describe("BankAccountDetailsV2 Object initialization", async () => { +describe("MindeeV1 - BankAccountDetailsV2 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/fr/carteGrise/carteGriseV1.spec.ts b/tests/v1/product/fr/carteGrise/carteGriseV1.spec.ts index 4cdebba0..a8901599 100644 --- a/tests/v1/product/fr/carteGrise/carteGriseV1.spec.ts +++ b/tests/v1/product/fr/carteGrise/carteGriseV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../../index"; import { expect } from "chai"; import * as mindee from "../../../../../src"; const dataPath = { - complete: "tests/data/products/carte_grise/response_v1/complete.json", - empty: "tests/data/products/carte_grise/response_v1/empty.json", - docString: "tests/data/products/carte_grise/response_v1/summary_full.rst", - page0String: "tests/data/products/carte_grise/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "carte_grise/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "carte_grise/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "carte_grise/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "carte_grise/response_v1/summary_page0.rst"), }; -describe("CarteGriseV1 Object initialization", async () => { +describe("MindeeV1 - CarteGriseV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/fr/energyBill/energyBillV1.spec.ts b/tests/v1/product/fr/energyBill/energyBillV1.spec.ts index 38fb11a1..1c1c03c3 100644 --- a/tests/v1/product/fr/energyBill/energyBillV1.spec.ts +++ b/tests/v1/product/fr/energyBill/energyBillV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../../index"; import { expect } from "chai"; import * as mindee from "../../../../../src"; const dataPath = { - complete: "tests/data/products/energy_bill_fra/response_v1/complete.json", - empty: "tests/data/products/energy_bill_fra/response_v1/empty.json", - docString: "tests/data/products/energy_bill_fra/response_v1/summary_full.rst", - page0String: "tests/data/products/energy_bill_fra/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "energy_bill_fra/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "energy_bill_fra/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "energy_bill_fra/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "energy_bill_fra/response_v1/summary_page0.rst"), }; -describe("EnergyBillV1 Object initialization", async () => { +describe("MindeeV1 - EnergyBillV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/fr/healthCard/healthCardV1.spec.ts b/tests/v1/product/fr/healthCard/healthCardV1.spec.ts index b09312ff..ef03a6a0 100644 --- a/tests/v1/product/fr/healthCard/healthCardV1.spec.ts +++ b/tests/v1/product/fr/healthCard/healthCardV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../../index"; import { expect } from "chai"; import * as mindee from "../../../../../src"; const dataPath = { - complete: "tests/data/products/french_healthcard/response_v1/complete.json", - empty: "tests/data/products/french_healthcard/response_v1/empty.json", - docString: "tests/data/products/french_healthcard/response_v1/summary_full.rst", - page0String: "tests/data/products/french_healthcard/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "french_healthcard/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "french_healthcard/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "french_healthcard/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "french_healthcard/response_v1/summary_page0.rst"), }; -describe("HealthCardV1 Object initialization", async () => { +describe("MindeeV1 - HealthCardV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/fr/idCard/idCardV1.spec.ts b/tests/v1/product/fr/idCard/idCardV1.spec.ts index 74c02a32..4c3b1443 100644 --- a/tests/v1/product/fr/idCard/idCardV1.spec.ts +++ b/tests/v1/product/fr/idCard/idCardV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../../index"; import { expect } from "chai"; import * as mindee from "../../../../../src"; const dataPath = { - complete: "tests/data/products/idcard_fr/response_v1/complete.json", - empty: "tests/data/products/idcard_fr/response_v1/empty.json", - docString: "tests/data/products/idcard_fr/response_v1/summary_full.rst", - page0String: "tests/data/products/idcard_fr/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "idcard_fr/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "idcard_fr/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "idcard_fr/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "idcard_fr/response_v1/summary_page0.rst"), }; -describe("IdCardV1 Object initialization", async () => { +describe("MindeeV1 - IdCardV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/fr/idCard/idCardV2.spec.ts b/tests/v1/product/fr/idCard/idCardV2.spec.ts index a43271a0..37e1d280 100644 --- a/tests/v1/product/fr/idCard/idCardV2.spec.ts +++ b/tests/v1/product/fr/idCard/idCardV2.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../../index"; import { expect } from "chai"; import * as mindee from "../../../../../src"; const dataPath = { - complete: "tests/data/products/idcard_fr/response_v2/complete.json", - empty: "tests/data/products/idcard_fr/response_v2/empty.json", - docString: "tests/data/products/idcard_fr/response_v2/summary_full.rst", - page0String: "tests/data/products/idcard_fr/response_v2/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "idcard_fr/response_v2/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "idcard_fr/response_v2/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "idcard_fr/response_v2/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "idcard_fr/response_v2/summary_page0.rst"), }; -describe("IdCardV2 Object initialization", async () => { +describe("MindeeV1 - IdCardV2 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/fr/payslip/payslipV2.spec.ts b/tests/v1/product/fr/payslip/payslipV2.spec.ts index c431a3b4..ef7c0576 100644 --- a/tests/v1/product/fr/payslip/payslipV2.spec.ts +++ b/tests/v1/product/fr/payslip/payslipV2.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../../index"; import { expect } from "chai"; import * as mindee from "../../../../../src"; const dataPath = { - complete: "tests/data/products/payslip_fra/response_v2/complete.json", - empty: "tests/data/products/payslip_fra/response_v2/empty.json", - docString: "tests/data/products/payslip_fra/response_v2/summary_full.rst", - page0String: "tests/data/products/payslip_fra/response_v2/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "payslip_fra/response_v2/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "payslip_fra/response_v2/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "payslip_fra/response_v2/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "payslip_fra/response_v2/summary_page0.rst"), }; -describe("PayslipV2 Object initialization", async () => { +describe("MindeeV1 - PayslipV2 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/fr/payslip/payslipV3.spec.ts b/tests/v1/product/fr/payslip/payslipV3.spec.ts index 1fcb2a4f..2ee0fb82 100644 --- a/tests/v1/product/fr/payslip/payslipV3.spec.ts +++ b/tests/v1/product/fr/payslip/payslipV3.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../../index"; import { expect } from "chai"; import * as mindee from "../../../../../src"; const dataPath = { - complete: "tests/data/products/payslip_fra/response_v3/complete.json", - empty: "tests/data/products/payslip_fra/response_v3/empty.json", - docString: "tests/data/products/payslip_fra/response_v3/summary_full.rst", - page0String: "tests/data/products/payslip_fra/response_v3/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "payslip_fra/response_v3/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "payslip_fra/response_v3/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "payslip_fra/response_v3/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "payslip_fra/response_v3/summary_page0.rst"), }; -describe("PayslipV3 Object initialization", async () => { +describe("MindeeV1 - PayslipV3 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/generated/generatedV1.spec.ts b/tests/v1/product/generated/generatedV1.spec.ts index 4746f78e..62a0a58b 100644 --- a/tests/v1/product/generated/generatedV1.spec.ts +++ b/tests/v1/product/generated/generatedV1.spec.ts @@ -7,27 +7,28 @@ import { GeneratedV1 } from "../../../../src/product"; import { GeneratedListField, GeneratedObjectField } from "../../../../src/parsing/generated"; import { GeneratedV1Page } from "../../../../src/product/generated/generatedV1Page"; import { StringField } from "../../../../src/parsing/standard"; +import { V1_PRODUCT_PATH } from "../../../index"; const dataPathInternationalId = { - complete: "tests/data/products/generated/response_v1/complete_international_id_v1.json", - empty: "tests/data/products/generated/response_v1/empty_international_id_v1.json", - docString: "tests/data/products/generated/response_v1/summary_full_international_id_v1.rst", - page0String: "tests/data/products/generated/response_v1/summary_page0_international_id_v1.rst", - emptyDocString: "tests/data/products/generated/response_v1/summary_empty_international_id_v1.rst" + complete: path.join(V1_PRODUCT_PATH, "generated/response_v1/complete_international_id_v1.json"), + empty: path.join(V1_PRODUCT_PATH, "generated/response_v1/empty_international_id_v1.json"), + docString: path.join(V1_PRODUCT_PATH, "generated/response_v1/summary_full_international_id_v1.rst"), + page0String: path.join(V1_PRODUCT_PATH, "generated/response_v1/summary_page0_international_id_v1.rst"), + emptyDocString: path.join(V1_PRODUCT_PATH, "generated/response_v1/summary_empty_international_id_v1.rst"), }; const dataPathInvoice = { - complete: "tests/data/products/generated/response_v1/complete_invoice_v4.json", - empty: "tests/data/products/generated/response_v1/empty_invoice_v4.json", - docString: "tests/data/products/generated/response_v1/summary_full_invoice_v4.rst", - page0String: "tests/data/products/generated/response_v1/summary_page0_invoice_v4.rst", - emptyDocString: "tests/data/products/generated/response_v1/summary_empty_invoice_v4.rst" + complete: path.join(V1_PRODUCT_PATH, "generated/response_v1/complete_invoice_v4.json"), + empty: path.join(V1_PRODUCT_PATH, "generated/response_v1/empty_invoice_v4.json"), + docString: path.join(V1_PRODUCT_PATH, "generated/response_v1/summary_full_invoice_v4.rst"), + page0String: path.join(V1_PRODUCT_PATH, "generated/response_v1/summary_page0_invoice_v4.rst"), + emptyDocString: path.join(V1_PRODUCT_PATH, "generated/response_v1/summary_empty_invoice_v4.rst"), }; describe("Generated Document Object initialization on an OTS invoice", async () => { it("should load an empty document prediction", async () => { - const jsonDataNA = await fs.readFile(path.resolve(dataPathInvoice.empty)); + const jsonDataNA = await fs.readFile(dataPathInvoice.empty); const response = JSON.parse(jsonDataNA.toString()); const doc = new mindee.Document(GeneratedV1, response.document); expect(doc.inference.prediction.fields.get("customer_address").value).to.be.undefined; @@ -81,8 +82,12 @@ describe("Generated Document Object initialization on an OTS invoice", async () 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("FR7640254025476501124705368"); - expect(page.prediction.fields.get("taxes").values[0].polygon.polygon).to.have.deep.members([[0.292, 0.749], [0.543, 0.749], [0.543, 0.763], [0.292, 0.763]]); + expect(page.prediction.fields.get("supplier_payment_details").values[0].iban).to.equals( + "FR7640254025476501124705368" + ); + expect(page.prediction.fields.get("taxes").values[0].polygon.polygon).to.have.deep.members( + [[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"); @@ -95,7 +100,9 @@ describe("Generated Document Object initialization on an OTS invoice", async () const jsonDataNA = await fs.readFile(path.resolve(dataPathInvoice.complete)); const response = JSON.parse(jsonDataNA.toString()); const doc = new mindee.Document(GeneratedV1, response.document); - expect(doc.inference.prediction.fields.get("customer_address").value).to.equals("1954 Bloon Street West Toronto, ON, M6P 3K9 Canada"); + expect(doc.inference.prediction.fields.get("customer_address").value).to.equals( + "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"); @@ -104,7 +111,9 @@ describe("Generated Document Object initialization on an OTS invoice", async () 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("S)BOIE 5X500 FEUILLES A4"); + expect(doc.inference.prediction.fields.get("line_items").values[0].description).to.equals( + "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; @@ -117,11 +126,17 @@ describe("Generated Document Object initialization on an OTS invoice", async () 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("156 University Ave, Toronto ON, Canada M5H 2H7"); + expect(doc.inference.prediction.fields.get("supplier_address").value).to.equals( + "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("FR7640254025476501124705368"); - expect(doc.inference.prediction.fields.get("taxes").values[0].polygon.polygon).to.have.deep.members([[0.292, 0.749], [0.543, 0.749], [0.543, 0.763], [0.292, 0.763]]); + expect(doc.inference.prediction.fields.get("supplier_payment_details").values[0].iban).to.equals( + "FR7640254025476501124705368" + ); + expect(doc.inference.prediction.fields.get("taxes").values[0].polygon.polygon).to.have.deep.members( + [[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"); diff --git a/tests/v1/product/ind/indianPassport/indianPassportV1.spec.ts b/tests/v1/product/ind/indianPassport/indianPassportV1.spec.ts index 2a77a7ca..0cd5be98 100644 --- a/tests/v1/product/ind/indianPassport/indianPassportV1.spec.ts +++ b/tests/v1/product/ind/indianPassport/indianPassportV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../../index"; import { expect } from "chai"; import * as mindee from "../../../../../src"; const dataPath = { - complete: "tests/data/products/ind_passport/response_v1/complete.json", - empty: "tests/data/products/ind_passport/response_v1/empty.json", - docString: "tests/data/products/ind_passport/response_v1/summary_full.rst", - page0String: "tests/data/products/ind_passport/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "ind_passport/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "ind_passport/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "ind_passport/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "ind_passport/response_v1/summary_page0.rst"), }; -describe("IndianPassportV1 Object initialization", async () => { +describe("MindeeV1 - IndianPassportV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/internationalId/internationalIdV2.spec.ts b/tests/v1/product/internationalId/internationalIdV2.spec.ts index 402b107f..921f778b 100644 --- a/tests/v1/product/internationalId/internationalIdV2.spec.ts +++ b/tests/v1/product/internationalId/internationalIdV2.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../index"; import { expect } from "chai"; import * as mindee from "../../../../src"; const dataPath = { - complete: "tests/data/products/international_id/response_v2/complete.json", - empty: "tests/data/products/international_id/response_v2/empty.json", - docString: "tests/data/products/international_id/response_v2/summary_full.rst", - page0String: "tests/data/products/international_id/response_v2/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "international_id/response_v2/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "international_id/response_v2/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "international_id/response_v2/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "international_id/response_v2/summary_page0.rst"), }; -describe("InternationalIdV2 Object initialization", async () => { +describe("MindeeV1 - InternationalIdV2 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/invoice/invoiceV4.spec.ts b/tests/v1/product/invoice/invoiceV4.spec.ts index d4488466..534c65f3 100644 --- a/tests/v1/product/invoice/invoiceV4.spec.ts +++ b/tests/v1/product/invoice/invoiceV4.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../index"; import { expect } from "chai"; import * as mindee from "../../../../src"; const dataPath = { - complete: "tests/data/products/invoices/response_v4/complete.json", - empty: "tests/data/products/invoices/response_v4/empty.json", - docString: "tests/data/products/invoices/response_v4/summary_full.rst", - page0String: "tests/data/products/invoices/response_v4/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "invoices/response_v4/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "invoices/response_v4/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "invoices/response_v4/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "invoices/response_v4/summary_page0.rst"), }; -describe("InvoiceV4 Object initialization", async () => { +describe("MindeeV1 - InvoiceV4 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/imageOperations/invoiceSplitter.integration.ts b/tests/v1/product/invoiceSplitter/invoiceSplitter.integration.ts similarity index 73% rename from tests/imageOperations/invoiceSplitter.integration.ts rename to tests/v1/product/invoiceSplitter/invoiceSplitter.integration.ts index 93141de2..a1042023 100644 --- a/tests/imageOperations/invoiceSplitter.integration.ts +++ b/tests/v1/product/invoiceSplitter/invoiceSplitter.integration.ts @@ -1,12 +1,12 @@ -import * as mindee from "../../src/"; -import { InvoiceSplitterV1 } from "../../src/product"; +import * as mindee from "../../../../src"; +import { InvoiceSplitterV1 } from "../../../../src/product"; import { expect } from "chai"; -import { levenshteinRatio } from "../testingUtilities"; +import { levenshteinRatio } from "../../../testingUtilities"; import { promises as fs } from "fs"; import path from "path"; -import { RESOURCE_PATH } from "../index"; +import { V1_PRODUCT_PATH } from "../../../index"; -describe("Given a PDF", async () => { +describe("MindeeV1 - InvoiceSplitterV1 Integration Tests", async () => { let client: mindee.Client; beforeEach(() => { @@ -15,7 +15,7 @@ describe("Given a PDF", async () => { it("should extract invoices in strict mode.", async () => { const sample = client.docFromPath( - path.join(RESOURCE_PATH, "products/invoice_splitter/default_sample.pdf") + path.join(V1_PRODUCT_PATH, "invoice_splitter/default_sample.pdf") ); await sample.init(); @@ -34,7 +34,7 @@ describe("Given a PDF", async () => { const invoiceResult = await client.parse(mindee.product.InvoiceV4, invoices[0].asSource()); const testStringRstInvoice = await fs.readFile( - path.join(RESOURCE_PATH, "products/invoices/response_v4/summary_full_invoice_p1.rst") + path.join(V1_PRODUCT_PATH, "invoices/response_v4/summary_full_invoice_p1.rst") ); expect( diff --git a/tests/v1/product/invoiceSplitter/invoiceSplitterV1.spec.ts b/tests/v1/product/invoiceSplitter/invoiceSplitterV1.spec.ts index da841773..42edc446 100644 --- a/tests/v1/product/invoiceSplitter/invoiceSplitterV1.spec.ts +++ b/tests/v1/product/invoiceSplitter/invoiceSplitterV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../index"; import { expect } from "chai"; import * as mindee from "../../../../src"; const dataPath = { - complete: "tests/data/products/invoice_splitter/response_v1/complete.json", - empty: "tests/data/products/invoice_splitter/response_v1/empty.json", - docString: "tests/data/products/invoice_splitter/response_v1/summary_full.rst", - page0String: "tests/data/products/invoice_splitter/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "invoice_splitter/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "invoice_splitter/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "invoice_splitter/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "invoice_splitter/response_v1/summary_page0.rst"), }; -describe("InvoiceSplitterV1 Object initialization", async () => { +describe("MindeeV1 - InvoiceSplitterV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/multiReceiptsDetector/multiReceiptsDetectorV1.spec.ts b/tests/v1/product/multiReceiptsDetector/multiReceiptsDetectorV1.spec.ts index e1c4d1ee..43f18e15 100644 --- a/tests/v1/product/multiReceiptsDetector/multiReceiptsDetectorV1.spec.ts +++ b/tests/v1/product/multiReceiptsDetector/multiReceiptsDetectorV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../index"; import { expect } from "chai"; import * as mindee from "../../../../src"; const dataPath = { - complete: "tests/data/products/multi_receipts_detector/response_v1/complete.json", - empty: "tests/data/products/multi_receipts_detector/response_v1/empty.json", - docString: "tests/data/products/multi_receipts_detector/response_v1/summary_full.rst", - page0String: "tests/data/products/multi_receipts_detector/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "multi_receipts_detector/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "multi_receipts_detector/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "multi_receipts_detector/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "multi_receipts_detector/response_v1/summary_page0.rst"), }; -describe("MultiReceiptsDetectorV1 Object initialization", async () => { +describe("MindeeV1 - MultiReceiptsDetectorV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/nutritionFactsLabel/nutritionFactsLabelV1.spec.ts b/tests/v1/product/nutritionFactsLabel/nutritionFactsLabelV1.spec.ts index 12200d39..3cb5a832 100644 --- a/tests/v1/product/nutritionFactsLabel/nutritionFactsLabelV1.spec.ts +++ b/tests/v1/product/nutritionFactsLabel/nutritionFactsLabelV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../index"; import { expect } from "chai"; import * as mindee from "../../../../src"; const dataPath = { - complete: "tests/data/products/nutrition_facts/response_v1/complete.json", - empty: "tests/data/products/nutrition_facts/response_v1/empty.json", - docString: "tests/data/products/nutrition_facts/response_v1/summary_full.rst", - page0String: "tests/data/products/nutrition_facts/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "nutrition_facts/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "nutrition_facts/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "nutrition_facts/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "nutrition_facts/response_v1/summary_page0.rst"), }; -describe("NutritionFactsLabelV1 Object initialization", async () => { +describe("MindeeV1 - NutritionFactsLabelV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/passport/passportV1.spec.ts b/tests/v1/product/passport/passportV1.spec.ts index 3c8f9feb..b9356f99 100644 --- a/tests/v1/product/passport/passportV1.spec.ts +++ b/tests/v1/product/passport/passportV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../index"; import { expect } from "chai"; import * as mindee from "../../../../src"; const dataPath = { - complete: "tests/data/products/passport/response_v1/complete.json", - empty: "tests/data/products/passport/response_v1/empty.json", - docString: "tests/data/products/passport/response_v1/summary_full.rst", - page0String: "tests/data/products/passport/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "passport/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "passport/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "passport/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "passport/response_v1/summary_page0.rst"), }; -describe("PassportV1 Object initialization", async () => { +describe("MindeeV1 - PassportV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/receipt/receiptV5.spec.ts b/tests/v1/product/receipt/receiptV5.spec.ts index 73596b5c..00196591 100644 --- a/tests/v1/product/receipt/receiptV5.spec.ts +++ b/tests/v1/product/receipt/receiptV5.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../index"; import { expect } from "chai"; import * as mindee from "../../../../src"; const dataPath = { - complete: "tests/data/products/expense_receipts/response_v5/complete.json", - empty: "tests/data/products/expense_receipts/response_v5/empty.json", - docString: "tests/data/products/expense_receipts/response_v5/summary_full.rst", - page0String: "tests/data/products/expense_receipts/response_v5/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "expense_receipts/response_v5/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "expense_receipts/response_v5/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "expense_receipts/response_v5/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "expense_receipts/response_v5/summary_page0.rst"), }; -describe("ReceiptV5 Object initialization", async () => { +describe("MindeeV1 - ReceiptV5 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/resume/resumeV1.spec.ts b/tests/v1/product/resume/resumeV1.spec.ts index 912da171..eefe0696 100644 --- a/tests/v1/product/resume/resumeV1.spec.ts +++ b/tests/v1/product/resume/resumeV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../index"; import { expect } from "chai"; import * as mindee from "../../../../src"; const dataPath = { - complete: "tests/data/products/resume/response_v1/complete.json", - empty: "tests/data/products/resume/response_v1/empty.json", - docString: "tests/data/products/resume/response_v1/summary_full.rst", - page0String: "tests/data/products/resume/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "resume/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "resume/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "resume/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "resume/response_v1/summary_page0.rst"), }; -describe("ResumeV1 Object initialization", async () => { +describe("MindeeV1 - ResumeV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/us/bankCheck/bankCheckV1.spec.ts b/tests/v1/product/us/bankCheck/bankCheckV1.spec.ts index f2a03ee6..7ae7d6d9 100644 --- a/tests/v1/product/us/bankCheck/bankCheckV1.spec.ts +++ b/tests/v1/product/us/bankCheck/bankCheckV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../../index"; import { expect } from "chai"; import * as mindee from "../../../../../src"; const dataPath = { - complete: "tests/data/products/bank_check/response_v1/complete.json", - empty: "tests/data/products/bank_check/response_v1/empty.json", - docString: "tests/data/products/bank_check/response_v1/summary_full.rst", - page0String: "tests/data/products/bank_check/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "bank_check/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "bank_check/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "bank_check/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "bank_check/response_v1/summary_page0.rst"), }; -describe("BankCheckV1 Object initialization", async () => { +describe("MindeeV1 - BankCheckV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/us/healthcareCard/healthcareCardV1.spec.ts b/tests/v1/product/us/healthcareCard/healthcareCardV1.spec.ts index 15435656..72c4c878 100644 --- a/tests/v1/product/us/healthcareCard/healthcareCardV1.spec.ts +++ b/tests/v1/product/us/healthcareCard/healthcareCardV1.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../../index"; import { expect } from "chai"; import * as mindee from "../../../../../src"; const dataPath = { - complete: "tests/data/products/us_healthcare_cards/response_v1/complete.json", - empty: "tests/data/products/us_healthcare_cards/response_v1/empty.json", - docString: "tests/data/products/us_healthcare_cards/response_v1/summary_full.rst", - page0String: "tests/data/products/us_healthcare_cards/response_v1/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "us_healthcare_cards/response_v1/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "us_healthcare_cards/response_v1/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "us_healthcare_cards/response_v1/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "us_healthcare_cards/response_v1/summary_page0.rst"), }; -describe("HealthcareCardV1 Object initialization", async () => { +describe("MindeeV1 - HealthcareCardV1 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/product/us/usMail/usMailV3.spec.ts b/tests/v1/product/us/usMail/usMailV3.spec.ts index 22b206a0..e1773db5 100644 --- a/tests/v1/product/us/usMail/usMailV3.spec.ts +++ b/tests/v1/product/us/usMail/usMailV3.spec.ts @@ -1,17 +1,18 @@ import { promises as fs } from "fs"; -import * as path from "path"; +import path from "path"; +import { V1_PRODUCT_PATH } from "../../../../index"; import { expect } from "chai"; import * as mindee from "../../../../../src"; const dataPath = { - complete: "tests/data/products/us_mail/response_v3/complete.json", - empty: "tests/data/products/us_mail/response_v3/empty.json", - docString: "tests/data/products/us_mail/response_v3/summary_full.rst", - page0String: "tests/data/products/us_mail/response_v3/summary_page0.rst", + complete: path.join(V1_PRODUCT_PATH, "us_mail/response_v3/complete.json"), + empty: path.join(V1_PRODUCT_PATH, "us_mail/response_v3/empty.json"), + docString: path.join(V1_PRODUCT_PATH, "us_mail/response_v3/summary_full.rst"), + page0String: path.join(V1_PRODUCT_PATH, "us_mail/response_v3/summary_page0.rst"), }; -describe("UsMailV3 Object initialization", async () => { +describe("MindeeV1 - UsMailV3 Object initialization", async () => { it("should load an empty document prediction", async () => { const jsonData = await fs.readFile(path.resolve(dataPath.empty)); const response = JSON.parse(jsonData.toString()); diff --git a/tests/v1/workflows/workflow.integration.ts b/tests/v1/workflows/workflow.integration.ts index 83bbf3d7..4a86729b 100644 --- a/tests/v1/workflows/workflow.integration.ts +++ b/tests/v1/workflows/workflow.integration.ts @@ -6,7 +6,7 @@ import { OptionalAsyncOptions } from "../../../src/client"; import { FinancialDocumentV1 } from "../../../src/product"; import { RAGExtra } from "../../../src/parsing/common/extras/ragExtra"; import path from "path"; -import { RESOURCE_PATH } from "../../index"; +import { V1_PRODUCT_PATH } from "../../index"; describe("MindeeV1 - Workflow calls", () => { let client: mindee.Client; @@ -17,7 +17,7 @@ describe("MindeeV1 - Workflow calls", () => { client = new mindee.Client(); workflowId = process.env["WORKFLOW_ID"] ?? ""; sample = client.docFromPath( - path.join(RESOURCE_PATH, "products/financial_document/default_sample.jpg") + path.join(V1_PRODUCT_PATH, "financial_document/default_sample.jpg") ); await sample.init(); }); diff --git a/tests/v2/clientV2.integration.ts b/tests/v2/clientV2.integration.ts index 5a5b7571..9e618b4f 100644 --- a/tests/v2/clientV2.integration.ts +++ b/tests/v2/clientV2.integration.ts @@ -13,26 +13,25 @@ import { Inference } from "../../src/parsing/v2"; import { SimpleField } from "../../src/parsing/v2/field"; import { MindeeHttpErrorV2 } from "../../src/errors/mindeeError"; import * as fs from "node:fs"; +import { RESOURCE_PATH, V2_PRODUCT_PATH } from "../index"; describe("MindeeV2 – Client Integration Tests", () => { let client: ClientV2; let modelId: string; - const dataDir = path.join(__dirname, "..", "data"); const emptyPdfPath = path.join( - dataDir, + RESOURCE_PATH, "file_types", "pdf", "multipage_cut-2.pdf", ); const sampleImagePath = path.join( - dataDir, - "products", + V2_PRODUCT_PATH, "financial_document", "default_sample.jpg", ); const sampleBase64Path = path.join( - dataDir, + RESOURCE_PATH, "file_types", "receipt.txt", ); diff --git a/tests/v2/input/localResponse.spec.ts b/tests/v2/input/localResponse.spec.ts new file mode 100644 index 00000000..ed83b9da --- /dev/null +++ b/tests/v2/input/localResponse.spec.ts @@ -0,0 +1,51 @@ +import * as fs from "node:fs/promises"; +import { expect } from "chai"; +import { InferenceResponse, LocalResponse } from "../../../src"; + +import path from "path"; +import { V2_RESOURCE_PATH } from "../../index"; + +const signature: string = "839dff294b71cb2c6972534d2c9c1d2684fd284f42a68891196612219046971c"; +const dummySecretKey: string = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH"; +const filePath: string = path.join(V2_RESOURCE_PATH, "inference/standard_field_types.json"); + +describe("MindeeV2 - Load Local Response", () => { + it("should load a string properly.", async () => { + 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; + }); + + 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; + }); + + it("should load a buffer properly.", async () => { + 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; + }); + + it("should deserialize a prediction.", async () => { + const fileObj = await fs.readFile(filePath, { encoding: "utf-8" }); + const localResponse = new LocalResponse(fileObj); + const response = await localResponse.deserializeResponse(InferenceResponse); + expect(response).to.be.an.instanceof(InferenceResponse); + + expect(JSON.stringify(response.getRawHttp())).to.eq(JSON.stringify(JSON.parse(fileObj))); + }); +});