#!/bin/bash
# Test ValidateMappingAgainstDB via the `import segments` CLI command
# Creates temporary .data files and mapping.json, then validates mapping errors
# Uses fresh copy of production DB in /tmp (auto-cleaned)
# Create fresh test database
DB_PATH=
SKRAAK="/skraak"
# Create test entities
DATASET_RESULT=
DATASET_ID=
if [; then
fi
LOCATION_RESULT=
LOCATION_ID=
if [; then
fi
CLUSTER_RESULT=
CLUSTER_ID=
if [; then
fi
# Import WAV files into the cluster first (segments require existing file records)
WAV_DIR="/tmp/skraak_map_test_"
IMPORT_COUNT=
if [; then
fi
# Helper: create a .data file for the test WAV
# Format: [meta, [start, end, freqLow, freqHigh, [labels]]]
# Labels have: species, certainty, filter
# Helper: run import segments and capture output
# -------------------------------------------------------
# Test 1: Valid mapping - species exists in DB
# -------------------------------------------------------
VALID_MAPPING="/tmp/skraak_valid_mapping_.json"
# This should pass mapping validation (may fail later for other reasons, but no mapping error)
RESULT=
if ! | ; then
|| ; ||
else
| |
|| ; ||
fi
# -------------------------------------------------------
# Test 2: Species in .data but not in mapping
# -------------------------------------------------------
INCOMPLETE_MAPPING="/tmp/skraak_incomplete_mapping_.json"
RESULT=
if | ; then
|| ; ||
else
|
|| ; ||
fi
# -------------------------------------------------------
# Test 3: Mapped species not found in DB
# -------------------------------------------------------
PHANTOM_MAPPING="/tmp/skraak_phantom_mapping_.json"
RESULT=
if | ; then
|| ; ||
else
|
|| ; ||
fi
# -------------------------------------------------------
# Test 4: Calltype not found in DB
# -------------------------------------------------------
BAD_CT_MAPPING="/tmp/skraak_bad_ct_mapping_.json"
RESULT=
if | ; then
|| ; ||
else
|
|| ; ||
fi
# -------------------------------------------------------
# Test 5: __NEGATIVE__ sentinel - should not error
# -------------------------------------------------------
NEG_MAPPING="/tmp/skraak_neg_mapping_.json"
RESULT=
# __NEGATIVE__ species are NOT looked up in DB, so no "mapped species not found" error
if ! | ; then
|| ; ||
else
|
|| ; ||
fi
# -------------------------------------------------------
# Test 6: __IGNORE__ sentinel - should not error
# -------------------------------------------------------
IGNORE_MAPPING="/tmp/skraak_ignore_mapping_.json"
RESULT=
if ! | ; then
|| ; ||
else
|
|| ; ||
fi
# Cleanup