14
14
*/
15
15
16
16
import { caching } from 'cache-manager' ;
17
+ import { createHash } from 'crypto' ;
17
18
18
19
import { computeEntityMap , normaliseParent , NodeManager } from '#node' ;
19
20
@@ -74,13 +75,17 @@ function generatePage({
74
75
} ;
75
76
}
76
77
78
+ function hashFn ( content : string | FullDatabase | FullPage ) : string {
79
+ return createHash ( 'sha256' ) . update ( JSON . stringify ( content ) ) . digest ( 'hex' ) ;
80
+ }
81
+
77
82
describe ( 'fn:computeEntityMap' , ( ) => {
78
83
it ( 'pass with a workspace parent' , ( ) => {
79
84
const workspaceDatabase = generateDatabase ( {
80
85
databaseID : 'database_under_a_workspace' ,
81
86
} ) ;
82
87
83
- const map = computeEntityMap ( [ workspaceDatabase ] ) ;
88
+ const map = computeEntityMap ( [ workspaceDatabase ] , hashFn ) ;
84
89
const normalised = map . get ( 'database:database_under_a_workspace' ) ;
85
90
expect ( normalised ! . id ) . toEqual ( 'database_under_a_workspace' ) ;
86
91
expect ( normalised ! . parent ) . toEqual ( null ) ;
@@ -93,7 +98,7 @@ describe('fn:computeEntityMap', () => {
93
98
parent : { type : 'page_id' , page_id : 'parent-page' } ,
94
99
} ) ;
95
100
96
- const map = computeEntityMap ( [ pageDatabase ] ) ;
101
+ const map = computeEntityMap ( [ pageDatabase ] , hashFn ) ;
97
102
const normalised = map . get ( 'database:database_under_a_page' ) ;
98
103
expect ( normalised ! . id ) . toEqual ( 'database_under_a_page' ) ;
99
104
expect ( normalised ! . parent ) . toEqual ( { object : 'page' , id : 'parent-page' } ) ;
@@ -106,7 +111,7 @@ describe('fn:computeEntityMap', () => {
106
111
parent : { type : 'database_id' , database_id : 'missing' } ,
107
112
} ) ;
108
113
109
- const map = computeEntityMap ( [ dangledPage ] ) ;
114
+ const map = computeEntityMap ( [ dangledPage ] , hashFn ) ;
110
115
const normalised = map . get ( 'page:dangled_page' ) ;
111
116
expect ( normalised ! . id ) . toEqual ( 'dangled_page' ) ;
112
117
expect ( normalised ! . parent ) . toEqual ( { object : 'database' , id : 'missing' } ) ;
@@ -129,7 +134,10 @@ describe('fn:computeEntityMap', () => {
129
134
parent : { type : 'page_id' , page_id : 'page_with_pages' } ,
130
135
} ) ;
131
136
132
- const map = computeEntityMap ( [ database , ...database . pages , page , subpage ] ) ;
137
+ const map = computeEntityMap (
138
+ [ database , ...database . pages , page , subpage ] ,
139
+ hashFn ,
140
+ ) ;
133
141
expect ( map . size ) . toEqual ( 4 ) ;
134
142
135
143
const normalisedDB = map . get ( 'database:database_with_pages' ) ;
@@ -194,7 +202,7 @@ describe('cl:NodeManager', () => {
194
202
it ( 'always keep gatsby synced' , async ( ) => {
195
203
const createNode = jest . fn ( ) ;
196
204
const deleteNode = jest . fn ( ) ;
197
- const createContentDigest = jest . fn ( ( ) => 'digest' ) ;
205
+ const createContentDigest = jest . fn ( hashFn ) ;
198
206
const createNodeId = jest . fn ( ( id ) => id ) ;
199
207
200
208
const manager = new NodeManager ( {
0 commit comments