11// @vitest -environment node
22
33import { describe , expect , it } from 'vitest' ;
4- import type { FeedData , QualityReview } from '@/blog/model/types' ;
4+ import type { FeedData } from '@/blog/model/types' ;
55import { getAllFeedSlugs , getSortedFeedData } from './post-repository' ;
6- import { filterVisiblePosts , isPostVisible } from './publication-policy' ;
6+ import {
7+ filterVisiblePosts ,
8+ getCoreTechReviewAverage ,
9+ isEligibleForFeaturedPost ,
10+ isPostVisible ,
11+ meetsPublicTechReviewThreshold ,
12+ PUBLICATION_POLICY ,
13+ } from './policy' ;
714
815const FEATURED_SLUGS = [
916 'ctr-pipeline' ,
@@ -12,17 +19,6 @@ const FEATURED_SLUGS = [
1219 'msa-domain-workspace-submodule' ,
1320] ;
1421
15- function readCoreAverage ( review : QualityReview | undefined ) : number | null {
16- const scores = [ review ?. philosophy , review ?. design , review ?. implementation ] ;
17-
18- if ( scores . some ( ( score ) => typeof score !== 'number' ) ) {
19- return null ;
20- }
21-
22- const [ philosophy , design , implementation ] = scores as number [ ] ;
23- return ( philosophy + design + implementation ) / 3 ;
24- }
25-
2622function describePost ( post : FeedData ) : string {
2723 return `${ post . slug } (${ post . title } )` ;
2824}
@@ -40,6 +36,34 @@ describe('publication policy', () => {
4036 expect ( filterVisiblePosts ( [ privatePost , publicPost ] ) ) . toEqual ( [ publicPost ] ) ;
4137 } ) ;
4238
39+ it ( 'keeps editorial thresholds in the policy module' , ( ) => {
40+ expect (
41+ meetsPublicTechReviewThreshold ( {
42+ philosophy : 3.5 ,
43+ design : 3.5 ,
44+ implementation : 3.5 ,
45+ } )
46+ ) . toBe ( true ) ;
47+ expect ( meetsPublicTechReviewThreshold ( { } ) ) . toBe ( false ) ;
48+
49+ expect (
50+ isEligibleForFeaturedPost ( {
51+ category : 'Tech' ,
52+ qualityReview : {
53+ brandFit : PUBLICATION_POLICY . featured . minimumBrandFit ,
54+ } ,
55+ } )
56+ ) . toBe ( true ) ;
57+ expect (
58+ isEligibleForFeaturedPost ( {
59+ category : 'Life' ,
60+ qualityReview : {
61+ brandFit : PUBLICATION_POLICY . featured . minimumBrandFit ,
62+ } ,
63+ } )
64+ ) . toBe ( false ) ;
65+ } ) ;
66+
4367 it ( 'keeps every private post out of public listings and static paths' , ( ) => {
4468 const allPosts = getSortedFeedData ( { includePrivate : true } ) ;
4569 const privatePosts = allPosts . filter (
@@ -70,17 +94,17 @@ describe('publication policy', () => {
7094 const offenses = getSortedFeedData ( )
7195 . filter ( ( post ) => post . category === 'Tech' )
7296 . flatMap ( ( post ) => {
73- const average = readCoreAverage ( post . qualityReview ) ;
97+ const average = getCoreTechReviewAverage ( post . qualityReview ) ;
7498
75- if ( average === null ) {
76- return [
77- `${ describePost ( post ) } : qualityReview core scores are incomplete` ,
78- ] ;
79- }
99+ if ( ! meetsPublicTechReviewThreshold ( post . qualityReview ) ) {
100+ if ( average === null ) {
101+ return [
102+ `${ describePost ( post ) } : qualityReview core scores are incomplete` ,
103+ ] ;
104+ }
80105
81- if ( average <= 3 ) {
82106 return [
83- `${ describePost ( post ) } : core average ${ average . toFixed ( 2 ) } <= 3.0 ` ,
107+ `${ describePost ( post ) } : core average ${ average . toFixed ( 2 ) } <= ${ PUBLICATION_POLICY . publicTech . minimumCoreReviewAverageExclusive . toFixed ( 1 ) } ` ,
84108 ] ;
85109 }
86110
@@ -93,26 +117,9 @@ describe('publication policy', () => {
93117 it ( 'requires featured posts to meet branding thresholds' , ( ) => {
94118 const featuredPosts = getSortedFeedData ( ) . filter ( ( post ) => post . featured ) ;
95119 const offenses = featuredPosts . flatMap ( ( post ) => {
96- const brandFit = post . qualityReview ?. brandFit ;
97- const currentOffenses : string [ ] = [ ] ;
98-
99- if ( post . category !== 'Tech' ) {
100- currentOffenses . push (
101- `${ describePost ( post ) } : featured posts must be Tech`
102- ) ;
103- }
104-
105- if ( post . series ) {
106- currentOffenses . push (
107- `${ describePost ( post ) } : featured posts must not be series`
108- ) ;
109- }
110-
111- if ( typeof brandFit !== 'number' || brandFit < 4 ) {
112- currentOffenses . push ( `${ describePost ( post ) } : brandFit must be >= 4.0` ) ;
113- }
114-
115- return currentOffenses ;
120+ return isEligibleForFeaturedPost ( post )
121+ ? [ ]
122+ : [ `${ describePost ( post ) } : does not meet featured criteria` ] ;
116123 } ) ;
117124
118125 expect ( featuredPosts . map ( ( post ) => post . slug ) . sort ( ) ) . toEqual (
0 commit comments