Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/_test-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ env:
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}
MINDEE_V2_SE_TESTS_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }}
MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}
MINDEE_V2_SE_TESTS_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }}

jobs:
test:
Expand Down
10 changes: 7 additions & 3 deletions bin/v2/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ def init_product_parser
options_parser.on('-a ALIAS', '--alias ALIAS', 'Add a file alias to the response') do |v|
@options[:alias] = v
end
options_parser.on('-w WEBHOOK_ID', '--webhook-id WEBHOOK_ID',
'Specify a webhook by ID. May be used multiple times.') do |v|
(@options[:webhook_ids] ||= []) << v
end
init_common_options(options_parser)
options_parser.on('-F', '--fix-pdf', 'Attempt to repair PDF before enqueueing') do
@options[:repair_pdf] = true
Expand All @@ -190,10 +194,10 @@ def init_product_parser
end

# @return [Hash]
def setup_product_params
def setup_product_params(product_command)
params = { model_id: @options[:model_id] }
@options.each_pair do |key, value|
params[key] = value if V2_PRODUCTS['extraction'].include?(key)
params[key] = value if V2_PRODUCTS[product_command].include?(key) || %i[alias webhook_ids].include?(key)
end
params
end
Expand All @@ -205,7 +209,7 @@ def send(product_command, options)
mindee_client = Mindee::V2::Client.new(api_key: options[:api_key])
response_class = V2_PRODUCTS[product_command][:response_class]
input_source = setup_input_source(options)
params = setup_product_params
params = setup_product_params(product_command)

mindee_client.enqueue_and_get_result(
response_class,
Expand Down
29 changes: 19 additions & 10 deletions spec/test_v2_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export PATH="$HOME/.rbenv/bin:$PATH"
eval "$($HOME/.rbenv/bin/rbenv init -)"

if [ -z "$TEST_FILE" ]; then
echo "Error: no sample file provided"
exit 1
TEST_FILE='./spec/data/file_types/pdf/blank_1.pdf'
fi
echo "TEST_FILE: ${TEST_FILE}"

if [ -z "$RID" ]; then
OS_NAME="$(uname -s)"
Expand Down Expand Up @@ -44,11 +44,20 @@ else
echo "Models retrieval OK"
fi

echo "--- Test extraction with no additional args"
SUMMARY_OUTPUT=$("$CLI_PATH" extraction -m "$MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID" "$TEST_FILE")
if [ -z "$SUMMARY_OUTPUT" ]; then
echo "Error: no extraction output"
exit 1
else
echo "Extraction retrieval OK"
fi
run_test() {
model_id="$1"
model_type="$2"

echo "--- Test $model_type ID: $model_id"
SUMMARY_OUTPUT=$("$CLI_PATH" "$model_type" -m "$model_id" -a "ruby-sdk-cli-${model_type}" "$TEST_FILE")
echo "$SUMMARY_OUTPUT"
echo ""
echo ""
sleep 0.5
}

run_test "$MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID" "extraction"
run_test "$MINDEE_V2_SE_TESTS_CROP_MODEL_ID" "crop"
run_test "$MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID" "split"
run_test "$MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID" "classification"
run_test "$MINDEE_V2_SE_TESTS_OCR_MODEL_ID" "ocr"
Loading