1
- import { newAsyncAPIDocument } from '../../../src/models' ;
2
- import { V2AsyncAPIDocument } from '../../../src/models/v2/asyncapi' ;
3
- import { V2Info } from '../../../src/models/v2/info' ;
1
+ import { newAsyncAPIDocument , V2AsyncAPIDocument , V2Info , V3AsyncAPIDocument } from '../../../src/models' ;
4
2
5
3
describe ( 'AsyncAPIDocument model' , function ( ) {
6
- it ( 'should create a valid document' , function ( ) {
7
- const doc = { asyncapi : "2.0.0" } ;
8
- const d = newAsyncAPIDocument ( doc )
9
- expect ( d . version ( ) ) . toEqual ( doc . asyncapi ) ;
10
- } ) ;
11
4
describe ( '.version()' , function ( ) {
12
5
it ( 'should return the value' , function ( ) {
13
6
const doc = { asyncapi : "3.0.0" } ;
@@ -30,3 +23,22 @@ describe('AsyncAPIDocument model', function() {
30
23
} ) ;
31
24
} ) ;
32
25
} ) ;
26
+
27
+ describe ( 'AsyncAPIDocument factory' , function ( ) {
28
+ it ( 'should create a valid document from v2.0.0' , function ( ) {
29
+ const doc = { asyncapi : "2.0.0" } ;
30
+ const d = newAsyncAPIDocument ( doc )
31
+ expect ( d . version ( ) ) . toEqual ( doc . asyncapi ) ;
32
+ expect ( d ) . toBeInstanceOf ( V2AsyncAPIDocument ) ;
33
+ } ) ;
34
+ it ( 'should create a valid document from v3.0.0' , function ( ) {
35
+ const doc = { asyncapi : "3.0.0" } ;
36
+ const d = newAsyncAPIDocument ( doc )
37
+ expect ( d . version ( ) ) . toEqual ( doc . asyncapi ) ;
38
+ expect ( d ) . toBeInstanceOf ( V3AsyncAPIDocument ) ;
39
+ } ) ;
40
+ it ( 'should fail trying to create a document from a non supported spec version' , function ( ) {
41
+ const doc = { asyncapi : "99.99.99" } ;
42
+ expect ( ( ) => newAsyncAPIDocument ( doc ) ) . toThrow ( "Unsupported version: 99.99.99" ) ;
43
+ } ) ;
44
+ } ) ;
0 commit comments