File tree Expand file tree Collapse file tree 5 files changed +12
-32
lines changed Expand file tree Collapse file tree 5 files changed +12
-32
lines changed Original file line number Diff line number Diff line change 1- import { assignId } from '../assignId ' ;
1+ import { generateId } from '../generateId ' ;
22
3- describe ( 'assignId util' , ( ) => {
3+ describe ( 'generateId util' , ( ) => {
44 let mathRandomSpy : jest . SpyInstance ;
55
66 beforeEach ( ( ) => {
@@ -14,16 +14,7 @@ describe('assignId util', () => {
1414 test ( 'should generate random id' , ( ) => {
1515 mathRandomSpy . mockReturnValueOnce ( 0.54444 ) . mockReturnValueOnce ( 0.321 ) ;
1616
17- expect ( assignId ( { } ) ) . toEqual ( '0.jlle4v0fcep' ) ;
18- expect ( assignId ( { } ) ) . toEqual ( '0.bk0kqhutdje' ) ;
19- } ) ;
20-
21- test ( 'should return previously stored id for same node' , ( ) => {
22- mathRandomSpy . mockReturnValueOnce ( 0.23 ) ;
23-
24- const node = { } ;
25- const id = assignId ( node ) ;
26-
27- expect ( assignId ( node ) ) . toEqual ( id ) ;
17+ expect ( generateId ( ) ) . toEqual ( '0.jlle4v0fcep' ) ;
18+ expect ( generateId ( ) ) . toEqual ( '0.bk0kqhutdje' ) ;
2819 } ) ;
2920} ) ;
Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ import { renderSchema } from '../renderSchema';
44
55const BASE_PATH = path . resolve ( __dirname , '../../__fixtures__/' ) ;
66
7- jest . mock ( '../assignId ' , ( ) => ( {
8- assignId : jest . fn ( ( ) => 'random-id' ) ,
7+ jest . mock ( '../generateId ' , ( ) => ( {
8+ generateId : jest . fn ( ( ) => 'random-id' ) ,
99} ) ) ;
1010
1111describe ( 'renderSchema util' , ( ) => {
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ export const generateId = ( ) : string => Math . random ( ) . toString ( 36 ) ;
Original file line number Diff line number Diff line change 88 SchemaKind ,
99 SchemaNode ,
1010} from '../types' ;
11- import { assignId } from './assignId ' ;
11+ import { generateId } from './generateId ' ;
1212import { getAnnotations } from './getAnnotations' ;
1313import { getPrimaryType } from './getPrimaryType' ;
1414import { getValidations } from './getValidations' ;
@@ -35,7 +35,7 @@ function processNode(node: JSONSchema4): SchemaNode | void {
3535
3636 if ( combiner ) {
3737 return {
38- id : assignId ( node ) ,
38+ id : generateId ( ) ,
3939 combiner,
4040 properties : node [ combiner ] ,
4141 annotations : getAnnotations ( node ) ,
@@ -45,7 +45,7 @@ function processNode(node: JSONSchema4): SchemaNode | void {
4545
4646 if ( type ) {
4747 const base : IBaseNode = {
48- id : assignId ( node ) ,
48+ id : generateId ( ) ,
4949 type : node . type || inferType ( node ) ,
5050 validations : getValidations ( node ) ,
5151 annotations : getAnnotations ( node ) ,
@@ -59,7 +59,7 @@ function processNode(node: JSONSchema4): SchemaNode | void {
5959
6060 if ( 'enum' in node ) {
6161 return {
62- id : assignId ( node ) ,
62+ id : generateId ( ) ,
6363 validations : getValidations ( node ) ,
6464 annotations : getAnnotations ( node ) ,
6565 enum : node . enum ,
@@ -68,7 +68,7 @@ function processNode(node: JSONSchema4): SchemaNode | void {
6868
6969 if ( '$ref' in node ) {
7070 return {
71- id : assignId ( node ) ,
71+ id : generateId ( ) ,
7272 $ref : node . $ref ,
7373 } as IRefNode ;
7474 }
You can’t perform that action at this time.
0 commit comments