@@ -11,6 +11,7 @@ import { Servers } from '../../../src/models/v3/servers';
11
11
import { serializeInput , assertExtensions } from './utils' ;
12
12
13
13
import type { v3 } from '../../../src/spec-types' ;
14
+ import { Collection } from '../../../src/models' ;
14
15
15
16
describe ( 'AsyncAPIDocument model' , function ( ) {
16
17
describe ( '.version()' , function ( ) {
@@ -164,6 +165,130 @@ describe('AsyncAPIDocument model', function() {
164
165
} ) ;
165
166
} ) ;
166
167
168
+ describe ( '.allMessages()' , function ( ) {
169
+ it ( 'should return a collection of messages' , function ( ) {
170
+ const duplicatedMessage = { } ;
171
+ const doc = serializeInput < v3 . AsyncAPIObject > ( { channels : { userSignup : { address : 'user/signup' , messages : { someMessage1 : { } , someMessage2 : duplicatedMessage } } , userLogout : { address : 'user/logout' , messages : { someMessage3 : duplicatedMessage } } } } ) ;
172
+ const d = new AsyncAPIDocument ( doc ) ;
173
+ expect ( d . allMessages ( ) . all ( ) ) . toBeInstanceOf ( Array ) ;
174
+ expect ( d . allMessages ( ) . all ( ) ) . not . toBeInstanceOf ( Collection ) ;
175
+ expect ( d . allMessages ( ) ) . toBeInstanceOf ( Messages ) ;
176
+ expect ( d . allMessages ( ) ) . toHaveLength ( 2 ) ;
177
+ } ) ;
178
+
179
+ it ( 'should return all messages (with messages from components)' , function ( ) {
180
+ const duplicatedMessage = { } ;
181
+ const doc = serializeInput < v3 . AsyncAPIObject > ( { channels : { userSignup : { address : 'user/signup' , messages : { someMessage1 : { } , someMessage2 : duplicatedMessage } } , userLogout : { address : 'user/logout' , messages : { someMessage3 : duplicatedMessage } } } , components : { messages : { someMessage4 : { } , someMessage5 : { } } } } ) ;
182
+ const d = new AsyncAPIDocument ( doc ) ;
183
+ expect ( d . allMessages ( ) ) . toBeInstanceOf ( Messages ) ;
184
+ expect ( d . allMessages ( ) ) . toHaveLength ( 4 ) ;
185
+ } ) ;
186
+
187
+ it ( 'should return a collection of messages even if messages are not defined' , function ( ) {
188
+ const doc = serializeInput < v3 . AsyncAPIObject > ( { } ) ;
189
+ const d = new AsyncAPIDocument ( doc ) ;
190
+ expect ( d . allMessages ( ) ) . toBeInstanceOf ( Messages ) ;
191
+ } ) ;
192
+ } ) ;
193
+
194
+ describe ( '.allSchemas()' , function ( ) {
195
+ it ( 'should return a collection of schemas' , function ( ) {
196
+ const doc = serializeInput < v3 . AsyncAPIObject > ( { channels : { userSignup : { address : 'user/signup' , messages : { someMessage1 : { payload : { } } , someMessage2 : { payload : { } } } } , userLogout : { address : 'user/logout' , messages : { someMessage3WithoutPayload : { } } } } } ) ;
197
+ const d = new AsyncAPIDocument ( doc ) ;
198
+ expect ( d . allSchemas ( ) ) . toBeInstanceOf ( Schemas ) ;
199
+ expect ( d . allSchemas ( ) . all ( ) ) . toBeInstanceOf ( Array ) ;
200
+ expect ( d . allSchemas ( ) . all ( ) ) . not . toBeInstanceOf ( Collection ) ;
201
+ expect ( d . allSchemas ( ) ) . toHaveLength ( 2 ) ;
202
+ } ) ;
203
+
204
+ it ( 'should return all schemas (with schemas from components)' , function ( ) {
205
+ const doc = serializeInput < v3 . AsyncAPIObject > ( { channels : { userSignup : { address : 'user/signup' , messages : { someMessage1 : { payload : { } } , someMessage2 : { payload : { } } } } } , components : { schemas : { schemaOne : { } , schemaTwo : { } } } } ) ;
206
+ const d = new AsyncAPIDocument ( doc ) ;
207
+ expect ( d . allSchemas ( ) ) . toBeInstanceOf ( Schemas ) ;
208
+ expect ( d . allSchemas ( ) ) . toHaveLength ( 4 ) ;
209
+ } ) ;
210
+
211
+ it ( 'should return a collection of schemas even if collection is empty' , function ( ) {
212
+ const doc = serializeInput < v3 . AsyncAPIObject > ( { } ) ;
213
+ const d = new AsyncAPIDocument ( doc ) ;
214
+ expect ( d . allSchemas ( ) ) . toBeInstanceOf ( Schemas ) ;
215
+ } ) ;
216
+ } ) ;
217
+
218
+ describe ( '.allServers()' , function ( ) {
219
+ it ( 'should return a collection of servers' , function ( ) {
220
+ const doc = serializeInput < v3 . AsyncAPIObject > ( { servers : { development : { } } } ) ;
221
+ const d = new AsyncAPIDocument ( doc ) ;
222
+ expect ( d . allServers ( ) ) . toBeInstanceOf ( Servers ) ;
223
+ expect ( d . allServers ( ) . all ( ) ) . toBeInstanceOf ( Array ) ;
224
+ expect ( d . allServers ( ) . all ( ) ) . not . toBeInstanceOf ( Collection ) ;
225
+ expect ( d . allServers ( ) ) . toHaveLength ( 1 ) ;
226
+ expect ( d . allServers ( ) . all ( ) [ 0 ] . id ( ) ) . toEqual ( 'development' ) ;
227
+ } ) ;
228
+
229
+ it ( 'should return all servers (with servers from components)' , function ( ) {
230
+ const doc = serializeInput < v3 . AsyncAPIObject > ( { servers : { production : { } } , components : { servers : { development : { } } } } ) ;
231
+ const d = new AsyncAPIDocument ( doc ) ;
232
+ expect ( d . allServers ( ) ) . toBeInstanceOf ( Servers ) ;
233
+ expect ( d . allServers ( ) ) . toHaveLength ( 2 ) ;
234
+ } ) ;
235
+
236
+ it ( 'should return a collection of servers even if servers are not defined' , function ( ) {
237
+ const doc = serializeInput < v3 . AsyncAPIObject > ( { } ) ;
238
+ const d = new AsyncAPIDocument ( doc ) ;
239
+ expect ( d . allServers ( ) ) . toBeInstanceOf ( Servers ) ;
240
+ } ) ;
241
+ } ) ;
242
+
243
+ describe ( '.allChannels()' , function ( ) {
244
+ it ( 'should return a collection of channels' , function ( ) {
245
+ const doc = serializeInput < v3 . AsyncAPIObject > ( { channels : { 'user/signup' : { } } } ) ;
246
+ const d = new AsyncAPIDocument ( doc ) ;
247
+ expect ( d . allChannels ( ) ) . toBeInstanceOf ( Channels ) ;
248
+ expect ( d . allChannels ( ) . all ( ) ) . not . toBeInstanceOf ( Collection ) ;
249
+ expect ( d . allChannels ( ) . all ( ) ) . toBeInstanceOf ( Array ) ;
250
+ expect ( d . allChannels ( ) ) . toHaveLength ( 1 ) ;
251
+ } ) ;
252
+
253
+ it ( 'should return all channels (with channels from components)' , function ( ) {
254
+ const doc = serializeInput < v3 . AsyncAPIObject > ( { channels : { 'user/signup' : { } } , components : { channels : { someChannel1 : { } , someChannel2 : { } } } } ) ;
255
+ const d = new AsyncAPIDocument ( doc ) ;
256
+ expect ( d . allChannels ( ) ) . toBeInstanceOf ( Channels ) ;
257
+ expect ( d . allChannels ( ) ) . toHaveLength ( 3 ) ;
258
+ } ) ;
259
+
260
+ it ( 'should return a collection of channels even if channels are not defined' , function ( ) {
261
+ const doc = serializeInput < v3 . AsyncAPIObject > ( { } ) ;
262
+ const d = new AsyncAPIDocument ( doc ) ;
263
+ expect ( d . allChannels ( ) ) . toBeInstanceOf ( Channels ) ;
264
+ } ) ;
265
+ } ) ;
266
+
267
+ describe ( '.allOperations()' , function ( ) {
268
+ it ( 'should return a collection of operations' , function ( ) {
269
+ const doc = serializeInput < v3 . AsyncAPIObject > ( { operations : { userSignup : { } , userLogout : { } } } ) ;
270
+ const d = new AsyncAPIDocument ( doc ) ;
271
+ expect ( d . allOperations ( ) ) . toBeInstanceOf ( Operations ) ;
272
+ expect ( d . allOperations ( ) . all ( ) ) . toBeInstanceOf ( Array ) ;
273
+ expect ( d . allOperations ( ) . all ( ) ) . not . toBeInstanceOf ( Collection ) ;
274
+ expect ( d . allOperations ( ) ) . toHaveLength ( 2 ) ;
275
+ } ) ;
276
+
277
+ it ( 'should return all operations (with operations from components)' , function ( ) {
278
+ const duplicatedOperation = { } ;
279
+ const doc = serializeInput < v3 . AsyncAPIObject > ( { operations : { userSignup : duplicatedOperation , userLogout : { } } , components : { operations : { someOperation1 : duplicatedOperation , someOperation2 : { } } } } ) ;
280
+ const d = new AsyncAPIDocument ( doc ) ;
281
+ expect ( d . allOperations ( ) ) . toBeInstanceOf ( Operations ) ;
282
+ expect ( d . allOperations ( ) ) . toHaveLength ( 3 ) ;
283
+ } ) ;
284
+
285
+ it ( 'should return a collection of operations even if operations are not defined' , function ( ) {
286
+ const doc = serializeInput < v3 . AsyncAPIObject > ( { } ) ;
287
+ const d = new AsyncAPIDocument ( doc ) ;
288
+ expect ( d . allOperations ( ) ) . toBeInstanceOf ( Operations ) ;
289
+ } ) ;
290
+ } ) ;
291
+
167
292
describe ( '.components()' , function ( ) {
168
293
it ( 'should return a components model' , function ( ) {
169
294
const doc = serializeInput < v3 . AsyncAPIObject > ( { components : { } } ) ;
0 commit comments