import { test } from 'node:test';
import assert from 'node:assert/strict';
import {
  POLICY_DOCUMENT_CATEGORIES,
  isPolicyDocumentCategory,
  nextPolicyDocumentVersion,
} from '@/shared/constants/policy-documents';

// --- category validation (Workstream 11) ---

test('isPolicyDocumentCategory accepts the two stored categories', () => {
  assert.equal(isPolicyDocumentCategory(POLICY_DOCUMENT_CATEGORIES.SAFETY_PROTOCOL), true);
  assert.equal(isPolicyDocumentCategory(POLICY_DOCUMENT_CATEGORIES.HANDBOOK_POLICY), true);
});

test('isPolicyDocumentCategory rejects anything else', () => {
  for (const bad of ['', 'safety', 'policy', null, undefined, 42, {}]) {
    assert.equal(isPolicyDocumentCategory(bad), false);
  }
});

// --- version-bump rule (re-acknowledgment) ---

test('editing content bumps the version', () => {
  assert.equal(nextPolicyDocumentVersion(1, true), 2);
  assert.equal(nextPolicyDocumentVersion(7, true), 8);
});

test('a metadata-only edit keeps the version', () => {
  assert.equal(nextPolicyDocumentVersion(1, false), 1);
  assert.equal(nextPolicyDocumentVersion(7, false), 7);
});

test('an explicit version overrides the rule', () => {
  assert.equal(nextPolicyDocumentVersion(1, false, 5), 5);
  assert.equal(nextPolicyDocumentVersion(1, true, 5), 5);
});
