11import * as chai from 'chai' ;
22import { expect } from 'chai' ;
3+ import { describe , test } from 'node:test' ;
34import Jsona from '../src' ;
45
56import {
@@ -31,95 +32,95 @@ chai.config.truncateThreshold = 0;
3132describe ( 'Jsona' , ( ) => {
3233 const jsona = new Jsona ( ) ;
3334
34- it ( 'should instantiate with fallback property mappers' , ( ) => {
35+ test ( 'should instantiate with fallback property mappers' , ( ) => {
3536 let jsona = new Jsona ( ) ;
3637 } ) ;
3738
3839 describe ( 'serialize' , ( ) => {
39- it ( 'should throw Error if stuff is not passed' , ( ) => {
40+ test ( 'should throw Error if stuff is not passed' , ( ) => {
4041 expect ( jsona . serialize . bind ( jsona , null ) ) . to . throw ( Error ) ;
4142 expect ( jsona . serialize . bind ( jsona , undefined ) ) . to . throw ( Error ) ;
4243 expect ( jsona . serialize . bind ( jsona , { stuff : null } ) ) . to . throw ( Error ) ;
4344 } ) ;
4445
45- it ( 'should build json with item, without included' , ( ) => {
46+ test ( 'should build json with item, without included' , ( ) => {
4647 const jsonBody = jsona . serialize ( { stuff : town1 . model } ) ;
4748 expect ( jsonBody . data ) . to . be . deep . equal ( town1 . json ) ;
4849 expect ( jsonBody . included ) . to . be . equal ( undefined ) ;
4950 } ) ;
5051
51- it ( 'should build json with collection, with included' , ( ) => {
52+ test ( 'should build json with collection, with included' , ( ) => {
5253 const jsonBody = jsona . serialize ( { stuff : user2 . model , includeNames : [ 'specialty' , 'town.country' ] } ) ;
5354 expect ( jsonBody . data ) . to . be . deep . equal ( user2 . json ) ;
5455 expect ( jsonBody . included ) . to . be . deep . equal ( [ specialty1 . json , specialty2 . json , town2 . json , country2 . json ] ) ;
5556 } ) ;
5657
57- it ( 'should build json with collection, with included resources that do not have ids' , ( ) => {
58+ test ( 'should build json with collection, with included resources that do not have ids' , ( ) => {
5859 const jsonBody = jsona . serialize ( { stuff : userWithIdlessSpecialties . model , includeNames : [ 'specialtyWithoutIds' ] } ) ;
5960 expect ( jsonBody . included ) . to . be . deep . equal ( [ idlessSpecialty1 . json , idlessSpecialty2 . json ] ) ;
6061 } ) ;
6162
62- it ( 'should build json and save null relationships' , ( ) => {
63+ test ( 'should build json and save null relationships' , ( ) => {
6364 const jsonBody = jsona . serialize ( { stuff : withNullRelationsMock . collection } ) ;
6465 expect ( jsonBody . data ) . to . be . deep . equal ( withNullRelationsMock . json ) ;
6566 } ) ;
6667 } ) ;
6768
6869 describe ( 'deserialize' , ( ) => {
69- it ( 'should throw Error if body is not passed' , ( ) => {
70+ test ( 'should throw Error if body is not passed' , ( ) => {
7071 expect ( jsona . deserialize . bind ( jsona , null ) ) . to . throw ( Error ) ;
7172 expect ( jsona . deserialize . bind ( jsona , undefined ) ) . to . throw ( Error ) ;
7273 } ) ;
7374
74- it ( 'should deserialize item without included' , ( ) => {
75+ test ( 'should deserialize item without included' , ( ) => {
7576 const userModel = jsona . deserialize ( { data : user2 . json } ) ;
7677 expect ( userModel ) . to . be . deep . equal ( user2 . modelWithoutIncluded ) ;
7778 } ) ;
7879
79- it ( 'should deserialize collection with included' , ( ) => {
80+ test ( 'should deserialize collection with included' , ( ) => {
8081 const townsCollection = jsona . deserialize ( {
8182 data : [ town1 . json , town2 . json ] ,
8283 included : [ country1 . json , country2 . json ]
8384 } ) ;
8485 expect ( townsCollection ) . to . be . deep . equal ( [ town1 . model , town2 . model ] ) ;
8586 } ) ;
8687
87- it ( 'should deserialize json with circular relationships' , ( ) => {
88+ test ( 'should deserialize json with circular relationships' , ( ) => {
8889 const recursiveItem = jsona . deserialize ( circular . json ) ;
8990 expect ( recursiveItem ) . to . be . deep . equal ( circular . model ) ;
9091 } ) ;
9192
92- it ( 'should deserialize json with meta & circular relationships' , ( ) => {
93+ test ( 'should deserialize json with meta & circular relationships' , ( ) => {
9394 const recursiveItem = jsona . deserialize ( circularWithMeta . json ) ;
9495 expect ( recursiveItem ) . to . be . deep . equal ( circularWithMeta . model ) ;
9596 } ) ;
9697
97- it ( 'should deserialize json with duplicate relationships' , ( ) => {
98+ test ( 'should deserialize json with duplicate relationships' , ( ) => {
9899 const duplicateItem = jsona . deserialize ( duplicate . json , { preferNestedDataFromData : true } ) ;
99100 expect ( duplicateItem ) . to . be . deep . equal ( duplicate . model ) ;
100101 } ) ;
101102
102- it ( 'should deserialize json with data without root ids' , ( ) => {
103+ test ( 'should deserialize json with data without root ids' , ( ) => {
103104 const collectionWithoutRootIds = jsona . deserialize ( { data : withoutRootIdsMock . json } ) ;
104105 expect ( collectionWithoutRootIds ) . to . be . deep . equal ( withoutRootIdsMock . collection ) ;
105106 } ) ;
106107
107- it ( 'should deserialize json and save null relationships' , ( ) => {
108+ test ( 'should deserialize json and save null relationships' , ( ) => {
108109 const collectionWithNullRelations = jsona . deserialize ( { data : withNullRelationsMock . json } ) ;
109110 expect ( collectionWithNullRelations ) . to . be . deep . equal ( withNullRelationsMock . collection ) ;
110111 } ) ;
111112
112- it ( 'should deserialize resource id object meta field into resourceIdObjMeta' , ( ) => {
113+ test ( 'should deserialize resource id object meta field into resourceIdObjMeta' , ( ) => {
113114 const stuff = jsona . deserialize ( resourceIdObjMetaMock . json ) ;
114115 expect ( stuff ) . to . be . deep . equal ( resourceIdObjMetaMock . collection ) ;
115116 } ) ;
116117
117- it ( 'should deserialize with different attrs for root object and related' , ( ) => {
118+ test ( 'should deserialize with different attrs for root object and related' , ( ) => {
118119 const stuff = jsona . deserialize ( differentAttrsInDataAndIncludedMock . json ) ;
119120 expect ( stuff ) . to . be . deep . equal ( differentAttrsInDataAndIncludedMock . collection ) ;
120121 } ) ;
121122
122- it ( 'should new' , ( ) => {
123+ test ( 'should new' , ( ) => {
123124 const stuff = jsona . deserialize ( differentAttrsInDataAndIncludedMock . json ) ;
124125 expect ( stuff ) . to . be . deep . equal ( differentAttrsInDataAndIncludedMock . collection ) ;
125126 } ) ;
@@ -128,29 +129,29 @@ describe('Jsona', () => {
128129
129130 describe ( 'denormalizeReduxObject' , ( ) => {
130131
131- it ( 'should throw Error if reduxObject is not passed' , ( ) => {
132+ test ( 'should throw Error if reduxObject is not passed' , ( ) => {
132133 const denormalizeReduxObject = jsona . denormalizeReduxObject . bind ( jsona , {
133134 reduxObject : null ,
134135 } ) ;
135136 expect ( denormalizeReduxObject ) . to . throw ( Error , 'reduxObject' ) ;
136137 } ) ;
137138
138- it ( 'should throw Error if entityType is not passed' , ( ) => {
139+ test ( 'should throw Error if entityType is not passed' , ( ) => {
139140 const denormalizeReduxObject = jsona . denormalizeReduxObject . bind ( jsona , {
140141 reduxObject : { } ,
141142 } ) ;
142143 expect ( denormalizeReduxObject ) . to . throw ( Error , 'entityType' ) ;
143144 } ) ;
144145
145- it ( 'should return null if no such entityType in reduxObject' , ( ) => {
146+ test ( 'should return null if no such entityType in reduxObject' , ( ) => {
146147 const model = jsona . denormalizeReduxObject ( {
147148 reduxObject : { } ,
148149 entityType : 'myEntity'
149150 } ) ;
150151 expect ( model ) . to . be . equal ( null ) ;
151152 } ) ;
152153
153- it ( 'should return null if no such entityId in reduxObject' , ( ) => {
154+ test ( 'should return null if no such entityId in reduxObject' , ( ) => {
154155 const model = jsona . denormalizeReduxObject ( {
155156 reduxObject : reduxObject1 ,
156157 entityType : 'article' ,
@@ -159,7 +160,7 @@ describe('Jsona', () => {
159160 expect ( model ) . to . be . equal ( null ) ;
160161 } ) ;
161162
162- it ( 'should return collection of models if entityIds is Array' , ( ) => {
163+ test ( 'should return collection of models if entityIds is Array' , ( ) => {
163164 const models = jsona . denormalizeReduxObject ( {
164165 reduxObject : reduxObject1 ,
165166 returnBuilderInRelations : false ,
@@ -170,7 +171,7 @@ describe('Jsona', () => {
170171 expect ( models ) . to . be . deep . equal ( [ town1 . model , town2 . model ] ) ;
171172 } ) ;
172173
173- it ( 'should return collection of models if entityIds is not passed' , ( ) => {
174+ test ( 'should return collection of models if entityIds is not passed' , ( ) => {
174175 const models = jsona . denormalizeReduxObject ( {
175176 reduxObject : reduxObject1 ,
176177 returnBuilderInRelations : false ,
@@ -181,7 +182,7 @@ describe('Jsona', () => {
181182 } ) ;
182183
183184
184- it ( 'should denormalize json with circular relationships' , ( ) => {
185+ test ( 'should denormalize json with circular relationships' , ( ) => {
185186 const model = jsona . denormalizeReduxObject ( {
186187 reduxObject : reduxObjectWithCircular ,
187188 returnBuilderInRelations : false ,
@@ -191,7 +192,7 @@ describe('Jsona', () => {
191192 expect ( model ) . to . be . deep . equal ( circular . model ) ;
192193 } ) ;
193194
194- it ( 'should denormalize model with relationships' , ( ) => {
195+ test ( 'should denormalize model with relationships' , ( ) => {
195196 const model1 = jsona . denormalizeReduxObject ( {
196197 reduxObject : reduxObject1 ,
197198 returnBuilderInRelations : false ,
@@ -208,7 +209,7 @@ describe('Jsona', () => {
208209 expect ( model2 [ 'country' ] ) . to . be . deep . equal ( country1 . model ) ;
209210 } ) ;
210211
211- it ( 'should allow to set relationships before denormalization' , ( ) => {
212+ test ( 'should allow to set relationships before denormalization' , ( ) => {
212213 const model = jsona . denormalizeReduxObject ( {
213214 reduxObject : reduxObject1 ,
214215 returnBuilderInRelations : true ,
0 commit comments