import test from "node:test";
import assert from "node:assert/strict";
import {
  CAPTURE_UPLOAD_DIR,
  getCaptureEvidenceKindFromMimeType,
  isAllowedCaptureMimeType,
  resolveCaptureStoragePath,
} from "@/lib/capture/files";

test("capture upload mime whitelist supports approved types only", () => {
  assert.equal(isAllowedCaptureMimeType("image/jpeg"), true);
  assert.equal(isAllowedCaptureMimeType("image/png"), true);
  assert.equal(isAllowedCaptureMimeType("image/webp"), true);
  assert.equal(isAllowedCaptureMimeType("application/pdf"), true);
  assert.equal(isAllowedCaptureMimeType("text/plain"), false);
});

test("capture evidence kind mapper returns only upload-compatible kinds", () => {
  assert.equal(getCaptureEvidenceKindFromMimeType("image/jpeg"), "photo");
  assert.equal(getCaptureEvidenceKindFromMimeType("application/pdf"), "document");
  assert.equal(getCaptureEvidenceKindFromMimeType("application/octet-stream"), "document");
});

test("resolveCaptureStoragePath blocks directory traversal", () => {
  const valid = resolveCaptureStoragePath("abc123.pdf");
  assert.equal(Boolean(valid?.startsWith(CAPTURE_UPLOAD_DIR)), true);

  const traversal = resolveCaptureStoragePath("../etc/passwd");
  assert.equal(traversal, null);
});
