@@ -5,6 +5,57 @@ const Components = require('../../lib/models/components');
55const { assertMixinSpecificationExtensionsInheritance } = require ( '../mixins/specification-extensions_test' ) ;
66
77describe ( 'Components' , function ( ) {
8+ describe ( '#channels()' , function ( ) {
9+ it ( 'should return a map of Channel objects' , function ( ) {
10+ const doc = { channels : { test1 : { description : 'test1' } , test2 : { description : 'test2' } } } ;
11+ const d = new Components ( doc ) ;
12+ expect ( typeof d . channels ( ) ) . to . be . equal ( 'object' ) ;
13+ expect ( d . channels ( ) . test1 . constructor . name ) . to . equal ( 'Channel' ) ;
14+ expect ( d . channels ( ) . test1 . json ( ) ) . to . equal ( doc . channels . test1 ) ;
15+ expect ( d . channels ( ) . test2 . constructor . name ) . to . equal ( 'Channel' ) ;
16+ expect ( d . channels ( ) . test2 . json ( ) ) . to . equal ( doc . channels . test2 ) ;
17+ } ) ;
18+
19+ it ( 'should return an empty object if the components field has no defined channels' , function ( ) {
20+ const doc = { } ;
21+ const d = new Components ( doc ) ;
22+ expect ( typeof d . channels ( ) ) . to . be . equal ( 'object' ) ;
23+ expect ( d . channels ( ) ) . to . deep . equal ( { } ) ;
24+ } ) ;
25+ } ) ;
26+
27+ describe ( '#hasChannels()' , function ( ) {
28+ it ( 'should return a boolean indicating if the components field has channels' , function ( ) {
29+ const doc = { channels : { test1 : { description : 'test1' } , test2 : { description : 'test2' } } } ;
30+ const docNoChannels = { schemas : { } } ;
31+ const d = new Components ( doc ) ;
32+ const d2 = new Components ( docNoChannels ) ;
33+ expect ( d . hasChannels ( ) ) . to . equal ( true ) ;
34+ expect ( d2 . hasChannels ( ) ) . to . equal ( false ) ;
35+ } ) ;
36+ } ) ;
37+
38+ describe ( '#channel()' , function ( ) {
39+ it ( 'should return a specific Channel object' , function ( ) {
40+ const doc = { channels : { test1 : { description : 'test1' } , test2 : { description : 'test2' } } } ;
41+ const d = new Components ( doc ) ;
42+ expect ( d . channel ( 'test1' ) . constructor . name ) . to . equal ( 'Channel' ) ;
43+ expect ( d . channel ( 'test1' ) . json ( ) ) . to . equal ( doc . channels . test1 ) ;
44+ } ) ;
45+
46+ it ( 'should return null if a channel name is not provided' , function ( ) {
47+ const doc = { channels : { test1 : { description : 'test1' } , test2 : { description : 'test2' } } } ;
48+ const d = new Components ( doc ) ;
49+ expect ( d . channel ( ) ) . to . equal ( null ) ;
50+ } ) ;
51+
52+ it ( 'should return null if a channel name is not found' , function ( ) {
53+ const doc = { channels : { test1 : { description : 'test1' } , test2 : { description : 'test2' } } } ;
54+ const d = new Components ( doc ) ;
55+ expect ( d . channel ( 'not found' ) ) . to . equal ( null ) ;
56+ } ) ;
57+ } ) ;
58+
859 describe ( '#messages()' , function ( ) {
960 it ( 'should return a map of Message objects' , function ( ) {
1061 const doc = { messages : { test1 : { test : 'test1' } , test2 : { test : 'test2' } } } ;
@@ -157,6 +208,57 @@ describe('Components', function() {
157208 expect ( d . securityScheme ( 'not found' ) ) . to . equal ( null ) ;
158209 } ) ;
159210 } ) ;
211+
212+ describe ( '#servers()' , function ( ) {
213+ it ( 'should return a map of Server objects' , function ( ) {
214+ const doc = { servers : { test1 : { url : 'test1' } , test2 : { url : 'test2' } } } ;
215+ const d = new Components ( doc ) ;
216+ expect ( typeof d . servers ( ) ) . to . be . equal ( 'object' ) ;
217+ expect ( d . servers ( ) . test1 . constructor . name ) . to . equal ( 'Server' ) ;
218+ expect ( d . servers ( ) . test1 . json ( ) ) . to . equal ( doc . servers . test1 ) ;
219+ expect ( d . servers ( ) . test2 . constructor . name ) . to . equal ( 'Server' ) ;
220+ expect ( d . servers ( ) . test2 . json ( ) ) . to . equal ( doc . servers . test2 ) ;
221+ } ) ;
222+
223+ it ( 'should return an empty object if the components field has no defined servers' , function ( ) {
224+ const doc = { } ;
225+ const d = new Components ( doc ) ;
226+ expect ( typeof d . servers ( ) ) . to . be . equal ( 'object' ) ;
227+ expect ( d . servers ( ) ) . to . deep . equal ( { } ) ;
228+ } ) ;
229+ } ) ;
230+
231+ describe ( '#hasServers()' , function ( ) {
232+ it ( 'should return a boolean indicating if the components field has servers' , function ( ) {
233+ const doc = { servers : { test1 : { url : 'test1' } , test2 : { url : 'test2' } } } ;
234+ const docNoServers = { schemas : { } } ;
235+ const d = new Components ( doc ) ;
236+ const d2 = new Components ( docNoServers ) ;
237+ expect ( d . hasServers ( ) ) . to . equal ( true ) ;
238+ expect ( d2 . hasServers ( ) ) . to . equal ( false ) ;
239+ } ) ;
240+ } ) ;
241+
242+ describe ( '#server()' , function ( ) {
243+ it ( 'should return a specific Server object' , function ( ) {
244+ const doc = { servers : { test1 : { url : 'test1' } , test2 : { url : 'test2' } } } ;
245+ const d = new Components ( doc ) ;
246+ expect ( d . server ( 'test1' ) . constructor . name ) . to . equal ( 'Server' ) ;
247+ expect ( d . server ( 'test1' ) . json ( ) ) . to . equal ( doc . servers . test1 ) ;
248+ } ) ;
249+
250+ it ( 'should return null if a message name is not provided' , function ( ) {
251+ const doc = { servers : { test1 : { url : 'test1' } , test2 : { url : 'test2' } } } ;
252+ const d = new Components ( doc ) ;
253+ expect ( d . server ( ) ) . to . equal ( null ) ;
254+ } ) ;
255+
256+ it ( 'should return null if a message name is not found' , function ( ) {
257+ const doc = { servers : { test1 : { url : 'test1' } , test2 : { url : 'test2' } } } ;
258+ const d = new Components ( doc ) ;
259+ expect ( d . server ( 'not found' ) ) . to . equal ( null ) ;
260+ } ) ;
261+ } ) ;
160262
161263 describe ( '#parameters()' , function ( ) {
162264 it ( 'should return a map of ChannelParameter objects' , function ( ) {
0 commit comments