@@ -23,6 +23,9 @@ DefaultTable.addEntity(
2323 set : { type : 'set' , setType : 'string' , alias : 'set_alias' } ,
2424 set_alias2 : { type : 'set' , setType : 'string' , map : 'set2' } ,
2525 number : 'number' ,
26+ numberSet : { type : 'set' , setType : 'number' } ,
27+ bigint : 'bigint' ,
28+ bigintSet : { type : 'set' , setType : 'bigint' } ,
2629 list : { type : 'list' , alias : 'list_alias' } ,
2730 list_alias2 : { type : 'list' , map : 'list2' } ,
2831 test : 'map' ,
@@ -38,63 +41,95 @@ DefaultTable.addEntity(
3841 } as const )
3942)
4043
41- // console.log(DefaultTable.User);
42-
4344describe ( 'formatItem' , ( ) => {
4445 it ( 'formats item with no alias' , ( ) => {
45- const result = formatItem ( ) (
46- DefaultTable . User . schema . attributes ,
47- DefaultTable . User . linked ,
48- { pk : 'test' }
49- )
46+ const result = formatItem ( ) ( DefaultTable . User . schema . attributes , DefaultTable . User . linked , {
47+ pk : 'test'
48+ } )
5049 expect ( result ) . toEqual ( { pk : 'test' } )
5150 } )
5251
5352 it ( 'formats item with alias' , ( ) => {
54- const result = formatItem ( ) (
55- DefaultTable . User . schema . attributes ,
56- DefaultTable . User . linked ,
57- { list : [ 'test' ] }
58- )
53+ const result = formatItem ( ) ( DefaultTable . User . schema . attributes , DefaultTable . User . linked , {
54+ list : [ 'test' ]
55+ } )
5956 expect ( result ) . toEqual ( { list_alias : [ 'test' ] } )
6057 } )
6158
6259 it ( 'formats item with mapping' , ( ) => {
63- const result = formatItem ( ) (
64- DefaultTable . User . schema . attributes ,
65- DefaultTable . User . linked ,
66- { list2 : [ 'test' ] }
67- )
60+ const result = formatItem ( ) ( DefaultTable . User . schema . attributes , DefaultTable . User . linked , {
61+ list2 : [ 'test' ]
62+ } )
6863 expect ( result ) . toEqual ( { list_alias2 : [ 'test' ] } )
6964 } )
7065
7166 it ( 'formats item with set (alias)' , ( ) => {
72- const result = formatItem ( ) (
73- DefaultTable . User . schema . attributes ,
74- DefaultTable . User . linked ,
75- { set : new Set ( [ 1 , 2 , 3 ] ) }
76- )
67+ const result = formatItem ( ) ( DefaultTable . User . schema . attributes , DefaultTable . User . linked , {
68+ set : new Set ( [ 1 , 2 , 3 ] )
69+ } )
7770 expect ( result ) . toEqual ( { set_alias : [ 1 , 2 , 3 ] } )
7871 } )
7972
8073 it ( 'formats item with set (map)' , ( ) => {
81- const result = formatItem ( ) (
82- DefaultTable . User . schema . attributes ,
83- DefaultTable . User . linked ,
84- { set2 : new Set ( [ 1 , 2 , 3 ] ) }
85- )
74+ const result = formatItem ( ) ( DefaultTable . User . schema . attributes , DefaultTable . User . linked , {
75+ set2 : new Set ( [ 1 , 2 , 3 ] )
76+ } )
8677 expect ( result ) . toEqual ( { set_alias2 : [ 1 , 2 , 3 ] } )
8778 } )
8879
8980 it ( 'formats item with linked fields' , ( ) => {
90- const result = formatItem ( ) (
91- DefaultTable . User . schema . attributes ,
92- DefaultTable . User . linked ,
93- { sk : 'test1#test2' }
94- )
81+ const result = formatItem ( ) ( DefaultTable . User . schema . attributes , DefaultTable . User . linked , {
82+ sk : 'test1#test2'
83+ } )
9584 expect ( result ) . toEqual ( { sk : 'test1#test2' , linked1 : 'test1' , linked2 : 'test2' } )
9685 } )
9786
87+ it ( 'formats item with wrapped numbers' , ( ) => {
88+ const result = formatItem ( ) ( DefaultTable . User . schema . attributes , DefaultTable . User . linked , {
89+ number : { value : '1' } ,
90+ numberSet : new Set ( [
91+ {
92+ value : '1'
93+ } ,
94+ {
95+ value : '2'
96+ } ,
97+ {
98+ value : '3'
99+ }
100+ ] ) ,
101+ bigint : { value : '1' } ,
102+ bigintSet : new Set ( [
103+ {
104+ value : '11234567899999999'
105+ } ,
106+ {
107+ value : '11234567899999999'
108+ } ,
109+ {
110+ value : '11234567899999999'
111+ }
112+ ] )
113+ } )
114+
115+ expect ( result ) . toMatchInlineSnapshot ( `
116+ {
117+ "bigint": 1n,
118+ "bigintSet": [
119+ 11234567899999999n,
120+ 11234567899999999n,
121+ 11234567899999999n,
122+ ],
123+ "number": 1,
124+ "numberSet": [
125+ 1,
126+ 2,
127+ 3,
128+ ],
129+ }
130+ ` )
131+ } )
132+
98133 it ( 'specifies attributes to include' , ( ) => {
99134 const result = formatItem ( ) (
100135 DefaultTable . User . schema . attributes ,
@@ -126,11 +161,9 @@ describe('formatItem', () => {
126161 } )
127162
128163 it ( 'formats item with linked aliased composite field' , ( ) => {
129- const result = formatItem ( ) (
130- DefaultTable . User . schema . attributes ,
131- DefaultTable . User . linked ,
132- { composite1 : 'test1#test2' }
133- )
164+ const result = formatItem ( ) ( DefaultTable . User . schema . attributes , DefaultTable . User . linked , {
165+ composite1 : 'test1#test2'
166+ } )
134167 expect ( result ) . toEqual ( {
135168 composite1_alias : 'test1#test2' ,
136169 linked3 : 'test1' ,
@@ -139,11 +172,9 @@ describe('formatItem', () => {
139172 } )
140173
141174 it ( 'formats item with linked mapped composite field' , ( ) => {
142- const result = formatItem ( ) (
143- DefaultTable . User . schema . attributes ,
144- DefaultTable . User . linked ,
145- { composite2 : 'test1#test2' }
146- )
175+ const result = formatItem ( ) ( DefaultTable . User . schema . attributes , DefaultTable . User . linked , {
176+ composite2 : 'test1#test2'
177+ } )
147178 expect ( result ) . toEqual ( {
148179 composite2_alias : 'test1#test2' ,
149180 linked5 : 'test1' ,
@@ -152,20 +183,16 @@ describe('formatItem', () => {
152183 } )
153184
154185 it ( 'passes through attribute not specified in entity' , ( ) => {
155- const result = formatItem ( ) (
156- DefaultTable . User . schema . attributes ,
157- DefaultTable . User . linked ,
158- { unspecified : 'value' }
159- )
186+ const result = formatItem ( ) ( DefaultTable . User . schema . attributes , DefaultTable . User . linked , {
187+ unspecified : 'value'
188+ } )
160189 expect ( result ) . toEqual ( { unspecified : 'value' } )
161190 } )
162191
163192 it ( 'passes through null attribute' , ( ) => {
164- const result = formatItem ( ) (
165- DefaultTable . User . schema . attributes ,
166- DefaultTable . User . linked ,
167- { number : null }
168- )
193+ const result = formatItem ( ) ( DefaultTable . User . schema . attributes , DefaultTable . User . linked , {
194+ number : null
195+ } )
169196 expect ( result ) . toEqual ( { number : null } )
170197 } )
171198} )
0 commit comments