OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-note / test / unit / notebook-gc.test.js

40 lines · javascript ref:
import test from 'brittle'
import { extractMediaHashes } from '../../lib/multiwriter/notebook-apply.js'

test('extractMediaHashes - finds image hashes in markdown', async (t) => {
  const content = 'Some text ![photo](/api/notebooks/general/media/abc123def456) and more ![vid](/api/notebooks/general/media/789012fed345)'
  const hashes = extractMediaHashes(content)
  t.is(hashes.size, 2)
  t.ok(hashes.has('abc123def456'))
  t.ok(hashes.has('789012fed345'))
})

test('extractMediaHashes - returns empty set for no media', async (t) => {
  const content = 'Just text, no images'
  const hashes = extractMediaHashes(content)
  t.is(hashes.size, 0)
})

test('extractMediaHashes - returns empty set for null/undefined', async (t) => {
  t.is(extractMediaHashes(null).size, 0)
  t.is(extractMediaHashes(undefined).size, 0)
  t.is(extractMediaHashes('').size, 0)
})

test('extractMediaHashes - handles 64-char hex hash references', async (t) => {
  const hash = 'a'.repeat(64)
  const content = '![image](' + hash + ')'
  const hashes = extractMediaHashes(content)
  t.is(hashes.size, 1)
  t.ok(hashes.has(hash))
})

test('extractMediaHashes - handles mixed old and new style refs', async (t) => {
  const hash = 'b'.repeat(64)
  const content = '![old](/api/notebooks/dev/media/lq3x2abc.jpg)\n![new](' + hash + ')'
  const hashes = extractMediaHashes(content)
  t.is(hashes.size, 2)
  t.ok(hashes.has('lq3x2abc.jpg'))
  t.ok(hashes.has(hash))
})