@@ -55,13 +55,13 @@ describe('custom operations - apply traits v3', function() {
55
55
const v3Document = document as AsyncAPIDocumentV3 ;
56
56
expect ( v3Document ) . toBeInstanceOf ( AsyncAPIDocumentV3 ) ;
57
57
58
- const someOperation1 = v3Document ?. json ( ) ?. operations ?. someOperation1 ;
58
+ const someOperation1 = v3Document ?. json ( ) ?. operations ?. someOperation1 as v3 . OperationObject ;
59
59
delete someOperation1 ?. traits ;
60
- expect ( someOperation1 ) . toEqual ( { action : 'send' , channel : { 'x-parser-unique-object-id' : 'channel1' } , description : 'another description' } ) ;
60
+ expect ( someOperation1 ) . toEqual ( { action : 'send' , channel : { 'x-parser-unique-object-id' : 'channel1' } , description : 'another description' , 'x-parser-unique-object-id' : 'someOperation1' } ) ;
61
61
62
- const someOperation2 = v3Document ?. json ( ) ?. operations ?. someOperation2 ;
62
+ const someOperation2 = v3Document ?. json ( ) ?. operations ?. someOperation2 as v3 . OperationObject ;
63
63
delete someOperation2 ?. traits ;
64
- expect ( someOperation2 ) . toEqual ( { action : 'send' , channel : { 'x-parser-unique-object-id' : 'channel1' } , description : 'root description' } ) ;
64
+ expect ( someOperation2 ) . toEqual ( { action : 'send' , channel : { 'x-parser-unique-object-id' : 'channel1' } , description : 'root description' , 'x-parser-unique-object-id' : 'someOperation2' } ) ;
65
65
} ) ;
66
66
67
67
it ( 'should apply traits to messages (channels)' , async function ( ) {
@@ -111,11 +111,11 @@ describe('custom operations - apply traits v3', function() {
111
111
const v3Document = document as AsyncAPIDocumentV3 ;
112
112
expect ( v3Document ) . toBeInstanceOf ( AsyncAPIDocumentV3 ) ;
113
113
114
- const message1 = v3Document ?. json ( ) ?. channels ?. someChannel1 ? .messages ?. someMessage ;
114
+ const message1 = ( v3Document ?. json ( ) ?. channels ?. someChannel1 as v3 . ChannelObject ) . messages ?. someMessage ;
115
115
delete ( message1 as v3 . MessageObject ) ?. traits ;
116
116
expect ( message1 ) . toEqual ( { summary : 'some summary' , description : 'another description' , 'x-parser-message-name' : 'someMessage' , 'x-parser-unique-object-id' : 'someMessage' } ) ;
117
117
118
- const message2 = v3Document ?. json ( ) ?. channels ?. someChannel2 ? .messages ?. someMessage ;
118
+ const message2 = ( v3Document ?. json ( ) ?. channels ?. someChannel2 as v3 . ChannelObject ) . messages ?. someMessage ;
119
119
delete ( message2 as v3 . MessageObject ) ?. traits ;
120
120
expect ( message2 ) . toEqual ( { summary : 'root summary' , description : 'root description' , 'x-parser-message-name' : 'someMessage' , 'x-parser-unique-object-id' : 'someMessage' } ) ;
121
121
} ) ;
@@ -163,14 +163,14 @@ describe('custom operations - apply traits v3', function() {
163
163
164
164
const message1 = v3Document ?. json ( ) ?. components ?. messages ?. someMessage1 ;
165
165
delete ( message1 as v3 . MessageObject ) ?. traits ;
166
- expect ( message1 ) . toEqual ( { summary : 'some summary' , description : 'another description' , 'x-parser-message-name' : 'someMessage1' } ) ;
166
+ expect ( message1 ) . toEqual ( { summary : 'some summary' , description : 'another description' , 'x-parser-message-name' : 'someMessage1' , 'x-parser-unique-object-id' : 'someMessage1' } ) ;
167
167
168
168
const message2 = v3Document ?. json ( ) ?. components ?. messages ?. someMessage2 ;
169
169
delete ( message2 as v3 . MessageObject ) ?. traits ;
170
- expect ( message2 ) . toEqual ( { summary : 'root summary' , description : 'root description' , 'x-parser-message-name' : 'someMessage2' } ) ;
170
+ expect ( message2 ) . toEqual ( { summary : 'root summary' , description : 'root description' , 'x-parser-message-name' : 'someMessage2' , 'x-parser-unique-object-id' : 'someMessage2' } ) ;
171
171
} ) ;
172
172
173
- it ( 'iterative functions should still work after traits have been applied' , async function ( ) {
173
+ describe ( 'iterative functions should still work after traits have been applied' , function ( ) {
174
174
const documentRaw = {
175
175
asyncapi : '3.0.0' ,
176
176
info : {
@@ -187,7 +187,7 @@ describe('custom operations - apply traits v3', function() {
187
187
'smartylighting.streetlights.1.0.event.{streetlightId}.lighting.measured' : {
188
188
address : 'smartylighting.streetlights.1.0.event.{streetlightId}.lighting.measured' ,
189
189
messages : {
190
- 'receiveLightMeasurement.message' : {
190
+ lightMeasured : {
191
191
$ref : '#/components/messages/lightMeasured'
192
192
}
193
193
} ,
@@ -213,7 +213,7 @@ describe('custom operations - apply traits v3', function() {
213
213
] ,
214
214
messages : [
215
215
{
216
- $ref : '#/components /messages/lightMeasured'
216
+ $ref : '#/channels/smartylighting.streetlights.1.0.event.{streetlightId}.lighting.measured /messages/lightMeasured'
217
217
}
218
218
]
219
219
}
@@ -290,32 +290,64 @@ describe('custom operations - apply traits v3', function() {
290
290
}
291
291
}
292
292
} ;
293
- const { document } = await parser . parse ( documentRaw ) ;
294
-
295
- const v3Document = document as AsyncAPIDocumentV3 ;
296
- expect ( v3Document ) . toBeInstanceOf ( AsyncAPIDocumentV3 ) ;
293
+ let v3Document : AsyncAPIDocumentV3 ;
297
294
const expectedOperationId = 'receiveLightMeasurement' ;
298
295
const expectedChannelId = 'smartylighting.streetlights.1.0.event.{streetlightId}.lighting.measured' ;
299
- const operations = v3Document . operations ( ) ;
300
- expect ( operations . length ) . toEqual ( 1 ) ;
301
- const operation = operations [ 0 ] ;
302
- expect ( operation . id ( ) ) . toEqual ( expectedOperationId ) ;
303
- const operationChannels = operation . channels ( ) . all ( ) ;
304
- expect ( operationChannels . length ) . toEqual ( 1 ) ;
305
- const lightMeasuredChannel = operationChannels [ 0 ] ;
306
- expect ( lightMeasuredChannel . json ( ) [ xParserObjectUniqueId ] ) . toEqual ( expectedChannelId ) ;
307
- const channelOperations = lightMeasuredChannel . operations ( ) . all ( ) ;
308
- expect ( channelOperations . length ) . toEqual ( 1 ) ;
309
- const circularOperation = channelOperations [ 0 ] ;
310
- expect ( circularOperation . id ( ) ) . toEqual ( expectedOperationId ) ;
296
+ const expectedMessageId = 'lightMeasured' ;
297
+
298
+ beforeAll ( async ( ) => {
299
+ const { document, diagnostics } = await parser . parse ( documentRaw ) ;
300
+ expect ( diagnostics . length ) . toEqual ( 0 ) ;
301
+ v3Document = document as AsyncAPIDocumentV3 ;
302
+ } ) ;
303
+
304
+ it ( 'should be able to go from operation -> channel' , ( ) => {
305
+ const operations = v3Document . operations ( ) . all ( ) ;
306
+ expect ( operations . length ) . toEqual ( 1 ) ;
307
+ const operation = operations [ 0 ] ;
308
+ expect ( operation . id ( ) ) . toEqual ( expectedOperationId ) ;
309
+ const operationChannels = operation . channels ( ) . all ( ) ;
310
+ expect ( operationChannels . length ) . toEqual ( 1 ) ;
311
+ const lightMeasuredChannel = operationChannels [ 0 ] ;
312
+ expect ( lightMeasuredChannel . json ( ) [ xParserObjectUniqueId ] ) . toEqual ( expectedChannelId ) ;
313
+ const messages = lightMeasuredChannel . messages ( ) . all ( ) ;
314
+ expect ( messages . length ) . toEqual ( 1 ) ;
315
+ const message = messages [ 0 ] ;
316
+ expect ( message . id ( ) ) . toEqual ( expectedMessageId ) ;
317
+ } ) ;
318
+
319
+ it ( 'should be able to go from channel -> operation' , ( ) => {
320
+ const channels = v3Document . channels ( ) . all ( ) ;
321
+ expect ( channels . length ) . toEqual ( 1 ) ;
322
+ const channel = channels [ 0 ] ;
323
+ expect ( channel . json ( ) [ xParserObjectUniqueId ] ) . toEqual ( expectedChannelId ) ;
324
+ const channelOperations = channel . operations ( ) . all ( ) ;
325
+ expect ( channelOperations . length ) . toEqual ( 1 ) ;
326
+ const operation = channelOperations [ 0 ] ;
327
+ expect ( operation . id ( ) ) . toEqual ( expectedOperationId ) ;
328
+ const messages = operation . messages ( ) . all ( ) ;
329
+ expect ( messages . length ) . toEqual ( 1 ) ;
330
+ const message = messages [ 0 ] ;
331
+ expect ( message . id ( ) ) . toEqual ( expectedMessageId ) ;
332
+ } ) ;
311
333
312
- const channels = v3Document . channels ( ) ;
313
- expect ( channels . length ) . toEqual ( 1 ) ;
314
- const channel = channels [ 0 ] ;
315
- expect ( channel . json ( ) [ xParserObjectUniqueId ] ) . toEqual ( expectedChannelId ) ;
316
- const channelOperations2 = channel . operations ( ) . all ( ) ;
317
- expect ( channelOperations2 . length ) . toEqual ( 1 ) ;
318
- const operation2 = channelOperations2 [ 0 ] ;
319
- expect ( operation2 . id ( ) ) . toEqual ( expectedOperationId ) ;
334
+ it ( 'should be able to go in full circle operation -> channel -> operation' , ( ) => {
335
+ const operations = v3Document . operations ( ) . all ( ) ;
336
+ expect ( operations . length ) . toEqual ( 1 ) ;
337
+ const operation = operations [ 0 ] ;
338
+ expect ( operation . id ( ) ) . toEqual ( expectedOperationId ) ;
339
+ const operationChannels = operation . channels ( ) . all ( ) ;
340
+ expect ( operationChannels . length ) . toEqual ( 1 ) ;
341
+ const lightMeasuredChannel = operationChannels [ 0 ] ;
342
+ expect ( lightMeasuredChannel . json ( ) [ xParserObjectUniqueId ] ) . toEqual ( expectedChannelId ) ;
343
+ const channelOperations = lightMeasuredChannel . operations ( ) . all ( ) ;
344
+ expect ( channelOperations . length ) . toEqual ( 1 ) ;
345
+ const circularOperation = channelOperations [ 0 ] ;
346
+ expect ( circularOperation . id ( ) ) . toEqual ( expectedOperationId ) ;
347
+ const messages = circularOperation . messages ( ) . all ( ) ;
348
+ expect ( messages . length ) . toEqual ( 1 ) ;
349
+ const message = messages [ 0 ] ;
350
+ expect ( message . id ( ) ) . toEqual ( expectedMessageId ) ;
351
+ } ) ;
320
352
} ) ;
321
353
} ) ;
0 commit comments