@@ -5,6 +5,8 @@ import {assert} from "chai";
55import { describe , it } from "node:test" ;
66
77import type { User as IUser , Friend as IFriend } from "./models/User" ;
8+ import type { UserSimple as IUserSimple , FriendSimple as IFriendSimple } from "./models/UserSimple" ;
9+ import { fromJSON } from "../src/functions/FromJSON" ;
810
911describe ( "Base functions" , ( ) => {
1012 it ( "user from method fromJSON must be instance of User" , async ( ) => {
@@ -13,7 +15,7 @@ describe("Base functions", () => {
1315
1416 const [ object ] = Reflect . get ( json , "default" ) as typeof json ;
1517
16- const user = new User ( ) . fromJSON ( object ) ;
18+ const user : IUser = new User ( ) . fromJSON ( object ) ;
1719
1820 assert . isTrue ( user instanceof User ) ;
1921 assert . strictEqual ( user . id , object . id , "id is not equal" ) ;
@@ -81,7 +83,7 @@ describe("Base functions", () => {
8183 const json = await import ( "./jsons/json-generator.json" , { with : { type : "json" } } ) ;
8284 const [ object ] = Reflect . get ( json , "default" ) as typeof json ;
8385
84- const user = new User ( ) . fromString ( JSON . stringify ( object ) ) ;
86+ const user : IUser = new User ( ) . fromString ( JSON . stringify ( object ) ) ;
8587
8688 assert . isTrue ( user instanceof User ) ;
8789 assert . strictEqual ( user . id , object . id , "id is not equal" ) ;
@@ -143,4 +145,39 @@ describe("Base functions", () => {
143145 assert . strictEqual ( friend . name , object . friends [ index ] . name , `friend ${ String ( index ) } name is not equal` ) ;
144146 } ) ;
145147 } ) ;
148+
149+ it ( "user from function fromJSON must be instance of User" , async ( ) => {
150+ const { UserSimple} = await import ( "./models/UserSimple" ) ;
151+ const json = await import ( "./jsons/json-generator.json" , { with : { type : "json" } } ) ;
152+
153+ const [ object ] = Reflect . get ( json , "default" ) as typeof json ;
154+
155+ const user : IUserSimple = fromJSON ( new UserSimple ( ) , object ) ;
156+
157+ assert . isTrue ( user instanceof UserSimple ) ;
158+ assert . strictEqual ( user . id , object . id , "id is not equal" ) ;
159+ assert . strictEqual ( user . index , object . index , "index is not equal" ) ;
160+ assert . strictEqual ( user . guid , object . guid , "guid is not equal" ) ;
161+ assert . strictEqual ( user . isActive , object . isActive , "isActive is not equal" ) ;
162+ assert . strictEqual ( user . balance , object . balance , "balance is not equal" ) ;
163+ assert . strictEqual ( user . picture , object . picture , "picture is not equal" ) ;
164+ assert . strictEqual ( user . age , object . age , "age is not equal" ) ;
165+ assert . strictEqual ( user . eyeColor , object . eyeColor , "eyeColor is not equal" ) ;
166+ assert . strictEqual ( user . name , object . name , "name is not equal" ) ;
167+ assert . strictEqual ( user . company , object . company , "company is not equal" ) ;
168+ assert . strictEqual ( user . email , object . email , "email is not equal" ) ;
169+ assert . strictEqual ( user . phone , object . phone , "phone is not equal" ) ;
170+ assert . strictEqual ( user . address , object . address , "address is not equal" ) ;
171+ assert . strictEqual ( user . about , object . about , "about is not equal" ) ;
172+ assert . strictEqual ( user . latitude , object . latitude , "latitude is not equal" ) ;
173+ assert . strictEqual ( user . longitude , object . longitude , "longitude is not equal" ) ;
174+ assert . deepEqual ( user . tags , object . tags , "tags is not equal" ) ;
175+ assert . strictEqual ( user . greeting , object . greeting , "greeting is not equal" ) ;
176+ assert . strictEqual ( user . favoriteFruit , object . favoriteFruit , "favoriteFruit is not equal" ) ;
177+
178+ user . friends . forEach ( ( friend : IFriendSimple , index : number ) => {
179+ assert . strictEqual ( friend . id , object . friends [ index ] . id , `friend ${ String ( index ) } id is not equal` ) ;
180+ assert . strictEqual ( friend . name , object . friends [ index ] . name , `friend ${ String ( index ) } name is not equal` ) ;
181+ } ) ;
182+ } ) ;
146183} ) ;
0 commit comments