1- import { createHash } from 'node:crypto' ;
2-
31import test from 'ava' ;
2+ import { NIL as NIL_UUID } from 'uuid' ;
43
54import { createColumn } from '../schema/column.js' ;
65import { addCQIDsColumns , cqIDColumn } from '../schema/meta.js' ;
@@ -10,21 +9,49 @@ import { createTable } from '../schema/table.js';
109import { setCQId } from './cqid.js' ;
1110
1211test ( 'setCQId - should set to random value if deterministicCQId is false' , ( t ) : void => {
13- const resource = new Resource ( addCQIDsColumns ( createTable ( { name : 'table1' } ) ) , null , null ) ;
12+ const resource = new Resource (
13+ addCQIDsColumns (
14+ createTable ( {
15+ name : 'table1' ,
16+ columns : [
17+ createColumn ( { name : 'pk1' , primaryKey : true , unique : true , notNull : true } ) ,
18+ createColumn ( { name : 'pk2' , primaryKey : true , unique : true , notNull : true } ) ,
19+ createColumn ( { name : 'pk3' , primaryKey : true , unique : true , notNull : true } ) ,
20+ createColumn ( { name : 'non_pk' } ) ,
21+ ] ,
22+ } ) ,
23+ ) ,
24+ null ,
25+ null ,
26+ ) ;
1427
15- setCQId ( resource , false , ( ) => 'random' ) ;
28+ setCQId ( resource , false , ( ) => NIL_UUID ) ;
1629
1730 t . is ( resource . getColumnData ( cqIDColumn . name ) . valid , true ) ;
18- t . is ( resource . getColumnData ( cqIDColumn . name ) . value . toString ( ) , 'random' ) ;
31+ t . is ( resource . getColumnData ( cqIDColumn . name ) . value . toString ( ) , NIL_UUID ) ;
1932} ) ;
2033
2134test ( 'setCQId - should set to random value if deterministicCQId is true and table does not have non _cq_id PKs' , ( t ) : void => {
22- const resource = new Resource ( addCQIDsColumns ( createTable ( { name : 'table1' } ) ) , null , null ) ;
35+ const resource = new Resource (
36+ addCQIDsColumns (
37+ createTable ( {
38+ name : 'table1' ,
39+ columns : [
40+ createColumn ( { name : 'pk1' , primaryKey : false , unique : true , notNull : true } ) ,
41+ createColumn ( { name : 'pk2' , primaryKey : false , unique : true , notNull : true } ) ,
42+ createColumn ( { name : 'pk3' , primaryKey : false , unique : true , notNull : true } ) ,
43+ createColumn ( { name : 'non_pk' } ) ,
44+ ] ,
45+ } ) ,
46+ ) ,
47+ null ,
48+ null ,
49+ ) ;
2350
24- setCQId ( resource , true , ( ) => 'random' ) ;
51+ setCQId ( resource , true , ( ) => NIL_UUID ) ;
2552
2653 t . is ( resource . getColumnData ( cqIDColumn . name ) . valid , true ) ;
27- t . is ( resource . getColumnData ( cqIDColumn . name ) . value . toString ( ) , 'random' ) ;
54+ t . is ( resource . getColumnData ( cqIDColumn . name ) . value . toString ( ) , NIL_UUID ) ;
2855} ) ;
2956
3057test ( 'setCQId - should set to fixed value if deterministicCQId is true and table has non _cq_id PKs' , ( t ) : void => {
@@ -49,16 +76,8 @@ test('setCQId - should set to fixed value if deterministicCQId is true and table
4976 resource . setColumData ( 'pk3' , 'pk3-value' ) ;
5077 resource . setColumData ( 'non_pk' , 'non-pk-value' ) ;
5178
52- const expectedSha256 = createHash ( 'sha256' ) ;
53- expectedSha256 . update ( 'pk1' ) ;
54- expectedSha256 . update ( 'pk1-value' ) ;
55- expectedSha256 . update ( 'pk2' ) ;
56- expectedSha256 . update ( 'pk2-value' ) ;
57- expectedSha256 . update ( 'pk3' ) ;
58- expectedSha256 . update ( 'pk3-value' ) ;
59-
6079 setCQId ( resource , true ) ;
6180
6281 t . is ( resource . getColumnData ( cqIDColumn . name ) . valid , true ) ;
63- t . is ( resource . getColumnData ( cqIDColumn . name ) . value . toString ( ) , expectedSha256 . digest ( 'hex' ) ) ;
82+ t . is ( resource . getColumnData ( cqIDColumn . name ) . value . toString ( ) , '415bd5dd-9bac-5806-b9d1-c53f17d37455' ) ;
6483} ) ;
0 commit comments