import { describe, expect, it } from 'vitest' import { digest } from './relay.mjs' import { analyzeDocument, analyzeDocuments, exclusionReason, factorPercentiles, READING_WPM, compareEcosystem, ecosystemMetrics, factorValues, countWords, extractLinks, extractText, isBulkAccount, normalizeTag, percentileRanks, scoreWithWarnings, rank, spamSignals, themeOf, titleSignature, treeScore, SCORE_TREE, } from './metrics.mjs' const NOW = Date.parse('2026-10-26T00:00:00Z') const DAY = 24 * 60 * 60 * 1000 function doc(overrides = {}) { return { title: 'A post', publishedAt: new Date(NOW - 5 * DAY).toISOString(), textContent: 'one two three', tags: [], ...overrides, } } describe('countWords', () => { it('counts tokens with a letter or number', () => { expect(countWords('one two, three… 42 — four')).toBe(5) }) it('does not count punctuation or empty text', () => { expect(countWords('— … !')).toBe(0) expect(countWords('')).toBe(0) expect(countWords(undefined)).toBe(0) }) }) describe('extractText', () => { it('prefers the standard.site field', () => { expect(extractText({ textContent: 'the body', content: { plaintext: 'ignored' } })).toBe( 'the body', ) }) it('reads Leaflet blocks nested under pages', () => { const record = { content: { $type: 'pub.leaflet.content', pages: [ { blocks: [ { block: { $type: 'pub.leaflet.blocks.text', plaintext: 'one two' } }, { block: { $type: 'pub.leaflet.blocks.blockquote', plaintext: 'three' } }, ], }, ], }, } expect(extractText(record)).toBe('one two\nthree') }) it('reads pckt items', () => { const record = { content: { $type: 'blog.pckt.content', items: [ { $type: 'blog.pckt.block.text', plaintext: 'one' }, { $type: 'blog.pckt.block.heading', plaintext: 'two' }, ], }, } expect(extractText(record)).toBe('one\ntwo') }) it('does not turn image alt text or placeholders into prose', () => { const record = { content: { items: [ { $type: 'blog.pckt.block.image', attrs: { alt: 'a photo of a cat', placeholder: 'data:image/png;base64,AAAA' }, }, ], }, } expect(extractText(record)).toBe('') }) }) describe('titleSignature', () => { it('reduces digits and hex ids to one shape', () => { expect(titleSignature('Color 0042')).toBe(titleSignature('Color 0043')) expect(titleSignature('Entry deadbeef')).toBe(titleSignature('Entry cafe12')) }) it('keeps different words apart', () => { expect(titleSignature('Color 1')).not.toBe(titleSignature('Shape 1')) }) }) describe('analyzeDocuments', () => { it('sums words and reports the median and recency', () => { const entries = [ analyzeDocument(doc({ textContent: 'one two three' }), { digest }), analyzeDocument( doc({ title: 'Older', textContent: 'one two', publishedAt: new Date(NOW - 200 * DAY).toISOString() }), { digest }, ), ] const metrics = analyzeDocuments(entries, { now: NOW }) expect(metrics.docCount).toBe(2) expect(metrics.wordCount).toBe(5) expect(metrics.medianWords).toBe(2.5) expect(metrics.postsLast30).toBe(1) expect(metrics.postsLast90).toBe(1) expect(metrics.noTextRatio).toBe(0) expect(metrics.readingMinutes).toBeCloseTo(5 / READING_WPM) expect(metrics.postsLast24h).toBe(0) expect(metrics.postsLast7d).toBe(1) expect(metrics.readingMinutesLast7d).toBeCloseTo(3 / READING_WPM) expect(metrics.readingMinutesLast30d).toBeCloseTo(3 / READING_WPM) }) it('does not treat a future-dated post as recent activity', () => { const entries = [ analyzeDocument( { publishedAt: new Date(NOW + 30 * DAY).toISOString(), textContent: 'scheduled future post', }, { digest }, ), analyzeDocument( { publishedAt: new Date(NOW - 2 * DAY).toISOString(), textContent: 'recent post', }, { digest }, ), ] const metrics = analyzeDocuments(entries, { now: NOW }) expect(metrics.docCount).toBe(2) expect(metrics.postsLast30).toBe(1) expect(metrics.lastPublishedAt).toBe(new Date(NOW - 2 * DAY).toISOString()) }) it('computes Presence and posting acceleration', () => { const entries = [ analyzeDocument( { publishedAt: new Date(NOW - 20 * DAY).toISOString(), textContent: 'recent words here' }, { digest }, ), analyzeDocument( { publishedAt: new Date(NOW - 60 * DAY).toISOString(), textContent: 'more recent words' }, { digest }, ), analyzeDocument( { publishedAt: new Date(NOW - 120 * DAY).toISOString(), textContent: 'prior words here' }, { digest }, ), ] const metrics = analyzeDocuments(entries, { now: NOW, publicationCreatedAt: new Date(NOW - 180 * DAY).toISOString(), }) expect(metrics.presence).toBeGreaterThan(0) expect(metrics.presence).toBeLessThanOrEqual(1) expect(metrics.acceleration).toBeGreaterThan(1) }) it('counts a document with no text as a post with zero words', () => { const entries = [analyzeDocument(doc({ textContent: undefined }), { digest })] const metrics = analyzeDocuments(entries, { now: NOW }) expect(metrics.docCount).toBe(1) expect(metrics.wordCount).toBe(0) expect(metrics.noTextRatio).toBe(1) }) it('notices repeated openings and titles', () => { const body = 'x'.repeat(120) const entries = [ analyzeDocument(doc({ title: 'Color 1', textContent: body }), { digest }), analyzeDocument(doc({ title: 'Color 2', textContent: body }), { digest }), analyzeDocument(doc({ title: 'Color 3', textContent: body }), { digest }), ] const metrics = analyzeDocuments(entries, { now: NOW }) expect(metrics.signatureDocs).toBe(3) expect(metrics.duplicateRatio).toBe(1) expect(metrics.templatedTitleRatio).toBe(1) }) it('counts text from a publishing tool that omits textContent', () => { const record = { title: 'A Leaflet post', publishedAt: new Date(NOW - DAY).toISOString(), content: { pages: [{ blocks: [{ block: { plaintext: 'one two three' } }] }] }, } expect(analyzeDocument(record, { digest }).words).toBe(3) }) it('counts normalized tags once per document', () => { const entries = [ analyzeDocument(doc({ tags: ['Rust', '#rust', 'atproto', 'rust'] }), { digest }), ] const metrics = analyzeDocuments(entries, { now: NOW }) expect(metrics.topTags).toEqual([ { tag: 'atproto', count: 1 }, { tag: 'rust', count: 1 }, ]) }) }) describe('spamSignals', () => { const base = { docCount: 5, noTextRatio: 0, duplicateRatio: 0, signatureDocs: 5, templatedTitleRatio: 0, velocityPerDay: 0, medianWords: 500, } it('leaves ordinary writing alone', () => { expect(spamSignals(base)).toEqual({ reasons: [], excluded: false }) }) it('excludes a corpus with one repeated body', () => { const spam = spamSignals({ ...base, docCount: 25, duplicateRatio: 0.9, signatureDocs: 25 }) expect(spam.reasons).toContain('duplicate-text') expect(spam.excluded).toBe(true) }) it('warns about a mostly empty publication without excluding it', () => { const spam = spamSignals({ ...base, docCount: 25, noTextRatio: 0.9 }) expect(spam.reasons).toContain('mostly-empty') expect(spam.excluded).toBe(false) }) it('excludes a high-velocity, low-depth corpus', () => { const spam = spamSignals({ ...base, docCount: 100, velocityPerDay: 50, medianWords: 20 }) expect(spam.reasons).toContain('bulk-velocity') expect(spam.excluded).toBe(true) }) }) describe('isBulkAccount', () => { it('flags an account that owns a network of publications', () => { expect(isBulkAccount({ publicationCount: 20, docCount: 20, wordCount: 1000 })).toBe(true) }) it('flags a mirrored documentation set', () => { expect(isBulkAccount({ publicationCount: 10, docCount: 100, wordCount: 5_000_000 })).toBe(true) }) it('leaves a prolific person alone', () => { expect(isBulkAccount({ publicationCount: 3, docCount: 900, wordCount: 400_000 })).toBe(false) }) }) describe('themeOf', () => { const color = (r, g, b) => ({ $type: 'site.standard.theme.color#rgb', r, g, b }) const basicTheme = (overrides = {}) => ({ $type: 'site.standard.theme.basic', accent: color(255, 2, 84), background: color(255, 255, 255), foreground: color(0, 0, 0), accentForeground: color(255, 255, 255), ...overrides, }) it('converts a complete theme to CSS colors', () => { expect(themeOf({ basicTheme: basicTheme() })).toEqual({ accent: 'rgb(255 2 84)', background: 'rgb(255 255 255)', foreground: 'rgb(0 0 0)', accentForeground: 'rgb(255 255 255)', }) }) it('returns undefined without a basic theme', () => { expect(themeOf({})).toBeUndefined() expect(themeOf(undefined)).toBeUndefined() }) it('requires a valid accent', () => { expect(themeOf({ basicTheme: basicTheme({ accent: undefined }) })).toBeUndefined() expect(themeOf({ basicTheme: basicTheme({ accent: { r: 1, g: 2 } }) })).toBeUndefined() }) it('rejects out-of-range and non-integer components', () => { expect(themeOf({ basicTheme: basicTheme({ accent: color(256, 0, 0) }) })).toBeUndefined() expect(themeOf({ basicTheme: basicTheme({ accent: color(0, -1, 0) }) })).toBeUndefined() expect(themeOf({ basicTheme: basicTheme({ accent: color('255', 0, 0) }) })).toBeUndefined() expect(themeOf({ basicTheme: basicTheme({ accent: color(1.5, 0, 0) }) })).toBeUndefined() }) it('includes only the valid optional colors', () => { expect( themeOf({ basicTheme: basicTheme({ background: undefined, foreground: color(300, 0, 0) }) }), ).toEqual({ accent: 'rgb(255 2 84)', accentForeground: 'rgb(255 255 255)' }) }) }) describe('extractLinks', () => { const record = { textContent: 'Read [the source](https://example.com/source) and https://example.org/raw. Again https://example.org/raw.', content: { pages: [ { blocks: [ { block: { $type: 'pub.leaflet.blocks.text', facets: [ { features: [ { $type: 'pub.leaflet.richtext.facet#link', uri: 'https://leaflet.test/a' }, ], }, ], }, }, ], }, ], }, links: [{ uri: 'https://links.test/b' }], } it('reads markdown, raw URLs, link facets and the links field, without duplicates', () => { expect(extractLinks(record, record.textContent).sort()).toEqual([ 'https://example.com/source', 'https://example.org/raw', 'https://leaflet.test/a', 'https://links.test/b', ]) }) it('drops non-http schemes', () => { const urls = extractLinks({ textContent: 'mailto:me@example.com ftp://x.test/a' }, 'mailto:me@example.com ftp://x.test/a') expect(urls).toEqual([]) }) }) describe('atproto and ecosystem links', () => { it('counts at:// references and structured embeds, ignoring the document discussion ref', () => { const entry = analyzeDocument( { textContent: 'A short post about a quote.', bskyPostRef: { uri: 'at://did:plc:a/app.bsky.feed.post/1', cid: 'bafcid' }, content: { $type: 'app.bsky.embed.record', record: { uri: 'at://did:plc:b/site.standard.document/2' }, nested: { text: 'See at://did:plc:c/site.standard.document/3' }, }, }, { digest }, ) expect(entry.atprotoRefs).toBe(2) expect(entry.embeds).toBe(1) }) it('classifies links to other stansites and atproto resources', () => { const entries = [ analyzeDocument( { textContent: 'Read https://other.stansite.test/a and https://bsky.app/profile/x and https://example.com/a.', }, { digest }, ), analyzeDocument( { textContent: 'Also https://other.stansite.test/b and https://bsky.app/profile/y.' }, { digest }, ), ] const metrics = analyzeDocuments(entries, { now: NOW, publicationHost: 'mine.test', stansiteHosts: new Set(['other.stansite.test']), }) expect(metrics.health.links.stansite).toBe(2) expect(metrics.health.links.atproto).toBe(2) expect(metrics.health.links.ecosystemPer1000Words).toBeGreaterThan(0) }) it('matches a shared host by path, not by host alone', () => { const entries = [ analyzeDocument( { textContent: 'Read https://shared.test/blog/post and https://shared.test/somewhere-else.', }, { digest }, ), ] const metrics = analyzeDocuments(entries, { now: NOW, publicationHost: 'mine.test', stansiteTargets: new Map([['shared.test', ['/blog']]]), }) expect(metrics.health.links.stansite).toBe(1) expect(metrics.health.links.sources).toBe(1) }) }) describe('factorValues', () => { const metrics = { docCount: 10, wordCount: 20_000, medianWords: 800, firstPublishedAt: new Date(NOW - 400 * DAY).toISOString(), lastPublishedAt: new Date(NOW - 5 * DAY).toISOString(), subscribers: 100, recommends: 10, postsLast90: 5, inboundReferences: 3, presence: 0.5, newAudience90: 4, linksPer1000Words: 5, duplicateRatio: 0.1, templatedTitleRatio: 0.2, } const health = { readability: { fleschKincaid: 10 }, lexical: { mtld: 100, hapaxRatio: 0.3, zipf: 4 }, links: { hostEntropy: 2, ecosystemPer1000Words: 3, atprotoRefsPer1000Words: 2, sources: 6, social: 2, uniqueSourceHosts: 4, }, structure: { structuralVariety: 0.5 }, cadence: { posts: 10, gapGini: 0.2 }, } it('returns every tree factor on its own scale', () => { const factors = factorValues(metrics, health, { now: NOW }) expect(Object.keys(factors)).toEqual([ 'reach', 'recommends', 'inboundReferences', 'volume', 'consistency', 'longevity', 'depth', 'lexicalDiversity', 'rareWords', 'structuralVariety', 'readability', 'freshness', 'audienceInflow', 'cadenceRegularity', 'sourceDiversity', 'atprotoRefs', ]) expect(factors.freshness).toBeCloseTo(Math.exp(-5 / 90), 6) expect(factors.readability).toBe(1) expect(factors.rareWords).toBe(0.5) expect(factors.structuralVariety).toBe(0.5) expect(factors.inboundReferences).toBeCloseTo(1.386) expect(factors.longevity).toBe(0.5) expect(factors.audienceInflow).toBeCloseTo(Math.log1p(4), 6) expect(factors.sourceDiversity).toBe(2) expect(factors.atprotoRefs).toBe(2) }) it('rewards a recent post over a dormant one', () => { const recent = factorValues(metrics, health, { now: NOW }).freshness const dormant = factorValues( { ...metrics, lastPublishedAt: new Date(NOW - 500 * DAY).toISOString() }, health, { now: NOW }, ).freshness expect(recent).toBeGreaterThan(dormant) }) it('does not give a one-post publication perfect cadence', () => { const onePost = { ...health, cadence: { posts: 1, gapGini: 0 } } expect(factorValues({ ...metrics, docCount: 1 }, onePost, { now: NOW }).cadenceRegularity).toBe(0) }) it('discounts consistency until five dated posts establish a history', () => { const two = factorValues( { ...metrics, docCount: 2, firstPublishedAt: new Date(NOW - 60 * DAY).toISOString(), lastPublishedAt: new Date(NOW).toISOString(), }, { ...health, cadence: { posts: 2, gapGini: 0 } }, { now: NOW }, ) const ten = factorValues( { ...metrics, docCount: 10, firstPublishedAt: new Date(NOW - 300 * DAY).toISOString(), lastPublishedAt: new Date(NOW).toISOString(), }, { ...health, cadence: { posts: 10, gapGini: 0 } }, { now: NOW }, ) expect(two.cadenceRegularity).toBeCloseTo(0.4) expect(ten.cadenceRegularity).toBeCloseTo(1) }) }) describe('percentileRanks', () => { it('puts the largest value at the top and shares ties', () => { expect(percentileRanks([10, 20, 20, 40])).toEqual([12.5, 50, 50, 87.5]) expect(percentileRanks([0, 0, 1, 2, 4])).toEqual([0, 0, 50, 70, 90]) }) it('answers an empty cohort with no ranks', () => { expect(percentileRanks([])).toEqual([]) }) }) describe('factorPercentiles', () => { it('keeps zero outside the positive audience cohort', () => { const rows = [ { factorValues: { reach: 0, recommends: 0 } }, { factorValues: { reach: 1, recommends: 10 } }, { factorValues: { reach: 2, recommends: 20 } }, { factorValues: { reach: 3 } }, ] const percentiles = factorPercentiles(rows, SCORE_TREE) expect(percentiles[0].reach).toBe(0) expect(percentiles[1].reach).toBeCloseTo(16.67) expect(percentiles[2].reach).toBeCloseTo(50) expect(percentiles[3].reach).toBeCloseTo(83.33) expect(percentiles[0].recommends).toBe(0) expect(percentiles[1].recommends).toBe(25) expect(percentiles[2].recommends).toBe(75) }) it('percentiles each factor and leaves missing factors undefined', () => { const rows = [ { factorValues: { reach: 1, recommends: 10 } }, { factorValues: { reach: 2, recommends: 20 } }, { factorValues: { reach: 3 } }, ] const percentiles = factorPercentiles(rows, SCORE_TREE) expect(percentiles[0].reach).toBeCloseTo(16.67) expect(percentiles[1].reach).toBeCloseTo(50) expect(percentiles[2].reach).toBeCloseTo(83.33) expect(percentiles[0].recommends).toBe(25) expect(percentiles[1].recommends).toBe(75) expect(percentiles[2].recommends).toBeUndefined() }) }) describe('SCORE_TREE', () => { it('stays within the two-level shape the editor renders', () => { expect(SCORE_TREE.categories.length).toBeGreaterThanOrEqual(5) expect(SCORE_TREE.categories.length).toBeLessThanOrEqual(10) for (const category of SCORE_TREE.categories) { expect(category.factors.length).toBeGreaterThanOrEqual(1) expect(category.factors.length).toBeLessThanOrEqual(5) } }) it('gives every node a name, icon or vibe, and an exact-metric description', () => { for (const category of SCORE_TREE.categories) { expect(category.name).toMatch(/^[A-Za-z]+$/) expect(category.icon).toMatch(/^[a-z]+$/) expect(category.vibe.length).toBeGreaterThan(0) expect(category.detail.length).toBeGreaterThan(0) for (const factor of category.factors) { expect(factor.name.length).toBeGreaterThan(0) expect(factor.detail.length).toBeGreaterThan(0) } } }) }) describe('treeScore', () => { const all100 = {} for (const category of SCORE_TREE.categories) { for (const factor of category.factors) all100[factor.id] = 100 } it('is 100 when every available factor is 100', () => { expect(treeScore(all100)).toBeCloseTo(100) expect(treeScore({ ...all100, reach: 0, recommends: 100 })).toBeCloseTo(90) }) it('renormalizes when a factor is unavailable', () => { const factors = { ...all100 } delete factors.readability expect(treeScore(factors)).toBeCloseTo(100) }) it('uses reader weights and renormalizes zero weights', () => { const weights = {} for (const category of SCORE_TREE.categories) { weights[category.id] = { weight: category.id === 'audience' ? 1 : 0, factors: Object.fromEntries(category.factors.map((factor) => [factor.id, factor.weight])), } } expect(treeScore({ ...all100, reach: 0, recommends: 100 }, SCORE_TREE, weights)).toBeCloseTo( 40, ) }) it('charges warnings five points each', () => { const clean = scoreWithWarnings(all100) const warned = scoreWithWarnings(all100, { reasons: ['mostly-empty'] }) expect(clean - warned).toBeCloseTo(5) }) }) describe('health metrics', () => { const text = [ 'I write with a small vocabulary. The sentences are short. Is this readable?', 'This paragraph is here to give the extractor something with a little more shape.', ].join('\n\n') it('computes readability, lexical and link health for a publication', () => { const entries = [ analyzeDocument( doc({ textContent: `${text} See https://example.com/source and https://bsky.app/profile/x.`, }), { digest }, ), ] const metrics = analyzeDocuments(entries, { now: NOW, publicationHost: 'example.com' }) expect(metrics.health.readability.fleschKincaid).toBeGreaterThan(0) expect(metrics.health.lexical.ttr).toBeGreaterThan(0) expect(metrics.health.links.total).toBe(2) expect(metrics.health.links.external).toBe(1) expect(metrics.health.links.internal).toBe(1) expect(metrics.health.links.social).toBe(1) expect(metrics.health.cadence.postsPerMonth).toBeGreaterThan(0) }) it('counts links from Leaflet facets as external', () => { const record = { title: 'With a source', publishedAt: new Date(NOW - DAY).toISOString(), content: { pages: [ { blocks: [ { block: { plaintext: 'A post with a source.', facets: [ { features: [ { $type: 'pub.leaflet.richtext.facet#link', uri: 'https://source.test/x' }, ], }, ], }, }, ], }, ], }, } const metrics = analyzeDocuments([analyzeDocument(record, { digest })], { now: NOW, publicationHost: 'leaflet.pub', }) expect(metrics.health.links.external).toBe(1) expect(metrics.health.links.uniqueExternalHosts).toBe(1) }) }) describe('ecosystemMetrics', () => { const row = (overrides = {}) => ({ readingMinutes: 120, readingMinutesLast24h: 60, readingMinutesLast7d: 120, readingMinutesLast30d: 120, postsLast24h: 1, postsLast7d: 2, postsLast30: 2, wordCount: 1000, docCount: 2, createdAt: new Date(NOW - 10 * DAY).toISOString(), duplicateRatio: 0.1, spam: { excluded: false, reasons: [] }, health: { readability: { fleschKincaid: 10, fleschReadingEase: 60 }, lexical: { mtld: 100, ttr: 0.4, hapaxRatio: 0.2 }, style: { sentenceLengthMean: 12 }, links: { external: 5, social: 1, hosts: ['a.test', 'b.test'], per1000Words: 5 }, }, ...overrides, }) const rows = [ row(), row({ readingMinutes: 60, readingMinutesLast24h: 0, readingMinutesLast7d: 60, readingMinutesLast30d: 60, postsLast24h: 0, postsLast7d: 1, postsLast30: 1, wordCount: 500, docCount: 1, duplicateRatio: 0.2, spam: { excluded: true, reasons: ['duplicate-text'] }, }), ] it('computes reading flow, growth and corpus medians', () => { const ecosystem = ecosystemMetrics(rows, { now: NOW }) expect(ecosystem.reading.wpm).toBe(READING_WPM) expect(ecosystem.reading.hoursLast24h).toBe(1) expect(ecosystem.reading.hoursPerDay7d).toBeCloseTo(3 / 7) expect(ecosystem.reading.hoursPerDay30d).toBeCloseTo(3 / 30) expect(ecosystem.reading.postsPerDay30d).toBeCloseTo(3 / 30) expect(ecosystem.reading.activePublications30d).toBe(2) expect(ecosystem.reading.publicationCount).toBe(2) expect(ecosystem.reading.newPublications30d).toBe(2) expect(ecosystem.reading.spamShare).toBe(0.5) expect(ecosystem.readability.fleschKincaid).toBe(10) expect(ecosystem.links.externalPer1000Words).toBeCloseTo((10 / 1500) * 1000) }) it('scores health only when there is a baseline', () => { const ecosystem = ecosystemMetrics(rows, { now: NOW }) expect(compareEcosystem(ecosystem, []).health).toBeNull() const compared = compareEcosystem(ecosystem, [ { name: 'baseline', metrics: { reading: { hoursPerDay30d: 0.2 }, readability: { fleschKincaid: 10 }, lexical: { mtld: 100 }, links: { externalPer1000Words: 5 }, }, }, ]) expect(compared.comparison.name).toBe('baseline') expect(compared.health.baseline).toBe('baseline') expect(compared.health.score).toBeGreaterThan(0) }) }) describe('normalizeTag', () => { it('lowercases, strips a hash and rejects noise', () => { expect(normalizeTag(' #Rust ')).toBe('rust') expect(normalizeTag('x')).toBeNull() expect(normalizeTag(42)).toBeNull() }) }) describe('rank', () => { it('orders by score and numbers the result', () => { const items = [ { uri: 'at://a', score: 1, wordCount: 10 }, { uri: 'at://b', score: 3, wordCount: 1 }, { uri: 'at://c', score: 3, wordCount: 20 }, ] expect(rank(items).map((item) => [item.uri, item.rank])).toEqual([ ['at://c', 1], ['at://b', 2], ['at://a', 3], ]) }) }) describe('exclusionReason', () => { const base = { discoverable: true, docCount: 3, wordCount: 1_000, spam: { excluded: false } } it('marks a ranked row included', () => { expect(exclusionReason({ ...base, rank: 1 }, 1_000)).toBe('included') }) it('follows the priority order', () => { expect( exclusionReason( { ...base, spam: { excluded: true }, discoverable: false, docCount: 0, wordCount: 0 }, 1_000, ), ).toBe('spam') expect(exclusionReason({ ...base, discoverable: false, docCount: 0, wordCount: 0 }, 1_000)).toBe( 'undiscoverable', ) expect(exclusionReason({ ...base, docCount: 0, wordCount: 0 }, 1_000)).toBe('no-posts') expect(exclusionReason({ ...base, wordCount: 999 }, 1_000)).toBe('below-minimum-words') expect(exclusionReason({ ...base, wordCount: 1_000 }, 1_000)).toBe('other') }) it('lets a rank override every exclusion', () => { expect( exclusionReason({ ...base, rank: 2, spam: { excluded: true }, discoverable: false }, 1_000), ).toBe('included') }) })