diff --git a/.github/workflows/_test-units.yml b/.github/workflows/_test-units.yml index 5f40538a1..a78ce8de9 100644 --- a/.github/workflows/_test-units.yml +++ b/.github/workflows/_test-units.yml @@ -42,7 +42,9 @@ jobs: - name: Install Ghostscript and ImageMagick on macOS if: runner.os == 'macOS' - run: brew install ghostscript imagemagick + run: | + brew install ghostscript imagemagick + /usr/bin/security find-certificate -a -p /System/Library/Keychains/SystemRootCertificates.keychain - name: Change ImageMagick security policy on Ubuntu if: runner.os == 'Linux' run: | diff --git a/Rakefile b/Rakefile index a0c32bdbc..d91990c61 100644 --- a/Rakefile +++ b/Rakefile @@ -23,6 +23,7 @@ end desc 'Run integration tests' RSpec::Core::RakeTask.new(:integration) do |t| t.pattern = 'spec/**/*_integration.rb' + t.rspec_opts = ['--require', 'integration_helper'] end Rake::Task[:doc].enhance do diff --git a/lib/mindee/http/endpoint.rb b/lib/mindee/http/endpoint.rb index 8bb829530..3e8ffd46f 100644 --- a/lib/mindee/http/endpoint.rb +++ b/lib/mindee/http/endpoint.rb @@ -7,6 +7,7 @@ require_relative 'response_validation' module Mindee + # Mindee internal HTTP module. module HTTP # API key's default environment key name. API_KEY_ENV_NAME = 'MINDEE_API_KEY' diff --git a/mindee.gemspec b/mindee.gemspec index c041f23bd..eeba5d4e2 100644 --- a/mindee.gemspec +++ b/mindee.gemspec @@ -33,6 +33,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'origamindee', '~> 4.0' spec.add_dependency 'pdf-reader', '~> 2.14' + spec.add_development_dependency 'openssl', '~> 3.3.2' spec.add_development_dependency 'prism', '~> 1.3' spec.add_development_dependency 'rake', '~> 13.2' spec.add_development_dependency 'rbs', '~> 3.6' diff --git a/sig/mindee/http/endpoint.rbs b/sig/mindee/http/endpoint.rbs index 960b59cdf..09909126b 100644 --- a/sig/mindee/http/endpoint.rbs +++ b/sig/mindee/http/endpoint.rbs @@ -23,6 +23,7 @@ module Mindee def document_queue_req_post: (Input::Source::LocalInputSource | Input::Source::URLInputSource, ParseOptions) -> Net::HTTPResponse def document_queue_req_get: (String) -> Net::HTTPResponse def check_api_key: -> void + def configure_ssl: (Net::HTTP) -> void end end end diff --git a/spec/data b/spec/data index bc8356c1c..b0d725b71 160000 --- a/spec/data +++ b/spec/data @@ -1 +1 @@ -Subproject commit bc8356c1ce52d60351ed3430d336f33366025012 +Subproject commit b0d725b71784a45db611c325739320b6c192b7e5 diff --git a/spec/data.rb b/spec/data.rb index a785e501d..5b67c8ca1 100644 --- a/spec/data.rb +++ b/spec/data.rb @@ -1,6 +1,12 @@ # frozen_string_literal: true -DATA_DIR = File.join(__dir__, 'data').freeze +ROOT_DATA_DIR = File.join(__dir__, 'data').freeze +FILE_TYPES_DIR = File.join(ROOT_DATA_DIR, 'file_types').freeze +V1_DATA_DIR = File.join(ROOT_DATA_DIR, 'v1').freeze +V2_DATA_DIR = File.join(ROOT_DATA_DIR, 'v2').freeze +V1_ASYNC_DIR = File.join(V1_DATA_DIR, 'async').freeze +V1_PRODUCT_DATA_DIR = File.join(V1_DATA_DIR, 'products').freeze +V1_OCR_DIR = File.join(V1_DATA_DIR, 'extras', 'ocr') def load_json(dir_path, file_name) file_data = File.read(File.join(dir_path, file_name)) diff --git a/spec/extras/extras_utils.rb b/spec/extras/extras_utils.rb deleted file mode 100644 index 06a18d29c..000000000 --- a/spec/extras/extras_utils.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -require_relative '../data' - -EXTRAS_DIR = File.join(DATA_DIR, 'extras').freeze diff --git a/spec/image/extracted_image_spec.rb b/spec/image/extracted_image_spec.rb index d01d7d67c..7462ddca1 100644 --- a/spec/image/extracted_image_spec.rb +++ b/spec/image/extracted_image_spec.rb @@ -8,14 +8,14 @@ describe Mindee::Image::ExtractedImage do let(:file_path) do - File.join(DATA_DIR, 'products', 'invoices', 'default_sample.jpg') + File.join(V1_DATA_DIR, 'products', 'invoices', 'default_sample.jpg') end let(:input_source) do Mindee::Input::Source::PathInputSource.new(file_path) end let(:page_id) { 1 } let(:element_id) { 42 } - let(:output_dir) { "#{DATA_DIR}/output" } + let(:output_dir) { "#{ROOT_DATA_DIR}/output" } describe '#initialize' do it 'initializes with correct attributes' do diff --git a/spec/image/image_compressor_spec.rb b/spec/image/image_compressor_spec.rb index 81c1b1340..342dff085 100644 --- a/spec/image/image_compressor_spec.rb +++ b/spec/image/image_compressor_spec.rb @@ -6,8 +6,8 @@ describe Mindee::Image::ImageCompressor do describe 'Image Quality Compression' do - let(:input_receipt_path) { "#{DATA_DIR}/file_types/receipt.jpg" } - let(:output_dir) { "#{DATA_DIR}/output/" } + let(:input_receipt_path) { "#{FILE_TYPES_DIR}/receipt.jpg" } + let(:output_dir) { "#{ROOT_DATA_DIR}/output/" } it 'should compress the image from input source' do receipt_input = Mindee::Input::Source::PathInputSource.new(input_receipt_path) diff --git a/spec/image/image_extractor_spec.rb b/spec/image/image_extractor_spec.rb index 985159255..54b55e223 100644 --- a/spec/image/image_extractor_spec.rb +++ b/spec/image/image_extractor_spec.rb @@ -7,11 +7,11 @@ describe Mindee::Image do include Mindee::Image let(:barcode_path) do - File.join(DATA_DIR, 'products', 'barcode_reader', 'default_sample.jpg') + File.join(V1_DATA_DIR, 'products', 'barcode_reader', 'default_sample.jpg') end let(:barcode_json_path) do - File.join(DATA_DIR, 'products', 'barcode_reader', 'response_v1', 'complete.json') + File.join(V1_DATA_DIR, 'products', 'barcode_reader', 'response_v1', 'complete.json') end context 'an image extractor' do diff --git a/spec/image/image_utils_spec.rb b/spec/image/image_utils_spec.rb index 0fb7f27ae..0579770b8 100644 --- a/spec/image/image_utils_spec.rb +++ b/spec/image/image_utils_spec.rb @@ -6,7 +6,7 @@ require 'mindee' describe Mindee::Image::ImageUtils do - let(:sample_image_path) { "#{DATA_DIR}/file_types/receipt.jpg" } + let(:sample_image_path) { "#{FILE_TYPES_DIR}/receipt.jpg" } let(:sample_image) { MiniMagick::Image.open(sample_image_path) } describe 'Image utility module' do diff --git a/spec/input/sources/files_handling_spec.rb b/spec/input/sources/files_handling_spec.rb index 22b536469..fb5a5c100 100644 --- a/spec/input/sources/files_handling_spec.rb +++ b/spec/input/sources/files_handling_spec.rb @@ -7,7 +7,7 @@ describe Mindee::Input::Source::LocalInputSource do context 'An jpg input file' do it 'should be readable as raw bytes' do - file = File.join(DATA_DIR, 'file_types/receipt.jpg') + file = File.join(FILE_TYPES_DIR, 'receipt.jpg') input = Mindee::Input::Source::PathInputSource.new(file) read_f = input.read_contents expect(read_f.length).to eq(2) @@ -17,7 +17,7 @@ context 'A jpga input file' do it 'should be readable as raw bytes' do - file = File.join(DATA_DIR, 'file_types/receipt.jpga') + file = File.join(FILE_TYPES_DIR, 'receipt.jpga') input = Mindee::Input::Source::PathInputSource.new(file) read_f = input.read_contents expect(read_f.length).to eq(2) @@ -27,7 +27,7 @@ context 'A heic input file' do it 'should be readable as raw bytes' do - file = File.join(DATA_DIR, 'file_types/receipt.heic') + file = File.join(FILE_TYPES_DIR, 'receipt.heic') input = Mindee::Input::Source::PathInputSource.new(file) read_f = input.read_contents expect(read_f.length).to eq(2) @@ -37,7 +37,7 @@ context 'A tif input file' do it 'should be readable as raw bytes' do - file = File.join(DATA_DIR, 'file_types/receipt.tif') + file = File.join(FILE_TYPES_DIR, 'receipt.tif') input = Mindee::Input::Source::PathInputSource.new(file) read_f = input.read_contents expect(read_f.length).to eq(2) @@ -47,7 +47,7 @@ context 'A tiff input file' do it 'should be readable as raw bytes' do - file = File.join(DATA_DIR, 'file_types/receipt.tiff') + file = File.join(FILE_TYPES_DIR, 'receipt.tiff') input = Mindee::Input::Source::PathInputSource.new(file) read_f = input.read_contents expect(read_f.length).to eq(2) @@ -57,7 +57,7 @@ context 'A txt input file' do it 'should stay in base64' do - file = File.join(DATA_DIR, 'file_types/receipt.txt') + file = File.join(FILE_TYPES_DIR, 'receipt.txt') input = Mindee::Input::Source::Base64InputSource.new(File.read(file), 'receipt.txt') read_f = input.read_contents expect(read_f.length).to eq(2) @@ -67,7 +67,7 @@ context 'A standard pdf input file' do it 'should not be converted' do - file = File.join(DATA_DIR, 'file_types/pdf/not_blank_image_only.pdf') + file = File.join(FILE_TYPES_DIR, 'pdf/not_blank_image_only.pdf') input = Mindee::Input::Source::PathInputSource.new(file) read_f = input.read_contents file_contents = File.read(file) @@ -79,7 +79,7 @@ context 'A valid written pdf input file' do it 'should not be converted' do - file = File.join(DATA_DIR, 'file_types/pdf/valid_exported.pdf') + file = File.join(FILE_TYPES_DIR, 'pdf/valid_exported.pdf') input = Mindee::Input::Source::PathInputSource.new(file) read_f = input.read_contents file_contents = File.read(file) diff --git a/spec/input/sources/local_input_source_spec.rb b/spec/input/sources/local_input_source_spec.rb index 5a270e834..1144ab83e 100644 --- a/spec/input/sources/local_input_source_spec.rb +++ b/spec/input/sources/local_input_source_spec.rb @@ -3,8 +3,8 @@ require 'mindee' describe Mindee::Input::Source::PathInputSource do - let(:input_file) { "#{DATA_DIR}/products/invoices/default_sample.jpg" } - let(:output_dir) { "#{DATA_DIR}/output/" } + let(:input_file) { "#{V1_DATA_DIR}/products/invoices/default_sample.jpg" } + let(:output_dir) { "#{ROOT_DATA_DIR}/output/" } describe '#write_to_file' do let(:local_input_source) { described_class.new(input_file) } diff --git a/spec/input/sources/sources_spec.rb b/spec/input/sources/sources_spec.rb index fb31fabca..0611c0651 100644 --- a/spec/input/sources/sources_spec.rb +++ b/spec/input/sources/sources_spec.rb @@ -11,7 +11,7 @@ context 'An image input file' do it 'should load a JPEG from a path' do input_source = Mindee::Input::Source::PathInputSource.new( - File.join(DATA_DIR, 'file_types/receipt.jpg') + File.join(FILE_TYPES_DIR, 'receipt.jpg') ) expect(input_source.file_mimetype).to eq('image/jpeg') expect(input_source.filename).to eq('receipt.jpg') @@ -19,7 +19,7 @@ expect(input_source.pdf?).to eq(false) input_source = Mindee::Input::Source::PathInputSource.new( - File.join(DATA_DIR, 'file_types/receipt.jpga') + File.join(FILE_TYPES_DIR, 'receipt.jpga') ) expect(input_source.file_mimetype).to eq('image/jpeg') expect(input_source.filename).to eq('receipt.jpga') @@ -29,7 +29,7 @@ it 'should load a TIFF from a path' do input_source = Mindee::Input::Source::PathInputSource.new( - File.join(DATA_DIR, 'file_types/receipt.tif') + File.join(FILE_TYPES_DIR, 'receipt.tif') ) expect(input_source.file_mimetype).to eq('image/tiff') expect(input_source.filename).to eq('receipt.tif') @@ -37,7 +37,7 @@ expect(input_source.pdf?).to eq(false) input_source = Mindee::Input::Source::PathInputSource.new( - File.join(DATA_DIR, 'file_types/receipt.tiff') + File.join(FILE_TYPES_DIR, 'receipt.tiff') ) expect(input_source.file_mimetype).to eq('image/tiff') expect(input_source.filename).to eq('receipt.tiff') @@ -47,7 +47,7 @@ it 'should load a HEIC from a path' do input_source = Mindee::Input::Source::PathInputSource.new( - File.join(DATA_DIR, 'file_types/receipt.heic') + File.join(FILE_TYPES_DIR, 'receipt.heic') ) expect(input_source.file_mimetype).to eq('image/heic') expect(input_source.filename).to eq('receipt.heic') @@ -59,7 +59,7 @@ context 'A PDF input file' do it 'should load a multi-page PDF from a path' do input_source = Mindee::Input::Source::PathInputSource.new( - File.join(DATA_DIR, 'products/invoices/invoice.pdf') + File.join(V1_DATA_DIR, 'products/invoices/invoice.pdf') ) expect(input_source.file_mimetype).to eq('application/pdf') expect(input_source.filename).to eq('invoice.pdf') @@ -67,7 +67,7 @@ expect(input_source.pdf?).to eq(true) input_source = Mindee::Input::Source::PathInputSource.new( - File.join(DATA_DIR, 'products/invoices/invoice.pdf') + File.join(V1_DATA_DIR, 'products/invoices/invoice.pdf') ) expect(input_source.file_mimetype).to eq('application/pdf') expect(input_source.filename).to eq('invoice.pdf') @@ -75,7 +75,7 @@ expect(input_source.pdf?).to eq(true) input_source = Mindee::Input::Source::PathInputSource.new( - File.join(DATA_DIR, 'products/invoices/invoice_10p.pdf') + File.join(V1_DATA_DIR, 'products/invoices/invoice_10p.pdf') ) expect(input_source.file_mimetype).to eq('application/pdf') expect(input_source.filename).to eq('invoice_10p.pdf') @@ -89,7 +89,7 @@ it 'Should not raise a mime error' do expect do mindee_client.source_from_path( - "#{DATA_DIR}/file_types/pdf/broken_fixable.pdf", repair_pdf: true + "#{FILE_TYPES_DIR}/pdf/broken_fixable.pdf", repair_pdf: true ) end.not_to raise_error end @@ -100,7 +100,7 @@ it 'Should raise an error' do expect do mindee_client.source_from_path( - "#{DATA_DIR}/file_types/pdf/broken_unfixable.pdf", repair_pdf: true + "#{FILE_TYPES_DIR}/pdf/broken_unfixable.pdf", repair_pdf: true ) end.to raise_error Mindee::Errors::MindeePDFError end @@ -109,9 +109,9 @@ context 'A broken fixable invoice PDF' do mindee_client = Mindee::Client.new(api_key: 'invalid-api-key') it 'Should send correct results' do - source_doc_original = mindee_client.source_from_path("#{DATA_DIR}/products/invoices/invoice.pdf") + source_doc_original = mindee_client.source_from_path("#{V1_DATA_DIR}/products/invoices/invoice.pdf") expect do - source_doc_fixed = mindee_client.source_from_path("#{DATA_DIR}/file_types/pdf/broken_invoice.pdf", + source_doc_fixed = mindee_client.source_from_path("#{FILE_TYPES_DIR}/pdf/broken_invoice.pdf", repair_pdf: true) expect(source_doc_fixed.read_contents[0].to_s).to eq(source_doc_original.read_contents[0].to_s) end.not_to raise_error diff --git a/spec/input/sources/url_input_source_spec.rb b/spec/input/sources/url_input_source_spec.rb index 3a0db99c2..d2f1cb487 100644 --- a/spec/input/sources/url_input_source_spec.rb +++ b/spec/input/sources/url_input_source_spec.rb @@ -7,7 +7,7 @@ let(:valid_url) { 'https://validurl/some/file.jpg' } let(:valid_url_no_filename) { 'https://validurl/some/' } let(:invalid_url) { 'http://invalidurl/some/file.jpg' } - let(:output_dir) { "#{DATA_DIR}/output/" } + let(:output_dir) { "#{ROOT_DATA_DIR}/output/" } describe '#initialize' do context 'with valid URL' do diff --git a/spec/integration_helper.rb b/spec/integration_helper.rb new file mode 100644 index 000000000..5719e6fa3 --- /dev/null +++ b/spec/integration_helper.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +require_relative 'openssl_crl_workaround' diff --git a/spec/openssl_crl_workaround.rb b/spec/openssl_crl_workaround.rb new file mode 100644 index 000000000..e76e81fa1 --- /dev/null +++ b/spec/openssl_crl_workaround.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require 'openssl' + +params = OpenSSL::SSL::SSLContext::DEFAULT_PARAMS + +params[:verify_mode] = OpenSSL::SSL::VERIFY_PEER + +if params[:verify_flags] + params[:verify_flags] &= + ~(OpenSSL::X509::V_FLAG_CRL_CHECK_ALL | OpenSSL::X509::V_FLAG_CRL_CHECK) +end diff --git a/spec/pdf/extracted_pdf_spec.rb b/spec/pdf/extracted_pdf_spec.rb index 4056b3394..06a8ca4a4 100644 --- a/spec/pdf/extracted_pdf_spec.rb +++ b/spec/pdf/extracted_pdf_spec.rb @@ -3,11 +3,9 @@ require 'mindee' describe Mindee::PDF::PDFExtractor::ExtractedPDF do - let(:product_data_dir) { File.join(DATA_DIR, 'products') } - let(:output_dir) { File.join(DATA_DIR, 'output') } - let(:file_types_dir) { File.join(DATA_DIR, 'file_types') } - let(:valid_pdf_path) { "#{product_data_dir}/invoices/invoice.pdf" } - let(:invalid_pdf_path) { "#{file_types_dir}/receipt.txt" } + let(:output_dir) { File.join(V1_DATA_DIR, 'output') } + let(:valid_pdf_path) { "#{V1_PRODUCT_DATA_DIR}/invoices/invoice.pdf" } + let(:invalid_pdf_path) { "#{FILE_TYPES_DIR}/receipt.txt" } let(:output_path) { "#{output_dir}/sample_output.pdf" } before do diff --git a/spec/pdf/pdf_compressor_spec.rb b/spec/pdf/pdf_compressor_spec.rb index bb36d87cf..13f6ab588 100644 --- a/spec/pdf/pdf_compressor_spec.rb +++ b/spec/pdf/pdf_compressor_spec.rb @@ -7,40 +7,42 @@ describe Mindee::PDF::PDFCompressor do describe 'The PDF text detection method' do it 'should detect text pdf in a PDF file.' do - text_input = Mindee::Input::Source::PathInputSource.new("#{DATA_DIR}/file_types/pdf/multipage.pdf") + text_input = Mindee::Input::Source::PathInputSource.new("#{FILE_TYPES_DIR}/pdf/multipage.pdf") expect(Mindee::PDF::PDFTools.source_text?(text_input.io_stream)).to be(true) end it 'should not detect text pdf in an empty PDF file.' do no_text_input = Mindee::Input::Source::PathInputSource.new( - "#{DATA_DIR}/file_types/pdf/blank_1.pdf" + "#{FILE_TYPES_DIR}/pdf/blank_1.pdf" ) expect(Mindee::PDF::PDFTools.source_text?(no_text_input.io_stream)).to be(false) end it 'should not detect text pdf in an image file.' do - image_input = Mindee::Input::Source::PathInputSource.new("#{DATA_DIR}/file_types/receipt.jpg") + image_input = Mindee::Input::Source::PathInputSource.new("#{FILE_TYPES_DIR}/receipt.jpg") expect(Mindee::PDF::PDFTools.source_text?(image_input.io_stream)).to be(false) end end describe 'PDF compression' do it 'should compress from an input source' do - input_file_path = "#{DATA_DIR}/products/invoice_splitter/default_sample.pdf" - output_file_path = "#{DATA_DIR}/output/compress_indirect.pdf" - pdf_input = Mindee::Input::Source::PathInputSource.new("#{DATA_DIR}/products/invoice_splitter/default_sample.pdf") + input_file_path = "#{V1_DATA_DIR}/products/invoice_splitter/default_sample.pdf" + output_file_path = "#{ROOT_DATA_DIR}/output/compress_indirect.pdf" + pdf_input = Mindee::Input::Source::PathInputSource.new( + "#{V1_DATA_DIR}/products/invoice_splitter/default_sample.pdf" + ) pdf_input.compress!(quality: 50) File.write(output_file_path, pdf_input.io_stream.read) expect(File.size(output_file_path)).to be < File.size(input_file_path) end it 'should compress from the compressor' do - input_file_path = "#{DATA_DIR}/products/invoice_splitter/default_sample.pdf" + input_file_path = "#{V1_DATA_DIR}/products/invoice_splitter/default_sample.pdf" output_file_paths = { - 85 => "#{DATA_DIR}/output/compressed_direct_85.pdf", - 75 => "#{DATA_DIR}/output/compressed_direct_75.pdf", - 50 => "#{DATA_DIR}/output/compressed_direct_50.pdf", - 10 => "#{DATA_DIR}/output/compressed_direct_10.pdf", + 85 => "#{ROOT_DATA_DIR}/output/compressed_direct_85.pdf", + 75 => "#{ROOT_DATA_DIR}/output/compressed_direct_75.pdf", + 50 => "#{ROOT_DATA_DIR}/output/compressed_direct_50.pdf", + 10 => "#{ROOT_DATA_DIR}/output/compressed_direct_10.pdf", } pdf = File.open(input_file_path) output_file_paths.each_pair do |key, value| @@ -55,7 +57,7 @@ end after(:each) do - output_dir = "#{DATA_DIR}/output" + output_dir = "#{ROOT_DATA_DIR}/output" FileUtils.rm_f("#{output_dir}/compressed_direct_85.pdf") FileUtils.rm_f("#{output_dir}/compressed_direct_75.pdf") FileUtils.rm_f("#{output_dir}/compressed_direct_50.pdf") @@ -66,8 +68,8 @@ describe 'source text PDF compression' do it 'should compress if forced' do - input_file_path = "#{DATA_DIR}/file_types/pdf/multipage.pdf" - output_file_path = "#{DATA_DIR}/output/compress_with_text.pdf" + input_file_path = "#{FILE_TYPES_DIR}/pdf/multipage.pdf" + output_file_path = "#{ROOT_DATA_DIR}/output/compress_with_text.pdf" pdf_input = Mindee::Input::Source::PathInputSource.new(input_file_path) pdf_input.compress!(quality: 50, force_source_text: true, disable_source_text: false) File.write(output_file_path, pdf_input.io_stream.read) @@ -89,7 +91,7 @@ end after(:each) do - output_dir = "#{DATA_DIR}/output" + output_dir = "#{ROOT_DATA_DIR}/output" FileUtils.rm_f("#{output_dir}/compress_with_text.pdf") end end diff --git a/spec/pdf/pdf_extractor_spec.rb b/spec/pdf/pdf_extractor_spec.rb index 19c208e03..f640e8eae 100644 --- a/spec/pdf/pdf_extractor_spec.rb +++ b/spec/pdf/pdf_extractor_spec.rb @@ -3,10 +3,9 @@ require 'mindee' describe 'Invoice extraction' do - let(:product_data_dir) { File.join(DATA_DIR, 'products') } - let(:invoice_default_sample_path) { File.join(product_data_dir, 'invoices', 'default_sample.jpg') } - let(:invoice_splitter_5p_path) { File.join(product_data_dir, 'invoice_splitter', 'invoice_5p.pdf') } - let(:loaded_prediction_path) { File.join(product_data_dir, 'invoice_splitter', 'response_v1', 'complete.json') } + let(:invoice_default_sample_path) { File.join(V1_PRODUCT_DATA_DIR, 'invoices', 'default_sample.jpg') } + let(:invoice_splitter_5p_path) { File.join(V1_PRODUCT_DATA_DIR, 'invoice_splitter', 'invoice_5p.pdf') } + let(:loaded_prediction_path) { File.join(V1_PRODUCT_DATA_DIR, 'invoice_splitter', 'response_v1', 'complete.json') } let(:loaded_prediction) do dummy_client = Mindee::Client.new(api_key: 'dummy_key') diff --git a/spec/pdf/pdf_processor_spec.rb b/spec/pdf/pdf_processor_spec.rb index 63eda9b47..e4e2f8f23 100644 --- a/spec/pdf/pdf_processor_spec.rb +++ b/spec/pdf/pdf_processor_spec.rb @@ -12,7 +12,7 @@ def open_pdf(io_stream) end context 'A single page PDF' do - filepath = File.join(DATA_DIR, 'file_types/pdf/blank.pdf').freeze + filepath = File.join(FILE_TYPES_DIR, 'pdf/blank.pdf').freeze it 'Should grab the first page' do io_stream = File.open(filepath, 'rb') @@ -42,7 +42,7 @@ def open_pdf(io_stream) end context 'A multi-page PDF' do - filepath = File.join(DATA_DIR, 'file_types/pdf/multipage.pdf').freeze + filepath = File.join(FILE_TYPES_DIR, 'pdf/multipage.pdf').freeze it 'Should grab the first page' do io_stream = File.open(filepath, 'rb') diff --git a/spec/api_response_spec.rb b/spec/v1/api_response_spec.rb similarity index 78% rename from spec/api_response_spec.rb rename to spec/v1/api_response_spec.rb index f99979bce..ef744bb60 100644 --- a/spec/api_response_spec.rb +++ b/spec/v1/api_response_spec.rb @@ -2,14 +2,13 @@ require 'json' require 'mindee' -require_relative 'data' -DIR_PRODUCTS = File.join(DATA_DIR, 'products').freeze +require_relative '../data' describe Mindee::Parsing::Common::ApiResponse do context 'An Invoice document' do it 'should be properly created from an ApiResponse' do - response = load_json(DIR_PRODUCTS, 'invoices/response_v4/complete.json') - rst_response = read_file(DIR_PRODUCTS, 'invoices/response_v4/summary_full.rst') + response = load_json(V1_PRODUCT_DATA_DIR, 'invoices/response_v4/complete.json') + rst_response = read_file(V1_PRODUCT_DATA_DIR, 'invoices/response_v4/summary_full.rst') parsed_response = Mindee::Parsing::Common::ApiResponse.new(Mindee::Product::Invoice::InvoiceV4, response, response.to_s) expect(parsed_response.document.inference).to be_a Mindee::Product::Invoice::InvoiceV4 diff --git a/spec/async_rseponse_spec.rb b/spec/v1/async_rseponse_spec.rb similarity index 92% rename from spec/async_rseponse_spec.rb rename to spec/v1/async_rseponse_spec.rb index 92cc4d71a..9a264a57f 100644 --- a/spec/async_rseponse_spec.rb +++ b/spec/v1/async_rseponse_spec.rb @@ -2,15 +2,13 @@ require 'json' require 'mindee' -require_relative 'data' -require_relative 'http/mock_http_response' - -DIR_ASYNC = File.join(DATA_DIR, 'async').freeze +require_relative '../data' +require_relative '../http/mock_http_response' describe Mindee::Parsing::Common::ApiResponse do context 'An async request' do it 'should be able to be sent' do - response = load_json(DIR_ASYNC, 'post_success.json') + response = load_json(V1_ASYNC_DIR, 'post_success.json') fake_response = MockHTTPResponse.new('1.0', response['api_request']['status_code'].to_s, 'OK', JSON.generate(response)) expect(Mindee::HTTP::ResponseValidation.valid_async_response?(fake_response)).to eq(true) @@ -26,7 +24,7 @@ end it 'should not be able to be sent on incompatible endpoints' do - response = load_json(DIR_ASYNC, 'post_fail_forbidden.json') + response = load_json(V1_ASYNC_DIR, 'post_fail_forbidden.json') fake_response = MockHTTPResponse.new('1.0', response['api_request']['status_code'].to_s, 'NOT OK', JSON.generate(response)) expect(Mindee::HTTP::ResponseValidation.valid_async_response?(fake_response)).to eq(false) @@ -36,7 +34,7 @@ end it 'should be able to poll processing a queue' do - response = load_json(DIR_ASYNC, 'get_processing.json') + response = load_json(V1_ASYNC_DIR, 'get_processing.json') fake_response = MockHTTPResponse.new('1.0', response['api_request']['status_code'].to_s, 'OK', JSON.generate(response)) expect(Mindee::HTTP::ResponseValidation.valid_async_response?(fake_response)).to eq(true) @@ -52,7 +50,7 @@ end it 'should be able to poll a completed queue' do - response = load_json(DIR_ASYNC, 'get_completed.json') + response = load_json(V1_ASYNC_DIR, 'get_completed.json') fake_response = MockHTTPResponse.new('1.0', response['api_request']['status_code'].to_s, 'OK', JSON.generate(response)) expect(Mindee::HTTP::ResponseValidation.valid_async_response?(fake_response)).to eq(true) @@ -69,7 +67,7 @@ end it 'should retrieve a failed job' do - response = load_json(DIR_ASYNC, 'get_failed_job_error.json') + response = load_json(V1_ASYNC_DIR, 'get_failed_job_error.json') fake_response = MockHTTPResponse.new('1.0', response['api_request']['status_code'].to_s, 'NOT OK', JSON.generate(response)) expect(Mindee::HTTP::ResponseValidation.valid_async_response?(fake_response)).to eq(false) diff --git a/spec/client_spec.rb b/spec/v1/client_spec.rb similarity index 77% rename from spec/client_spec.rb rename to spec/v1/client_spec.rb index 1de4573c9..3b6e0caf0 100644 --- a/spec/client_spec.rb +++ b/spec/v1/client_spec.rb @@ -2,52 +2,52 @@ require 'mindee' -require_relative 'data' +require_relative '../data' describe Mindee::Client do context 'A client' do mindee_client = Mindee::Client.new(api_key: 'invalid-api-key') it 'should open PDF files from a path' do - input_source = mindee_client.source_from_path("#{DATA_DIR}/products/invoices/invoice.pdf") + input_source = mindee_client.source_from_path("#{V1_DATA_DIR}/products/invoices/invoice.pdf") expect(input_source).to respond_to(:read_contents) - input_source = mindee_client.source_from_path("#{DATA_DIR}/products/invoices/invoice_10p.pdf") + input_source = mindee_client.source_from_path("#{V1_DATA_DIR}/products/invoices/invoice_10p.pdf") expect(input_source).to respond_to(:read_contents) end it 'should open PDF files from a file handle' do - file = File.open("#{DATA_DIR}/products/invoices/invoice_10p.pdf", 'rb') + file = File.open("#{V1_DATA_DIR}/products/invoices/invoice_10p.pdf", 'rb') input_source = mindee_client.source_from_file(file, 'invoice_10p.pdf') expect(input_source).to respond_to(:read_contents) end it 'should open PDF files from raw bytes' do - file_data = File.binread("#{DATA_DIR}/products/invoices/invoice_10p.pdf") + file_data = File.binread("#{V1_DATA_DIR}/products/invoices/invoice_10p.pdf") input_source = mindee_client.source_from_bytes(file_data, 'invoice_10p.pdf') expect(input_source).to respond_to(:read_contents) end it 'should open PDF files from a base64 string' do - file_data = File.read("#{DATA_DIR}/products/invoices/invoice_10p.txt") + file_data = File.read("#{V1_DATA_DIR}/products/invoices/invoice_10p.txt") input_source = mindee_client.source_from_b64string(file_data, 'invoice_10p.txt') expect(input_source).to respond_to(:read_contents) end it 'should open JPG files from a path' do - input_source = mindee_client.source_from_path("#{DATA_DIR}/file_types/receipt.jpg") + input_source = mindee_client.source_from_path("#{FILE_TYPES_DIR}/receipt.jpg") expect(input_source).to respond_to(:read_contents) - input_source = mindee_client.source_from_path("#{DATA_DIR}/file_types/receipt.jpga") + input_source = mindee_client.source_from_path("#{FILE_TYPES_DIR}/receipt.jpga") expect(input_source).to respond_to(:read_contents) end it 'should open JPG files from a file handle' do - file = File.open("#{DATA_DIR}/file_types/receipt.jpg", 'rb') + file = File.open("#{FILE_TYPES_DIR}/receipt.jpg", 'rb') input_source = mindee_client.source_from_file(file, 'receipt.jpg') expect(input_source).to respond_to(:read_contents) end it 'should open JPG files from raw bytes' do - file_data = File.binread("#{DATA_DIR}/file_types/receipt.jpg") + file_data = File.binread("#{FILE_TYPES_DIR}/receipt.jpg") input_source = mindee_client.source_from_bytes(file_data, 'receipt.jpg') expect(input_source).to respond_to(:read_contents) end @@ -59,20 +59,20 @@ end it 'should load a local response' do - local_resp = Mindee::Input::LocalResponse.new("#{DATA_DIR}/products/invoices/response_v4/complete.json") + local_resp = Mindee::Input::LocalResponse.new("#{V1_DATA_DIR}/products/invoices/response_v4/complete.json") mindee_client.load_prediction(Mindee::Product::Invoice::InvoiceV4, local_resp) expect(mindee_client).to_not be_nil end it 'should not load an invalid local response' do - local_resp = Mindee::Input::LocalResponse.new("#{DATA_DIR}/geometry/polygon.json") + local_resp = Mindee::Input::LocalResponse.new("#{V1_DATA_DIR}/geometry/polygon.json") expect do mindee_client.load_prediction(Mindee::Product::Invoice::InvoiceV4, local_resp) end.to raise_error Mindee::Errors::MindeeInputError end it 'should not validate improper async parameters' do - file_data = File.binread("#{DATA_DIR}/file_types/receipt.jpg") + file_data = File.binread("#{FILE_TYPES_DIR}/receipt.jpg") input_source = mindee_client.source_from_bytes(file_data, 'receipt.jpg') expect do mindee_client.parse( diff --git a/spec/extraction/invoice_splitter_extraction_integration.rb b/spec/v1/extraction/invoice_splitter_extraction_integration.rb similarity index 80% rename from spec/extraction/invoice_splitter_extraction_integration.rb rename to spec/v1/extraction/invoice_splitter_extraction_integration.rb index 718d4ab9b..6414dac3d 100644 --- a/spec/extraction/invoice_splitter_extraction_integration.rb +++ b/spec/v1/extraction/invoice_splitter_extraction_integration.rb @@ -1,12 +1,11 @@ # frozen_string_literal: true require 'mindee' -require_relative '../data' -require_relative '../test_utilities' +require_relative '../../data' +require_relative '../../test_utilities' describe 'PDF Invoice Extraction (Strict Mode)' do - let(:product_data_dir) { File.join(DATA_DIR, 'products') } - let(:invoice_splitter_5p_path) { File.join(product_data_dir, 'invoice_splitter', 'invoice_5p.pdf') } + let(:invoice_splitter_5p_path) { File.join(V1_PRODUCT_DATA_DIR, 'invoice_splitter', 'invoice_5p.pdf') } def prepare_invoice_return(rst_file_path, invoice_prediction) rst_content = File.read(rst_file_path) @@ -22,7 +21,7 @@ def prepare_invoice_return(rst_file_path, invoice_prediction) it 'should extract invoices from a PDF (strict mode)' do client = Mindee::Client.new invoice_splitter_input = Mindee::Input::Source::PathInputSource.new( - File.join(product_data_dir, 'invoice_splitter', 'default_sample.pdf') + File.join(V1_PRODUCT_DATA_DIR, 'invoice_splitter', 'default_sample.pdf') ) response = client.parse( invoice_splitter_input, Mindee::Product::InvoiceSplitter::InvoiceSplitterV1, options: { close_file: false } @@ -41,7 +40,7 @@ def prepare_invoice_return(rst_file_path, invoice_prediction) invoice0 = client.parse(extracted_pdfs_strict[0].as_input_source, Mindee::Product::Invoice::InvoiceV4) test_string_rst_invoice0 = prepare_invoice_return( - File.join(product_data_dir, 'invoices', 'response_v4', 'summary_full_invoice_p1.rst'), + File.join(V1_PRODUCT_DATA_DIR, 'invoices', 'response_v4', 'summary_full_invoice_p1.rst'), invoice0.document ) diff --git a/spec/extraction/multi_receipts_extractor_spec.rb b/spec/v1/extraction/multi_receipts_extractor_spec.rb similarity index 94% rename from spec/extraction/multi_receipts_extractor_spec.rb rename to spec/v1/extraction/multi_receipts_extractor_spec.rb index b2da50949..345837b0b 100644 --- a/spec/extraction/multi_receipts_extractor_spec.rb +++ b/spec/v1/extraction/multi_receipts_extractor_spec.rb @@ -3,7 +3,7 @@ require 'mindee/product' require 'mindee/input/sources' require 'mindee/extraction' -require_relative '../data' +require_relative '../../data' describe 'multi-receipts extraction' do let(:empty_inference) do @@ -18,19 +18,19 @@ double('InputSource', count_pages: 0) end let(:multi_receipts_single_page_path) do - File.join(DATA_DIR, 'products', 'multi_receipts_detector', 'default_sample.jpg') + File.join(V1_DATA_DIR, 'products', 'multi_receipts_detector', 'default_sample.jpg') end let(:multi_receipts_single_page_json_path) do - File.join(DATA_DIR, 'products', 'multi_receipts_detector', 'response_v1') + File.join(V1_DATA_DIR, 'products', 'multi_receipts_detector', 'response_v1') end let(:multi_receipts_multi_page_path) do - File.join(DATA_DIR, 'products', 'multi_receipts_detector', 'multipage_sample.pdf') + File.join(V1_DATA_DIR, 'products', 'multi_receipts_detector', 'multipage_sample.pdf') end let(:multi_receipts_multi_page_json_path) do - File.join(DATA_DIR, 'products', 'multi_receipts_detector', 'response_v1') + File.join(V1_DATA_DIR, 'products', 'multi_receipts_detector', 'response_v1') end context 'with single page multi receipt' do diff --git a/spec/extras/cropper_extra_spec.rb b/spec/v1/extras/cropper_extra_spec.rb similarity index 100% rename from spec/extras/cropper_extra_spec.rb rename to spec/v1/extras/cropper_extra_spec.rb diff --git a/spec/extras/extras_integration.rb b/spec/v1/extras/extras_integration.rb similarity index 80% rename from spec/extras/extras_integration.rb rename to spec/v1/extras/extras_integration.rb index 415d4fb04..fa296ca8f 100644 --- a/spec/extras/extras_integration.rb +++ b/spec/v1/extras/extras_integration.rb @@ -3,11 +3,11 @@ require 'json' require 'mindee' require_relative 'extras_utils' -require_relative '../data' -require_relative '../test_utilities' +require_relative '../../data' +require_relative '../../test_utilities' describe 'cropper extra' do - let(:invoice_path) { File.join(DATA_DIR, 'products', 'invoices', 'default_sample.jpg') } + let(:invoice_path) { File.join(V1_DATA_DIR, 'products', 'invoices', 'default_sample.jpg') } let(:client) { Mindee::Client.new } it 'should send correctly' do cropper_extra = Mindee::Input::Source::PathInputSource.new( @@ -20,7 +20,7 @@ end describe 'Full Text OCR extra' do - let(:invoice_path) { File.join(DATA_DIR, 'products', 'invoices', 'default_sample.jpg') } + let(:invoice_path) { File.join(V1_DATA_DIR, 'products', 'invoices', 'default_sample.jpg') } let(:client) { Mindee::Client.new } it 'should send correctly' do full_text_ocr_input = Mindee::Input::Source::PathInputSource.new( diff --git a/spec/v1/extras/extras_utils.rb b/spec/v1/extras/extras_utils.rb new file mode 100644 index 000000000..25d40bc9b --- /dev/null +++ b/spec/v1/extras/extras_utils.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +require_relative '../../data' + +EXTRAS_DIR = File.join(V1_DATA_DIR, 'extras').freeze diff --git a/spec/extras/full_text_ocr_spec.rb b/spec/v1/extras/full_text_ocr_spec.rb similarity index 97% rename from spec/extras/full_text_ocr_spec.rb rename to spec/v1/extras/full_text_ocr_spec.rb index f2e6c6684..706c8e5c4 100644 --- a/spec/extras/full_text_ocr_spec.rb +++ b/spec/v1/extras/full_text_ocr_spec.rb @@ -25,7 +25,7 @@ end let(:load_invalid_document) do prediction_data = JSON.parse( - File.read(File.join(DIR_PRODUCTS, 'bank_statement_fr', 'response_v2', 'complete.json')) + File.read(File.join(V1_PRODUCT_DATA_DIR, 'bank_statement_fr', 'response_v2', 'complete.json')) ) Mindee::Parsing::Common::ApiResponse.new( Mindee::Product::FR::BankStatement::BankStatementV2, diff --git a/spec/http/endpoint_spec.rb b/spec/v1/http/endpoint_spec.rb similarity index 100% rename from spec/http/endpoint_spec.rb rename to spec/v1/http/endpoint_spec.rb diff --git a/spec/v1/http/error_handler_integration.rb b/spec/v1/http/error_handler_integration.rb new file mode 100644 index 000000000..d5761d1f8 --- /dev/null +++ b/spec/v1/http/error_handler_integration.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'mindee' +require 'json' +require_relative '../../http/mock_http_response' + +describe Mindee::HTTP::ErrorHandler do + context 'An HTTP call' do + it 'should make an invalid API sync parse call raising an exception' do + mindee_client1 = Mindee::Client.new(api_key: 'invalid-api-key') + file = File.open("#{FILE_TYPES_DIR}/receipt.jpg", 'rb') + input_source = mindee_client1.source_from_file(file, 'receipt.jpg') + doc_class = Mindee::Product::Receipt::ReceiptV5 + expect do + mindee_client1.parse(input_source, doc_class, options: { all_words: false, close_file: true }) + end.to raise_error Mindee::Errors::MindeeHTTPClientError + end + + it 'should make an invalid API async enqueue call raising an exception' do + mindee_client1 = Mindee::Client.new(api_key: 'invalid-api-key') + file = File.open("#{V1_DATA_DIR}/products/invoice_splitter/default_sample.pdf", 'rb') + input_source = mindee_client1.source_from_file(file, 'default_sample.pdf') + doc_class = Mindee::Product::Invoice::InvoiceV4 + expect do + mindee_client1.enqueue(input_source, doc_class) + end.to raise_error Mindee::Errors::MindeeHTTPClientError + end + + it 'should make an invalid API async parse call raising an exception' do + mindee_client1 = Mindee::Client.new(api_key: 'invalid-api-key') + doc_class = Mindee::Product::InvoiceSplitter::InvoiceSplitterV1 + expect do + mindee_client1.parse_queued('invalid-job-id', doc_class) + end.to raise_error Mindee::Errors::MindeeHTTPClientError + end + end +end diff --git a/spec/http/error_handler_spec.rb b/spec/v1/http/error_handler_spec.rb similarity index 67% rename from spec/http/error_handler_spec.rb rename to spec/v1/http/error_handler_spec.rb index 34a7462f2..17157fd80 100644 --- a/spec/http/error_handler_spec.rb +++ b/spec/v1/http/error_handler_spec.rb @@ -2,44 +2,16 @@ require 'mindee' require 'json' -require_relative 'mock_http_response' +require_relative '../../http/mock_http_response' describe Mindee::HTTP::ErrorHandler do context 'An HTTP call' do - it 'should make an invalid API sync parse call raising an exception' do - mindee_client1 = Mindee::Client.new(api_key: 'invalid-api-key') - file = File.open("#{DATA_DIR}/file_types/receipt.jpg", 'rb') - input_source = mindee_client1.source_from_file(file, 'receipt.jpg') - doc_class = Mindee::Product::Receipt::ReceiptV5 - expect do - mindee_client1.parse(input_source, doc_class, options: { all_words: false, close_file: true }) - end.to raise_error Mindee::Errors::MindeeHTTPClientError - end - - it 'should make an invalid API async enqueue call raising an exception' do - mindee_client1 = Mindee::Client.new(api_key: 'invalid-api-key') - file = File.open("#{DATA_DIR}/products/invoice_splitter/default_sample.pdf", 'rb') - input_source = mindee_client1.source_from_file(file, 'default_sample.pdf') - doc_class = Mindee::Product::Invoice::InvoiceV4 - expect do - mindee_client1.enqueue(input_source, doc_class) - end.to raise_error Mindee::Errors::MindeeHTTPClientError - end - - it 'should make an invalid API async parse call raising an exception' do - mindee_client1 = Mindee::Client.new(api_key: 'invalid-api-key') - doc_class = Mindee::Product::InvoiceSplitter::InvoiceSplitterV1 - expect do - mindee_client1.parse_queued('invalid-job-id', doc_class) - end.to raise_error Mindee::Errors::MindeeHTTPClientError - end - # NOTE: No reliable UT each HTTP error for ruby as the only semi-reliable http mock lib (Webmock) isn't compatible # with multipart/form-data yet # TODO: fix when this is patched: https://github.com/bblimke/webmock/pull/791 it 'should fail on a 400 response with object' do - file = File.read("#{DATA_DIR}/errors/error_400_no_details.json") + file = File.read("#{V1_DATA_DIR}/errors/error_400_no_details.json") error_obj = MockHTTPResponse.new('1.0', '400', 'Some scary message here', file) error400 = Mindee::HTTP::ErrorHandler.handle_error('dummy-url', error_obj) expect do @@ -52,7 +24,7 @@ end it 'should fail on a 401 response with object' do - file = File.read("#{DATA_DIR}/errors/error_401_invalid_token.json") + file = File.read("#{V1_DATA_DIR}/errors/error_401_invalid_token.json") error_obj = MockHTTPResponse.new('1.0', '401', 'Authorization required', file) error401 = Mindee::HTTP::ErrorHandler.handle_error('dummy-url', error_obj) expect do @@ -65,7 +37,7 @@ end it 'should fail on a 429 response with object' do - file = File.read("#{DATA_DIR}/errors/error_429_too_many_requests.json") + file = File.read("#{V1_DATA_DIR}/errors/error_429_too_many_requests.json") error_obj = MockHTTPResponse.new('1.0', '429', 'Too many requests', file) error429 = Mindee::HTTP::ErrorHandler.handle_error('dummy-url', error_obj) expect do @@ -78,7 +50,7 @@ end it 'should fail on a 500 response with object' do - file = File.read("#{DATA_DIR}/errors/error_500_inference_fail.json") + file = File.read("#{V1_DATA_DIR}/errors/error_500_inference_fail.json") error_obj = MockHTTPResponse.new('1.0', '500', 'Inference failed', file) error500 = Mindee::HTTP::ErrorHandler.handle_error('dummy-url', error_obj) expect do @@ -91,7 +63,7 @@ end it 'should fail on a 500 HTML response' do - file = File.read("#{DATA_DIR}/errors/error_50x.html") + file = File.read("#{V1_DATA_DIR}/errors/error_50x.html") error_obj = MockHTTPResponse.new('1.0', '500', '', file) error500 = Mindee::HTTP::ErrorHandler.handle_error('dummy-url', error_obj) expect do @@ -104,7 +76,7 @@ end it 'should fail on a 200 success but job failed' do - file = File.read("#{DATA_DIR}/async/get_failed_job_error.json") + file = File.read("#{V1_DATA_DIR}/async/get_failed_job_error.json") error_obj = MockHTTPResponse.new('1.0', '200', 'success', file) hashed_obj = JSON.parse(error_obj.body) expect(error_obj.code.to_i).to eq(200) diff --git a/spec/input/local_response_spec.rb b/spec/v1/input/local_response_spec.rb similarity index 95% rename from spec/input/local_response_spec.rb rename to spec/v1/input/local_response_spec.rb index 058973c21..abfad1a06 100644 --- a/spec/input/local_response_spec.rb +++ b/spec/v1/input/local_response_spec.rb @@ -1,13 +1,12 @@ # frozen_string_literal: true require 'mindee/input/local_response' - -require_relative '../data' +require_relative '../../data' dummy_secret_key = 'ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH' signature = '5ed1673e34421217a5dbfcad905ee62261a3dd66c442f3edd19302072bbf70d0' -FILE_PATH = File.join(DATA_DIR, 'async', 'get_completed_empty.json').freeze +FILE_PATH = File.join(V1_DATA_DIR, 'async', 'get_completed_empty.json').freeze describe Mindee::Input::LocalResponse do context 'A local response' do diff --git a/spec/input/sources/url_input_source_integration.rb b/spec/v1/input/sources/url_input_source_integration.rb similarity index 69% rename from spec/input/sources/url_input_source_integration.rb rename to spec/v1/input/sources/url_input_source_integration.rb index e66d137d3..230ee0356 100644 --- a/spec/input/sources/url_input_source_integration.rb +++ b/spec/v1/input/sources/url_input_source_integration.rb @@ -6,18 +6,18 @@ let(:client) { Mindee::Client.new(api_key: ENV.fetch('MINDEE_API_KEY')) } it 'retrieves response from a remote file' do - remote_input = Mindee::Input::Source::URLInputSource.new('https://github.com/mindee/client-lib-test-data/blob/main/products/invoice_splitter/invoice_5p.pdf?raw=true') + remote_input = Mindee::Input::Source::URLInputSource.new(ENV.fetch('MINDEE_V2_SE_TESTS_BLANK_PDF_URL')) local_input = remote_input.as_local_input_source - expect(local_input.filename).to eq('invoice_5p.pdf') + expect(local_input.filename).to eq('blank_1.pdf') result = client.parse(local_input, Mindee::Product::Invoice::InvoiceV4) - expect(result.document.n_pages).to eq(5) + expect(result.document.n_pages).to eq(1) end it 'streams with chunked transfer‐encoding without creating temp files' do remote_input = Mindee::Input::Source::URLInputSource - .new('https://upload.wikimedia.org/wikipedia/commons/1/1d/Blank_Page.pdf') + .new(ENV.fetch('MINDEE_V2_SE_TESTS_BLANK_PDF_URL')) allow(Tempfile).to receive(:new).and_call_original allow(Tempfile).to receive(:create).and_call_original diff --git a/spec/ocr_spec.rb b/spec/v1/ocr_spec.rb similarity index 71% rename from spec/ocr_spec.rb rename to spec/v1/ocr_spec.rb index 287439d8c..4119d0f89 100644 --- a/spec/ocr_spec.rb +++ b/spec/v1/ocr_spec.rb @@ -3,16 +3,14 @@ require 'json' require 'mindee/parsing' -require_relative 'data' - -DIR_OCR = File.join(DATA_DIR, 'extras', 'ocr') +require_relative '../data' describe Mindee::Parsing::Common do include Mindee::Parsing::Common context 'An OCR extraction' do - json_data = load_json(DIR_OCR, 'complete.json') + json_data = load_json(V1_OCR_DIR, 'complete.json') it 'should extract ocr data from a document' do - expected_text = read_file(DIR_OCR, 'ocr.txt') + expected_text = read_file(V1_OCR_DIR, 'ocr.txt') ocr = Mindee::Parsing::Common::OCR::OCR.new(json_data['document']['ocr']) expect(ocr.to_s).to eq(expected_text) expect(ocr.mvision_v1.pages[0].to_s).to eq(expected_text) diff --git a/spec/parsing/standard/date_field_spec.rb b/spec/v1/parsing/standard/date_field_spec.rb similarity index 100% rename from spec/parsing/standard/date_field_spec.rb rename to spec/v1/parsing/standard/date_field_spec.rb diff --git a/spec/parsing/standard/string_field_spec.rb b/spec/v1/parsing/standard/string_field_spec.rb similarity index 100% rename from spec/parsing/standard/string_field_spec.rb rename to spec/v1/parsing/standard/string_field_spec.rb diff --git a/spec/parsing/universal/universal_list_field_spec.rb b/spec/v1/parsing/universal/universal_list_field_spec.rb similarity index 100% rename from spec/parsing/universal/universal_list_field_spec.rb rename to spec/v1/parsing/universal/universal_list_field_spec.rb diff --git a/spec/parsing/universal/universal_object_field_spec.rb b/spec/v1/parsing/universal/universal_object_field_spec.rb similarity index 100% rename from spec/parsing/universal/universal_object_field_spec.rb rename to spec/v1/parsing/universal/universal_object_field_spec.rb diff --git a/spec/product/barcode_reader_v1_spec.rb b/spec/v1/product/barcode_reader_v1_spec.rb similarity index 87% rename from spec/product/barcode_reader_v1_spec.rb rename to spec/v1/product/barcode_reader_v1_spec.rb index c770b2e80..fa44de21d 100644 --- a/spec/product/barcode_reader_v1_spec.rb +++ b/spec/v1/product/barcode_reader_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../data' +require_relative '../../data' -DIR_BARCODE_READER_V1 = File.join(DATA_DIR, 'products', 'barcode_reader', 'response_v1').freeze +DIR_BARCODE_READER_V1 = File.join(V1_DATA_DIR, 'products', 'barcode_reader', 'response_v1').freeze describe Mindee::Product::BarcodeReader::BarcodeReaderV1 do context 'A Barcode Reader V1' do diff --git a/spec/product/bill_of_lading_v1_spec.rb b/spec/v1/product/bill_of_lading_v1_spec.rb similarity index 87% rename from spec/product/bill_of_lading_v1_spec.rb rename to spec/v1/product/bill_of_lading_v1_spec.rb index 7a2235f99..0d1683557 100644 --- a/spec/product/bill_of_lading_v1_spec.rb +++ b/spec/v1/product/bill_of_lading_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../data' +require_relative '../../data' -DIR_BILL_OF_LADING_V1 = File.join(DATA_DIR, 'products', 'bill_of_lading', 'response_v1').freeze +DIR_BILL_OF_LADING_V1 = File.join(V1_DATA_DIR, 'products', 'bill_of_lading', 'response_v1').freeze describe Mindee::Product::BillOfLading::BillOfLadingV1 do context 'A Bill of Lading V1' do diff --git a/spec/product/business_card_v1_spec.rb b/spec/v1/product/business_card_v1_spec.rb similarity index 88% rename from spec/product/business_card_v1_spec.rb rename to spec/v1/product/business_card_v1_spec.rb index b54e5bae9..afafb2e6f 100644 --- a/spec/product/business_card_v1_spec.rb +++ b/spec/v1/product/business_card_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../data' +require_relative '../../data' -DIR_BUSINESS_CARD_V1 = File.join(DATA_DIR, 'products', 'business_card', 'response_v1').freeze +DIR_BUSINESS_CARD_V1 = File.join(V1_DATA_DIR, 'products', 'business_card', 'response_v1').freeze describe Mindee::Product::BusinessCard::BusinessCardV1 do context 'A Business Card V1' do diff --git a/spec/product/cropper_v1_spec.rb b/spec/v1/product/cropper_v1_spec.rb similarity index 91% rename from spec/product/cropper_v1_spec.rb rename to spec/v1/product/cropper_v1_spec.rb index 7e2d66e99..bda490c3a 100644 --- a/spec/product/cropper_v1_spec.rb +++ b/spec/v1/product/cropper_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../data' +require_relative '../../data' -DIR_CROPPER_V1 = File.join(DATA_DIR, 'products', 'cropper', 'response_v1').freeze +DIR_CROPPER_V1 = File.join(V1_DATA_DIR, 'products', 'cropper', 'response_v1').freeze describe Mindee::Product::Cropper::CropperV1 do context 'A Cropper V1' do diff --git a/spec/product/delivery_note_v1_spec.rb b/spec/v1/product/delivery_note_v1_spec.rb similarity index 87% rename from spec/product/delivery_note_v1_spec.rb rename to spec/v1/product/delivery_note_v1_spec.rb index bfcaa4b83..329e92f16 100644 --- a/spec/product/delivery_note_v1_spec.rb +++ b/spec/v1/product/delivery_note_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../data' +require_relative '../../data' -DIR_DELIVERY_NOTE_V1 = File.join(DATA_DIR, 'products', 'delivery_notes', 'response_v1').freeze +DIR_DELIVERY_NOTE_V1 = File.join(V1_DATA_DIR, 'products', 'delivery_notes', 'response_v1').freeze describe Mindee::Product::DeliveryNote::DeliveryNoteV1 do context 'A Delivery note V1' do diff --git a/spec/product/driver_license_v1_spec.rb b/spec/v1/product/driver_license_v1_spec.rb similarity index 87% rename from spec/product/driver_license_v1_spec.rb rename to spec/v1/product/driver_license_v1_spec.rb index 1763ac5f0..40fd3d067 100644 --- a/spec/product/driver_license_v1_spec.rb +++ b/spec/v1/product/driver_license_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../data' +require_relative '../../data' -DIR_DRIVER_LICENSE_V1 = File.join(DATA_DIR, 'products', 'driver_license', 'response_v1').freeze +DIR_DRIVER_LICENSE_V1 = File.join(V1_DATA_DIR, 'products', 'driver_license', 'response_v1').freeze describe Mindee::Product::DriverLicense::DriverLicenseV1 do context 'A Driver License V1' do diff --git a/spec/product/financial_document_v1_spec.rb b/spec/v1/product/financial_document_v1_spec.rb similarity index 97% rename from spec/product/financial_document_v1_spec.rb rename to spec/v1/product/financial_document_v1_spec.rb index 1bd40bf57..ca83c7013 100644 --- a/spec/product/financial_document_v1_spec.rb +++ b/spec/v1/product/financial_document_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../data' +require_relative '../../data' -DIR_FINANCIAL_DOCUMENT_V1 = File.join(DATA_DIR, 'products', 'financial_document', 'response_v1').freeze +DIR_FINANCIAL_DOCUMENT_V1 = File.join(V1_DATA_DIR, 'products', 'financial_document', 'response_v1').freeze describe Mindee::Product::FinancialDocument::FinancialDocumentV1 do context 'A FinancialDocumentV1' do diff --git a/spec/product/fr/bank_account_details_v1_spec.rb b/spec/v1/product/fr/bank_account_details_v1_spec.rb similarity index 87% rename from spec/product/fr/bank_account_details_v1_spec.rb rename to spec/v1/product/fr/bank_account_details_v1_spec.rb index 14e8104ef..4266d9df9 100644 --- a/spec/product/fr/bank_account_details_v1_spec.rb +++ b/spec/v1/product/fr/bank_account_details_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../../data' +require_relative '../../../data' -DIR_FR_BANK_ACCOUNT_DETAILS_V1 = File.join(DATA_DIR, 'products', 'bank_account_details', 'response_v1').freeze +DIR_FR_BANK_ACCOUNT_DETAILS_V1 = File.join(V1_DATA_DIR, 'products', 'bank_account_details', 'response_v1').freeze describe Mindee::Product::FR::BankAccountDetails::BankAccountDetailsV1 do context 'A Bank Account Details V1' do diff --git a/spec/product/fr/bank_account_details_v2_spec.rb b/spec/v1/product/fr/bank_account_details_v2_spec.rb similarity index 87% rename from spec/product/fr/bank_account_details_v2_spec.rb rename to spec/v1/product/fr/bank_account_details_v2_spec.rb index 0744e43f6..15f9a2152 100644 --- a/spec/product/fr/bank_account_details_v2_spec.rb +++ b/spec/v1/product/fr/bank_account_details_v2_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../../data' +require_relative '../../../data' -DIR_FR_BANK_ACCOUNT_DETAILS_V2 = File.join(DATA_DIR, 'products', 'bank_account_details', 'response_v2').freeze +DIR_FR_BANK_ACCOUNT_DETAILS_V2 = File.join(V1_DATA_DIR, 'products', 'bank_account_details', 'response_v2').freeze describe Mindee::Product::FR::BankAccountDetails::BankAccountDetailsV2 do context 'A Bank Account Details V2' do diff --git a/spec/product/fr/bank_statement_v2_spec.rb b/spec/v1/product/fr/bank_statement_v2_spec.rb similarity index 87% rename from spec/product/fr/bank_statement_v2_spec.rb rename to spec/v1/product/fr/bank_statement_v2_spec.rb index 779f949cd..666b5ef5e 100644 --- a/spec/product/fr/bank_statement_v2_spec.rb +++ b/spec/v1/product/fr/bank_statement_v2_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../../data' +require_relative '../../../data' -DIR_FR_BANK_STATEMENT_V2 = File.join(DATA_DIR, 'products', 'bank_statement_fr', 'response_v2').freeze +DIR_FR_BANK_STATEMENT_V2 = File.join(V1_DATA_DIR, 'products', 'bank_statement_fr', 'response_v2').freeze describe Mindee::Product::FR::BankStatement::BankStatementV2 do context 'A Bank Statement V2' do diff --git a/spec/product/fr/carte_grise_v1_spec.rb b/spec/v1/product/fr/carte_grise_v1_spec.rb similarity index 87% rename from spec/product/fr/carte_grise_v1_spec.rb rename to spec/v1/product/fr/carte_grise_v1_spec.rb index 2739c7197..0a94ec5ed 100644 --- a/spec/product/fr/carte_grise_v1_spec.rb +++ b/spec/v1/product/fr/carte_grise_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../../data' +require_relative '../../../data' -DIR_FR_CARTE_GRISE_V1 = File.join(DATA_DIR, 'products', 'carte_grise', 'response_v1').freeze +DIR_FR_CARTE_GRISE_V1 = File.join(V1_DATA_DIR, 'products', 'carte_grise', 'response_v1').freeze describe Mindee::Product::FR::CarteGrise::CarteGriseV1 do context 'A Carte Grise V1' do diff --git a/spec/product/fr/energy_bill_v1_spec.rb b/spec/v1/product/fr/energy_bill_v1_spec.rb similarity index 87% rename from spec/product/fr/energy_bill_v1_spec.rb rename to spec/v1/product/fr/energy_bill_v1_spec.rb index 093847aea..ec9ae55bc 100644 --- a/spec/product/fr/energy_bill_v1_spec.rb +++ b/spec/v1/product/fr/energy_bill_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../../data' +require_relative '../../../data' -DIR_FR_ENERGY_BILL_V1 = File.join(DATA_DIR, 'products', 'energy_bill_fra', 'response_v1').freeze +DIR_FR_ENERGY_BILL_V1 = File.join(V1_DATA_DIR, 'products', 'energy_bill_fra', 'response_v1').freeze describe Mindee::Product::FR::EnergyBill::EnergyBillV1 do context 'A Energy Bill V1' do diff --git a/spec/product/fr/health_card_v1_spec.rb b/spec/v1/product/fr/health_card_v1_spec.rb similarity index 87% rename from spec/product/fr/health_card_v1_spec.rb rename to spec/v1/product/fr/health_card_v1_spec.rb index df39eb2ed..5add26748 100644 --- a/spec/product/fr/health_card_v1_spec.rb +++ b/spec/v1/product/fr/health_card_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../../data' +require_relative '../../../data' -DIR_FR_HEALTH_CARD_V1 = File.join(DATA_DIR, 'products', 'french_healthcard', 'response_v1').freeze +DIR_FR_HEALTH_CARD_V1 = File.join(V1_DATA_DIR, 'products', 'french_healthcard', 'response_v1').freeze describe Mindee::Product::FR::HealthCard::HealthCardV1 do context 'A Health Card V1' do diff --git a/spec/product/fr/id_card_v1_spec.rb b/spec/v1/product/fr/id_card_v1_spec.rb similarity index 91% rename from spec/product/fr/id_card_v1_spec.rb rename to spec/v1/product/fr/id_card_v1_spec.rb index 203fe28de..c73602e06 100644 --- a/spec/product/fr/id_card_v1_spec.rb +++ b/spec/v1/product/fr/id_card_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../../data' +require_relative '../../../data' -DIR_FR_ID_CARD_V1 = File.join(DATA_DIR, 'products', 'idcard_fr', 'response_v1').freeze +DIR_FR_ID_CARD_V1 = File.join(V1_DATA_DIR, 'products', 'idcard_fr', 'response_v1').freeze describe Mindee::Product::FR::IdCard::IdCardV1 do context 'A Carte Nationale d\'Identité V1' do diff --git a/spec/product/fr/id_card_v2_spec.rb b/spec/v1/product/fr/id_card_v2_spec.rb similarity index 91% rename from spec/product/fr/id_card_v2_spec.rb rename to spec/v1/product/fr/id_card_v2_spec.rb index 6fd6282a2..db44a18d8 100644 --- a/spec/product/fr/id_card_v2_spec.rb +++ b/spec/v1/product/fr/id_card_v2_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../../data' +require_relative '../../../data' -DIR_FR_ID_CARD_V2 = File.join(DATA_DIR, 'products', 'idcard_fr', 'response_v2').freeze +DIR_FR_ID_CARD_V2 = File.join(V1_DATA_DIR, 'products', 'idcard_fr', 'response_v2').freeze describe Mindee::Product::FR::IdCard::IdCardV2 do context 'A Carte Nationale d\'Identité V2' do diff --git a/spec/product/fr/payslip_v2_spec.rb b/spec/v1/product/fr/payslip_v2_spec.rb similarity index 87% rename from spec/product/fr/payslip_v2_spec.rb rename to spec/v1/product/fr/payslip_v2_spec.rb index cd843fdae..ef839cf04 100644 --- a/spec/product/fr/payslip_v2_spec.rb +++ b/spec/v1/product/fr/payslip_v2_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../../data' +require_relative '../../../data' -DIR_FR_PAYSLIP_V2 = File.join(DATA_DIR, 'products', 'payslip_fra', 'response_v2').freeze +DIR_FR_PAYSLIP_V2 = File.join(V1_DATA_DIR, 'products', 'payslip_fra', 'response_v2').freeze describe Mindee::Product::FR::Payslip::PayslipV2 do context 'A Payslip V2' do diff --git a/spec/product/fr/payslip_v3_spec.rb b/spec/v1/product/fr/payslip_v3_spec.rb similarity index 87% rename from spec/product/fr/payslip_v3_spec.rb rename to spec/v1/product/fr/payslip_v3_spec.rb index 073483826..a9d179562 100644 --- a/spec/product/fr/payslip_v3_spec.rb +++ b/spec/v1/product/fr/payslip_v3_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../../data' +require_relative '../../../data' -DIR_FR_PAYSLIP_V3 = File.join(DATA_DIR, 'products', 'payslip_fra', 'response_v3').freeze +DIR_FR_PAYSLIP_V3 = File.join(V1_DATA_DIR, 'products', 'payslip_fra', 'response_v3').freeze describe Mindee::Product::FR::Payslip::PayslipV3 do context 'A Payslip V3' do diff --git a/spec/product/ind/indian_passport_v1_spec.rb b/spec/v1/product/ind/indian_passport_v1_spec.rb similarity index 87% rename from spec/product/ind/indian_passport_v1_spec.rb rename to spec/v1/product/ind/indian_passport_v1_spec.rb index 6bd153a76..65d44bdd6 100644 --- a/spec/product/ind/indian_passport_v1_spec.rb +++ b/spec/v1/product/ind/indian_passport_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../../data' +require_relative '../../../data' -DIR_IND_INDIAN_PASSPORT_V1 = File.join(DATA_DIR, 'products', 'ind_passport', 'response_v1').freeze +DIR_IND_INDIAN_PASSPORT_V1 = File.join(V1_DATA_DIR, 'products', 'ind_passport', 'response_v1').freeze describe Mindee::Product::IND::IndianPassport::IndianPassportV1 do context 'A Passport - India V1' do diff --git a/spec/product/international_id_v2_spec.rb b/spec/v1/product/international_id_v2_spec.rb similarity index 87% rename from spec/product/international_id_v2_spec.rb rename to spec/v1/product/international_id_v2_spec.rb index b03e49f36..6e4e3bf7d 100644 --- a/spec/product/international_id_v2_spec.rb +++ b/spec/v1/product/international_id_v2_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../data' +require_relative '../../data' -DIR_INTERNATIONAL_ID_V2 = File.join(DATA_DIR, 'products', 'international_id', 'response_v2').freeze +DIR_INTERNATIONAL_ID_V2 = File.join(V1_DATA_DIR, 'products', 'international_id', 'response_v2').freeze describe Mindee::Product::InternationalId::InternationalIdV2 do context 'A International ID V2' do diff --git a/spec/product/invoice_splitter_v1_spec.rb b/spec/v1/product/invoice_splitter_v1_spec.rb similarity index 87% rename from spec/product/invoice_splitter_v1_spec.rb rename to spec/v1/product/invoice_splitter_v1_spec.rb index 36b3d53fe..2b9e889bd 100644 --- a/spec/product/invoice_splitter_v1_spec.rb +++ b/spec/v1/product/invoice_splitter_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../data' +require_relative '../../data' -DIR_INVOICE_SPLITTER_V1 = File.join(DATA_DIR, 'products', 'invoice_splitter', 'response_v1').freeze +DIR_INVOICE_SPLITTER_V1 = File.join(V1_DATA_DIR, 'products', 'invoice_splitter', 'response_v1').freeze describe Mindee::Product::InvoiceSplitter::InvoiceSplitterV1 do context 'A Invoice Splitter V1' do diff --git a/spec/product/invoice_v4_spec.rb b/spec/v1/product/invoice_v4_spec.rb similarity index 88% rename from spec/product/invoice_v4_spec.rb rename to spec/v1/product/invoice_v4_spec.rb index fe19dbf19..9c7278401 100644 --- a/spec/product/invoice_v4_spec.rb +++ b/spec/v1/product/invoice_v4_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../data' +require_relative '../../data' -DIR_INVOICE_V4 = File.join(DATA_DIR, 'products', 'invoices', 'response_v4').freeze +DIR_INVOICE_V4 = File.join(V1_DATA_DIR, 'products', 'invoices', 'response_v4').freeze describe Mindee::Product::Invoice::InvoiceV4 do context 'A Invoice V4' do diff --git a/spec/product/multi_receipts_detector_v1_spec.rb b/spec/v1/product/multi_receipts_detector_v1_spec.rb similarity index 87% rename from spec/product/multi_receipts_detector_v1_spec.rb rename to spec/v1/product/multi_receipts_detector_v1_spec.rb index b307f8657..dce0041ee 100644 --- a/spec/product/multi_receipts_detector_v1_spec.rb +++ b/spec/v1/product/multi_receipts_detector_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../data' +require_relative '../../data' -DIR_MULTI_RECEIPTS_DETECTOR_V1 = File.join(DATA_DIR, 'products', 'multi_receipts_detector', 'response_v1').freeze +DIR_MULTI_RECEIPTS_DETECTOR_V1 = File.join(V1_DATA_DIR, 'products', 'multi_receipts_detector', 'response_v1').freeze describe Mindee::Product::MultiReceiptsDetector::MultiReceiptsDetectorV1 do context 'A Multi Receipts Detector V1' do diff --git a/spec/product/nutrition_facts_label_v1_spec.rb b/spec/v1/product/nutrition_facts_label_v1_spec.rb similarity index 88% rename from spec/product/nutrition_facts_label_v1_spec.rb rename to spec/v1/product/nutrition_facts_label_v1_spec.rb index bc5de8133..910df0a99 100644 --- a/spec/product/nutrition_facts_label_v1_spec.rb +++ b/spec/v1/product/nutrition_facts_label_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../data' +require_relative '../../data' -DIR_NUTRITION_FACTS_LABEL_V1 = File.join(DATA_DIR, 'products', 'nutrition_facts', 'response_v1').freeze +DIR_NUTRITION_FACTS_LABEL_V1 = File.join(V1_DATA_DIR, 'products', 'nutrition_facts', 'response_v1').freeze describe Mindee::Product::NutritionFactsLabel::NutritionFactsLabelV1 do context 'A Nutrition Facts Label V1' do diff --git a/spec/product/passport_v1_spec.rb b/spec/v1/product/passport_v1_spec.rb similarity index 88% rename from spec/product/passport_v1_spec.rb rename to spec/v1/product/passport_v1_spec.rb index e74e2afdc..2bf0b5e4d 100644 --- a/spec/product/passport_v1_spec.rb +++ b/spec/v1/product/passport_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../data' +require_relative '../../data' -DIR_PASSPORT_V1 = File.join(DATA_DIR, 'products', 'passport', 'response_v1').freeze +DIR_PASSPORT_V1 = File.join(V1_DATA_DIR, 'products', 'passport', 'response_v1').freeze describe Mindee::Product::Passport::PassportV1 do context 'A Passport V1' do diff --git a/spec/product/receipt_v5_spec.rb b/spec/v1/product/receipt_v5_spec.rb similarity index 87% rename from spec/product/receipt_v5_spec.rb rename to spec/v1/product/receipt_v5_spec.rb index 06f7293e7..9153c5b79 100644 --- a/spec/product/receipt_v5_spec.rb +++ b/spec/v1/product/receipt_v5_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../data' +require_relative '../../data' -DIR_RECEIPT_V5 = File.join(DATA_DIR, 'products', 'expense_receipts', 'response_v5').freeze +DIR_RECEIPT_V5 = File.join(V1_DATA_DIR, 'products', 'expense_receipts', 'response_v5').freeze describe Mindee::Product::Receipt::ReceiptV5 do context 'A Receipt V5' do diff --git a/spec/product/resume_v1_spec.rb b/spec/v1/product/resume_v1_spec.rb similarity index 88% rename from spec/product/resume_v1_spec.rb rename to spec/v1/product/resume_v1_spec.rb index 97beadc2d..dce4c9b49 100644 --- a/spec/product/resume_v1_spec.rb +++ b/spec/v1/product/resume_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../data' +require_relative '../../data' -DIR_RESUME_V1 = File.join(DATA_DIR, 'products', 'resume', 'response_v1').freeze +DIR_RESUME_V1 = File.join(V1_DATA_DIR, 'products', 'resume', 'response_v1').freeze describe Mindee::Product::Resume::ResumeV1 do context 'A Resume V1' do diff --git a/spec/product/universal_spec.rb b/spec/v1/product/universal_spec.rb similarity index 97% rename from spec/product/universal_spec.rb rename to spec/v1/product/universal_spec.rb index 5430ed1af..99c39ad59 100644 --- a/spec/product/universal_spec.rb +++ b/spec/v1/product/universal_spec.rb @@ -3,7 +3,7 @@ require 'json' require 'mindee' -require_relative '../data' +require_relative '../../data' StringField = Mindee::Parsing::Standard.const_get(:StringField) PositionField = Mindee::Parsing::Standard.const_get(:PositionField) @@ -15,7 +15,7 @@ describe 'International ID v1 document' do let(:international_id_v1_complete_doc) do - parsed_file = JSON.parse(File.read(File.join(DATA_DIR, + parsed_file = JSON.parse(File.read(File.join(V1_DATA_DIR, 'products', 'generated', 'response_v1', @@ -25,7 +25,7 @@ end let(:international_id_v1_empty_doc) do - parsed_file = JSON.parse(File.read(File.join(DATA_DIR, + parsed_file = JSON.parse(File.read(File.join(V1_DATA_DIR, 'products', 'generated', 'response_v1', 'empty_international_id_v1.json'))) Document.new(Universal, @@ -33,12 +33,12 @@ end let(:international_id_v1_complete_doc_string) do - File.read(File.join(DATA_DIR, + File.read(File.join(V1_DATA_DIR, 'products', 'generated', 'response_v1', 'summary_full_international_id_v1.rst')) end let(:international_id_v1_empty_doc_string) do - File.read(File.join(DATA_DIR, + File.read(File.join(V1_DATA_DIR, 'products', 'generated', 'response_v1', 'summary_empty_international_id_v1.rst')) end @@ -232,7 +232,7 @@ describe 'Invoice V4 document' do let(:invoice_v4_complete_doc) do - parsed_file = JSON.parse(File.read(File.join(DATA_DIR, + parsed_file = JSON.parse(File.read(File.join(V1_DATA_DIR, 'products', 'generated', 'response_v1', @@ -241,7 +241,7 @@ parsed_file['document']) end let(:invoice_v4_page0_doc) do - parsed_file = JSON.parse(File.read(File.join(DATA_DIR, + parsed_file = JSON.parse(File.read(File.join(V1_DATA_DIR, 'products', 'generated', 'response_v1', @@ -250,7 +250,7 @@ end let(:invoice_v4_empty_doc) do - parsed_file = JSON.parse(File.read(File.join(DATA_DIR, + parsed_file = JSON.parse(File.read(File.join(V1_DATA_DIR, 'products', 'generated', 'response_v1', 'empty_invoice_v4.json'))) Document.new(Universal, @@ -258,16 +258,16 @@ end let(:invoice_v4_complete_doc_string) do - File.read(File.join(DATA_DIR, + File.read(File.join(V1_DATA_DIR, 'products', 'generated', 'response_v1', 'summary_full_invoice_v4.rst')) end let(:invoice_v4_page0_doc_string) do - File.read(File.join(DATA_DIR, + File.read(File.join(V1_DATA_DIR, 'products', 'generated', 'response_v1', 'summary_page0_invoice_v4.rst')) end let(:invoice_v4_empty_doc_string) do - File.read(File.join(DATA_DIR, + File.read(File.join(V1_DATA_DIR, 'products', 'generated', 'response_v1', 'summary_empty_invoice_v4.rst')) end describe 'Empty universal Invoice' do diff --git a/spec/product/us/bank_check_v1_spec.rb b/spec/v1/product/us/bank_check_v1_spec.rb similarity index 91% rename from spec/product/us/bank_check_v1_spec.rb rename to spec/v1/product/us/bank_check_v1_spec.rb index d5daebc99..a0d8cc97d 100644 --- a/spec/product/us/bank_check_v1_spec.rb +++ b/spec/v1/product/us/bank_check_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../../data' +require_relative '../../../data' -DIR_US_BANK_CHECK_V1 = File.join(DATA_DIR, 'products', 'bank_check', 'response_v1').freeze +DIR_US_BANK_CHECK_V1 = File.join(V1_DATA_DIR, 'products', 'bank_check', 'response_v1').freeze describe Mindee::Product::US::BankCheck::BankCheckV1 do context 'A Bank Check V1' do diff --git a/spec/product/us/healthcare_card_v1_spec.rb b/spec/v1/product/us/healthcare_card_v1_spec.rb similarity index 87% rename from spec/product/us/healthcare_card_v1_spec.rb rename to spec/v1/product/us/healthcare_card_v1_spec.rb index 7132e2941..f544aaec7 100644 --- a/spec/product/us/healthcare_card_v1_spec.rb +++ b/spec/v1/product/us/healthcare_card_v1_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../../data' +require_relative '../../../data' -DIR_US_HEALTHCARE_CARD_V1 = File.join(DATA_DIR, 'products', 'us_healthcare_cards', 'response_v1').freeze +DIR_US_HEALTHCARE_CARD_V1 = File.join(V1_DATA_DIR, 'products', 'us_healthcare_cards', 'response_v1').freeze describe Mindee::Product::US::HealthcareCard::HealthcareCardV1 do context 'A Healthcare Card V1' do diff --git a/spec/product/us/us_mail_v3_spec.rb b/spec/v1/product/us/us_mail_v3_spec.rb similarity index 88% rename from spec/product/us/us_mail_v3_spec.rb rename to spec/v1/product/us/us_mail_v3_spec.rb index bd9313981..6730c75ff 100644 --- a/spec/product/us/us_mail_v3_spec.rb +++ b/spec/v1/product/us/us_mail_v3_spec.rb @@ -4,9 +4,9 @@ require 'mindee/product' require 'mindee/parsing' -require_relative '../../data' +require_relative '../../../data' -DIR_US_US_MAIL_V3 = File.join(DATA_DIR, 'products', 'us_mail', 'response_v3').freeze +DIR_US_US_MAIL_V3 = File.join(V1_DATA_DIR, 'products', 'us_mail', 'response_v3').freeze describe Mindee::Product::US::UsMail::UsMailV3 do context 'A US Mail V3' do diff --git a/spec/workflow/workflow_integration.rb b/spec/v1/workflow/workflow_integration.rb similarity index 90% rename from spec/workflow/workflow_integration.rb rename to spec/v1/workflow/workflow_integration.rb index f494e7d6b..6bbe76a35 100644 --- a/spec/workflow/workflow_integration.rb +++ b/spec/v1/workflow/workflow_integration.rb @@ -2,15 +2,14 @@ require 'json' require 'mindee' -require_relative '../data' +require_relative '../../data' describe Mindee::Client do describe 'execute_workflow call to API' do - let(:product_data_dir) { File.join(DATA_DIR, 'products') } let(:client) { Mindee::Client.new } let(:sample_input) do Mindee::Input::Source::PathInputSource.new( - File.join(product_data_dir, 'financial_document', 'default_sample.jpg') + File.join(V1_PRODUCT_DATA_DIR, 'financial_document', 'default_sample.jpg') ) end let(:workflow_id) { ENV.fetch('WORKFLOW_ID') } diff --git a/spec/workflow/workflow_spec.rb b/spec/v1/workflow/workflow_spec.rb similarity index 95% rename from spec/workflow/workflow_spec.rb rename to spec/v1/workflow/workflow_spec.rb index 4655e9d00..f05ae4cde 100644 --- a/spec/workflow/workflow_spec.rb +++ b/spec/v1/workflow/workflow_spec.rb @@ -2,12 +2,12 @@ require 'json' require 'mindee' -require_relative '../data' +require_relative '../../data' describe Mindee::Client do describe 'execute_workflow' do it 'should deserialize response correctly when sending a document to an execution' do - json_file_path = "#{DATA_DIR}/workflows/success.json" + json_file_path = "#{V1_DATA_DIR}/workflows/success.json" mock_response = JSON.parse(File.read(json_file_path)) mocked_response = MockHTTPResponse.new('1.0', '202', 'OK', JSON.generate(mock_response)) @@ -39,7 +39,7 @@ end it 'should deserialize response correctly when sending a document to an execution with priority and alias' do - json_file_path = "#{DATA_DIR}/workflows/success_low_priority.json" + json_file_path = "#{V1_DATA_DIR}/workflows/success_low_priority.json" mock_response = JSON.parse(File.read(json_file_path)) mocked_response = MockHTTPResponse.new('1.0', '200', 'OK', JSON.generate(mock_response)) diff --git a/spec/client_v2_integration.rb b/spec/v2/client_v2_integration.rb similarity index 93% rename from spec/client_v2_integration.rb rename to spec/v2/client_v2_integration.rb index cd25a32e7..2b65c09af 100644 --- a/spec/client_v2_integration.rb +++ b/spec/v2/client_v2_integration.rb @@ -8,7 +8,7 @@ let(:client) { Mindee::ClientV2.new(api_key: api_key) } it 'parses an empty multi-page PDF successfully' do - src_path = File.join(__dir__ || './', 'data', 'file_types', 'pdf', 'multipage_cut-2.pdf') + src_path = File.join(FILE_TYPES_DIR, 'pdf', 'multipage_cut-2.pdf') input = Mindee::Input::Source::FileInputSource.new(File.open(src_path, 'rb'), 'multipage_cut-2.pdf') polling = Mindee::Input::PollingOptions.new( @@ -61,7 +61,7 @@ end it 'parses a filled single-page image successfully' do - src_path = File.join(__dir__ || './', 'data', 'products', 'financial_document', 'default_sample.jpg') + src_path = File.join(V1_PRODUCT_DATA_DIR, 'financial_document', 'default_sample.jpg') input = Mindee::Input::Source::FileInputSource.new(File.open(src_path, 'rb'), 'default_sample.jpg') params = Mindee::Input::InferenceParameters.new( @@ -107,7 +107,7 @@ end it 'raises MindeeHTTPErrorV2 (422) on invalid model id' do - src_path = File.join(__dir__ || './', 'data', 'file_types', 'pdf', 'blank_1.pdf') + src_path = File.join(FILE_TYPES_DIR, 'pdf', 'blank_1.pdf') input = Mindee::Input::Source::FileInputSource.new(File.open(src_path, 'rb'), 'blank_1.pdf') params = Mindee::Input::InferenceParameters.new('INVALID_MODEL_ID') @@ -118,7 +118,7 @@ end it 'raises MindeeHTTPErrorV2 (422) on invalid webhook id' do - src_path = File.join(__dir__ || './', 'data', 'file_types', 'pdf', 'blank_1.pdf') + src_path = File.join(FILE_TYPES_DIR, 'pdf', 'blank_1.pdf') input = Mindee::Input::Source::FileInputSource.new(File.open(src_path, 'rb'), 'blank_1.pdf') params = Mindee::Input::InferenceParameters.new(model_id, diff --git a/spec/client_v2_spec.rb b/spec/v2/client_v2_spec.rb similarity index 89% rename from spec/client_v2_spec.rb rename to spec/v2/client_v2_spec.rb index 65c6209dc..953e3e8d6 100644 --- a/spec/client_v2_spec.rb +++ b/spec/v2/client_v2_spec.rb @@ -2,12 +2,10 @@ require 'json' require 'mindee' -require_relative 'http/mock_http_response' # <- the original helper +require_relative '../http/mock_http_response' # <- the original helper RSpec.describe Mindee::ClientV2 do - let(:file_types_dir) { File.join(__dir__ || './', 'data', 'file_types') } - let(:v2_data_dir) { File.join(__dir__ || './', 'data', 'v2') } - let(:input_doc) { Mindee::Input::Source::PathInputSource.new(File.join(file_types_dir, 'pdf', 'blank.pdf')) } + let(:input_doc) { Mindee::Input::Source::PathInputSource.new(File.join(FILE_TYPES_DIR, 'pdf', 'blank.pdf')) } let(:base_url) { 'https://dummy-url' } let(:api_key) { 'dummy-api-key' } @@ -77,7 +75,7 @@ def stub_next_request_with(method, hash:, status_code: 0) end it 'get_job(job_id) returns a fully-formed JobResponse' do - json_path = File.join(v2_data_dir, 'job', 'ok_processing.json') + json_path = File.join(V2_DATA_DIR, 'job', 'ok_processing.json') parsed = File.read(json_path) stub_next_request_with(:inference_job_req_get, hash: parsed, status_code: 200) diff --git a/spec/parsing/v2/inference_spec.rb b/spec/v2/parsing/inference_spec.rb similarity index 98% rename from spec/parsing/v2/inference_spec.rb rename to spec/v2/parsing/inference_spec.rb index 79f656bc3..a53c3e00b 100644 --- a/spec/parsing/v2/inference_spec.rb +++ b/spec/v2/parsing/inference_spec.rb @@ -3,9 +3,8 @@ require 'mindee' RSpec.describe 'inference' do - let(:v2_data_dir) { File.join(DATA_DIR, 'v2') } - let(:findoc_path) { File.join(v2_data_dir, 'products', 'financial_document') } - let(:inference_path) { File.join(v2_data_dir, 'inference') } + let(:findoc_path) { File.join(V2_DATA_DIR, 'products', 'financial_document') } + let(:inference_path) { File.join(V2_DATA_DIR, 'inference') } let(:deep_nested_field_path) { File.join(inference_path, 'deep_nested_fields.json') } let(:standard_field_path) { File.join(inference_path, 'standard_field_types.json') } let(:standard_field_rst_path) { File.join(inference_path, 'standard_field_types.rst') }