1
+ import { TestAnchor , TestOverlay } from '../../../../test/helpers/test-classes.js' ;
1
2
import { ModelSerializedOutput } from '../../../app.type.js' ;
2
3
import { Container } from '../../../decorators/container.js' ;
3
4
import { IDependency } from '../../../functions/dependency/dependency.js' ;
@@ -9,13 +10,16 @@ import { Server } from '../../../models/server/server.model.js';
9
10
import { Service } from '../../../models/service/service.model.js' ;
10
11
import { Subnet } from '../../../models/subnet/subnet.model.js' ;
11
12
import { OverlayDataRepository , OverlayDataRepositoryFactory } from '../../../overlays/overlay-data.repository.js' ;
13
+ import { OverlayService , OverlayServiceFactory } from '../../../overlays/overlay.service.js' ;
12
14
import { ModelSerializationService , ModelSerializationServiceFactory } from './model-serialization.service.js' ;
13
15
14
16
describe ( 'Model Serialization Service UT' , ( ) => {
15
17
beforeEach ( ( ) => {
16
18
Container . registerFactory ( OverlayDataRepository , OverlayDataRepositoryFactory ) ;
17
19
Container . get ( OverlayDataRepository , { args : [ true , [ ] , [ ] ] } ) ;
18
20
21
+ Container . registerFactory ( OverlayService , OverlayServiceFactory ) ;
22
+
19
23
Container . registerFactory ( ModelSerializationService , ModelSerializationServiceFactory ) ;
20
24
Container . get ( ModelSerializationService , { args : [ true ] } ) ;
21
25
} ) ;
@@ -97,6 +101,18 @@ describe('Model Serialization Service UT', () => {
97
101
expect ( app1 . name ) . toBe ( 'test-app' ) ;
98
102
} ) ;
99
103
104
+ it ( 'should deserialize a single model' , async ( ) => {
105
+ const app_0 = new App ( 'test-app' ) ;
106
+
107
+ const service = await Container . get ( ModelSerializationService ) ;
108
+ service . registerClass ( 'App' , App ) ;
109
+
110
+ const output = await service . serialize ( app_0 ) ;
111
+ const app_1 = ( await service . deserialize ( output ) ) as App ;
112
+
113
+ expect ( app_1 . name ) . toBe ( 'test-app' ) ;
114
+ } ) ;
115
+
100
116
it ( 'should return the serialized root on deserialization' , async ( ) => {
101
117
const app0 = new App ( 'test-app' ) ;
102
118
const region0 = new Region ( 'region-0' ) ;
@@ -142,6 +158,31 @@ describe('Model Serialization Service UT', () => {
142
158
) ;
143
159
expect ( newAppDependencies ) . toEqual ( oldAppDependencies ) ;
144
160
} ) ;
161
+
162
+ it ( 'should deserialize overlay with multiple anchors of same parent' , async ( ) => {
163
+ const app_0 = new App ( 'test-app' ) ;
164
+ const anchor1 = new TestAnchor ( 'anchor-1' , app_0 ) ;
165
+ const anchor2 = new TestAnchor ( 'anchor-2' , app_0 ) ;
166
+ app_0 [ 'anchors' ] . push ( anchor1 , anchor2 ) ;
167
+
168
+ const service = await Container . get ( ModelSerializationService ) ;
169
+ service . registerClass ( 'App' , App ) ;
170
+ service . registerClass ( 'TestAnchor' , TestAnchor ) ;
171
+ service . registerClass ( 'TestOverlay' , TestOverlay ) ;
172
+ const overlayService = await Container . get ( OverlayService ) ;
173
+
174
+ const overlay1_0 = new TestOverlay ( 'overlay-1' , { } , [ anchor1 , anchor2 ] ) ;
175
+ await overlayService . addOverlay ( overlay1_0 ) ;
176
+
177
+ const appSerialized = await service . serialize ( app_0 ) ;
178
+ const app_1 = ( await service . deserialize ( appSerialized ) ) as App ;
179
+
180
+ const overlay1_1 = await overlayService . getOverlayById ( 'overlay-1' ) ;
181
+ expect ( overlay1_1 ! . getAnchors ( ) . map ( ( a ) => a . getParent ( ) . getContext ( ) ) ) . toEqual ( [
182
+ app_1 . getContext ( ) ,
183
+ app_1 . getContext ( ) ,
184
+ ] ) ;
185
+ } ) ;
145
186
} ) ;
146
187
147
188
describe ( 'serialize()' , ( ) => {
@@ -197,5 +238,20 @@ describe('Model Serialization Service UT', () => {
197
238
198
239
expect ( await service . serialize ( app ) ) . toMatchSnapshot ( ) ;
199
240
} ) ;
241
+
242
+ it ( 'should serialize overlay with multiple anchors of same parent' , async ( ) => {
243
+ const service = await Container . get ( ModelSerializationService ) ;
244
+ const overlayService = await Container . get ( OverlayService ) ;
245
+
246
+ const app = new App ( 'test-app' ) ;
247
+ const anchor1 = new TestAnchor ( 'anchor-1' , app ) ;
248
+ const anchor2 = new TestAnchor ( 'anchor-2' , app ) ;
249
+ app [ 'anchors' ] . push ( anchor1 , anchor2 ) ;
250
+
251
+ const overlay1 = new TestOverlay ( 'overlay-1' , { } , [ anchor1 , anchor2 ] ) ;
252
+ await overlayService . addOverlay ( overlay1 ) ;
253
+
254
+ expect ( await service . serialize ( app ) ) . toMatchSnapshot ( ) ;
255
+ } ) ;
200
256
} ) ;
201
257
} ) ;
0 commit comments