# Media Importer Test Plan

## Purpose
This test plan ensures the reliability and correctness of `media-importer.sh` by covering key scenarios and edge cases.

## Test Areas
1. **Basic Functionality**
   - Organize media files by date using all supported organization patterns (`y`, `m`, `d`, `h`).
   - Move and copy modes (with and without `--keep-originals`).
   - Dry run mode (`--dry-run`).

2. **Source and Destination Handling**
   - Single and multiple source patterns (folders, globs, files).
   - Destination folder creation and error handling.
   - Exclusion of destination from source search.
   - Symlinked source directories.

3. **Error Handling**
   - Missing or invalid organization pattern.
   - Missing required dependencies (e.g., exiftool).
   - Unwritable destination directory.
   - Files with no EXIF/media date metadata (should be skipped or collected as unsortable).
   - Fatal errors (e.g., cannot generate destination path).
   - Recoverable errors (e.g., failed copy/move).

4. **Performance and Edge Cases**
   - Large number of files (10k+).
   - Files with conflicting names (should be renamed).
   - Mixed media types and extensions.
   - Files with unusual or missing extensions.

5. **Reporting**
   - Correct summary of processed, skipped, and error files.
   - Accurate size and speed reporting.
   - Verbose and non-verbose output modes.



## Sample Data Note
The `samples/media` directory contains files both with and without EXIF date metadata. Any test that does not correctly detect and handle files lacking EXIF dates (i.e., skips or collects them as unsortable) is considered failed.

## Test Directory Usage
To facilitate testing, the `tests` directory will be used as the working directory for all test scenarios. Before each test, relevant files will be copied from `samples/media` into `tests`. After inspecting the results, the `tests` directory will be cleaned to ensure a fresh state for the next test.

## Specific Test Cases

### TC01: Basic Organization Patterns
- **Objective**: Test all organization patterns (y, m, d, h)
- **Setup**: Copy sample files from `samples/media` to `tests/media`
- **Commands**: 
  - `./media-importer.sh -s ./tests/media -d ./tests/sorted_y -o y`
  - `./media-importer.sh -s ./tests/media -d ./tests/sorted_m -o m`
  - `./media-importer.sh -s ./tests/media -d ./tests/sorted_d -o d`
  - `./media-importer.sh -s ./tests/media -d ./tests/sorted_h -o h`
- **Expected**: Files organized according to each pattern
- **Cleanup**: `rm -rf ./tests/*`

### TC02: Copy vs Move Mode
- **Objective**: Test --keep-originals flag
- **Setup**: Copy sample files to `tests/media`
- **Commands**:
  - `./media-importer.sh -s ./tests/media -d ./tests/copied -k`
  - `./media-importer.sh -s ./tests/media -d ./tests/moved`
- **Expected**: First command copies files, second moves them
- **Cleanup**: `rm -rf ./tests/*`

### TC03: Dry Run Mode
- **Objective**: Test --dry-run functionality
- **Setup**: Copy sample files to `tests/media`
- **Command**: `./media-importer.sh -s ./tests/media -d ./tests/dry --dry-run`
- **Expected**: Shows what would be done without moving files
- **Cleanup**: `rm -rf ./tests/*`

### TC04: Symlinked Source
- **Objective**: Test symlinked source directory
- **Setup**: 
  - `mkdir -p tests/media`
  - `ln -sf ../samples/media tests/linked_media`
- **Command**: `./media-importer.sh -s ./tests/linked_media -d ./tests/from_symlink`
- **Expected**: Files from symlinked directory are processed
- **Cleanup**: `rm -rf ./tests/*`

### TC05: Error Handling - Invalid Pattern
- **Objective**: Test invalid organization pattern
- **Command**: `./media-importer.sh -o z`
- **Expected**: Error message and exit code 1
- **Cleanup**: None needed

### TC06: Same Source and Destination (Fatal Error)
- **Objective**: Test fatal error handling
- **Setup**: Copy sample files to `tests/media`
- **Command**: `./media-importer.sh -s ./tests -d ./tests`
- **Expected**: Fatal error stops processing immediately
- **Cleanup**: `rm -rf ./tests/*`

## New Feature: --full-date Argument & Default Flat Naming

### TC07: --full-date Argument (EXIF Date Required)
- **Objective**: Verify that only files with EXIF/media dates are processed and named with full date format.
- **Setup**: Copy sample files to `tests/media`
- **Command**: `./media-importer.sh --full-date -s ./tests/media -d ./tests/flat`
- **Expected**: Only files with EXIF dates in `tests/flat` named as `yyyy-mm-dd_hh-mm-ss.ext` (no subfolders). Files without EXIF dates remain in source.
- **Cleanup**: `rm -rf ./tests/*`

### TC08: No Organization Directive (EXIF Date Required)
- **Objective**: Verify that omitting the organization directive results in flat full-date naming for files with EXIF dates only.
- **Setup**: Copy sample files to `tests/media`
- **Command**: `./media-importer.sh -s ./tests/media -d ./tests/flat_default`
- **Expected**: Only files with EXIF dates in `tests/flat_default` named as `yyyy-mm-dd_hh-mm-ss.ext` (no subfolders). Files without EXIF dates remain in source.
- **Cleanup**: `rm -rf ./tests/*`

### TC09: Organization Directive with --full-date (EXIF Date Required)
- **Objective**: Verify that --full-date overrides any organization directive and processes only files with EXIF dates.
- **Setup**: Copy sample files to `tests/media`
- **Command**: `./media-importer.sh --full-date -o y -s ./tests/media -d ./tests/flat_override`
- **Expected**: Only files with EXIF dates in `tests/flat_override` named as `yyyy-mm-dd_hh-mm-ss.ext` (no subfolders). Files without EXIF dates remain in source.
- **Cleanup**: `rm -rf ./tests/*`

### TC10: --collect-unsortable Flag
- **Objective**: Verify that files without EXIF dates are moved to unsortable folder when flag is used.
- **Setup**: Copy sample files to `tests/media`
- **Command**: `./media-importer.sh --full-date --collect-unsortable -s ./tests/media -d ./tests/flat`
- **Expected**: Files with EXIF dates in `tests/flat` named as `yyyy-mm-dd_hh-mm-ss.ext`. Files without EXIF dates in `tests/flat/unsortable/`.
- **Cleanup**: `rm -rf ./tests/*`

### TC11: Basic Organization with EXIF Requirement
- **Objective**: Test that organization patterns only process files with EXIF dates.
- **Setup**: Copy sample files to `tests/media`
- **Command**: `./media-importer.sh -o y -s ./tests/media -d ./tests/sorted_y`
- **Expected**: Only files with EXIF dates organized by year. Files without EXIF dates remain in source.
- **Cleanup**: `rm -rf ./tests/*`

## Test Execution Framework
- Before each test: Prepare test data from `samples/media`
- Run test command and capture output
- Verify expected behavior and results
- After each test: Clean `tests` directory with `rm -rf ./tests/*`

---
This plan should be updated as new features or bug fixes are added.
