1414 */
1515
1616import { caching } from 'cache-manager' ;
17+ import { createHash } from 'crypto' ;
1718
1819import { computeEntityMap , normaliseParent , NodeManager } from '#node' ;
1920
@@ -74,13 +75,17 @@ function generatePage({
7475 } ;
7576}
7677
78+ function hashFn ( content : string | FullDatabase | FullPage ) : string {
79+ return createHash ( 'sha256' ) . update ( JSON . stringify ( content ) ) . digest ( 'hex' ) ;
80+ }
81+
7782describe ( 'fn:computeEntityMap' , ( ) => {
7883 it ( 'pass with a workspace parent' , ( ) => {
7984 const workspaceDatabase = generateDatabase ( {
8085 databaseID : 'database_under_a_workspace' ,
8186 } ) ;
8287
83- const map = computeEntityMap ( [ workspaceDatabase ] ) ;
88+ const map = computeEntityMap ( [ workspaceDatabase ] , hashFn ) ;
8489 const normalised = map . get ( 'database:database_under_a_workspace' ) ;
8590 expect ( normalised ! . id ) . toEqual ( 'database_under_a_workspace' ) ;
8691 expect ( normalised ! . parent ) . toEqual ( null ) ;
@@ -93,7 +98,7 @@ describe('fn:computeEntityMap', () => {
9398 parent : { type : 'page_id' , page_id : 'parent-page' } ,
9499 } ) ;
95100
96- const map = computeEntityMap ( [ pageDatabase ] ) ;
101+ const map = computeEntityMap ( [ pageDatabase ] , hashFn ) ;
97102 const normalised = map . get ( 'database:database_under_a_page' ) ;
98103 expect ( normalised ! . id ) . toEqual ( 'database_under_a_page' ) ;
99104 expect ( normalised ! . parent ) . toEqual ( { object : 'page' , id : 'parent-page' } ) ;
@@ -106,7 +111,7 @@ describe('fn:computeEntityMap', () => {
106111 parent : { type : 'database_id' , database_id : 'missing' } ,
107112 } ) ;
108113
109- const map = computeEntityMap ( [ dangledPage ] ) ;
114+ const map = computeEntityMap ( [ dangledPage ] , hashFn ) ;
110115 const normalised = map . get ( 'page:dangled_page' ) ;
111116 expect ( normalised ! . id ) . toEqual ( 'dangled_page' ) ;
112117 expect ( normalised ! . parent ) . toEqual ( { object : 'database' , id : 'missing' } ) ;
@@ -129,7 +134,10 @@ describe('fn:computeEntityMap', () => {
129134 parent : { type : 'page_id' , page_id : 'page_with_pages' } ,
130135 } ) ;
131136
132- const map = computeEntityMap ( [ database , ...database . pages , page , subpage ] ) ;
137+ const map = computeEntityMap (
138+ [ database , ...database . pages , page , subpage ] ,
139+ hashFn ,
140+ ) ;
133141 expect ( map . size ) . toEqual ( 4 ) ;
134142
135143 const normalisedDB = map . get ( 'database:database_with_pages' ) ;
@@ -194,7 +202,7 @@ describe('cl:NodeManager', () => {
194202 it ( 'always keep gatsby synced' , async ( ) => {
195203 const createNode = jest . fn ( ) ;
196204 const deleteNode = jest . fn ( ) ;
197- const createContentDigest = jest . fn ( ( ) => 'digest' ) ;
205+ const createContentDigest = jest . fn ( hashFn ) ;
198206 const createNodeId = jest . fn ( ( id ) => id ) ;
199207
200208 const manager = new NodeManager ( {
0 commit comments