11const Promise = require ( "bluebird" )
22const yaml = require ( "js-yaml" )
3+ const _ = require ( "lodash" )
34
45const { onNodeCreate } = require ( "../src/gatsby-node" )
56
@@ -37,7 +38,7 @@ describe(`Process YAML nodes correctly`, () => {
3738 } )
3839 } )
3940
40- it ( `If the object has an id, it uses that as the id instead of the contentDigest ` , async ( ) => {
41+ it ( `If the object has an id, it uses that as the id instead of the auto-generated one ` , async ( ) => {
4142 const data = [
4243 { id : "foo" , blue : true , funny : "yup" } ,
4344 { blue : false , funny : "nope" } ,
@@ -56,4 +57,28 @@ describe(`Process YAML nodes correctly`, () => {
5657 expect ( createNode . mock . calls [ 0 ] [ 0 ] . id ) . toEqual ( "foo" )
5758 } )
5859 } )
60+
61+ it ( `the different objects shouldn't get the same ID even if they have the same content` , async ( ) => {
62+ const data = [
63+ { id : "foo" , blue : true , funny : "yup" } ,
64+ { blue : false , funny : "nope" } ,
65+ { blue : false , funny : "nope" } ,
66+ { green : false , funny : "nope" } ,
67+ ]
68+ node . content = yaml . safeDump ( data )
69+
70+ const createNode = jest . fn ( )
71+ const updateNode = jest . fn ( )
72+ const boundActionCreators = { createNode, updateNode }
73+
74+ await onNodeCreate ( {
75+ node,
76+ loadNodeContent,
77+ boundActionCreators,
78+ } ) . then ( ( ) => {
79+ const ids = createNode . mock . calls . map ( object => object [ 0 ] . id )
80+ // Test that they're unique
81+ expect ( _ . uniq ( ids ) . length ) . toEqual ( 4 )
82+ } )
83+ } )
5984} )
0 commit comments