@@ -20,13 +20,90 @@ const securityDefinitionsFixture: Dictionary<Security> = {
2020} ;
2121
2222describe ( 'accessors' , ( ) => {
23- const securityFixture = [
23+ const securityFixture : Array < Dictionary < string [ ] , string > > = [
2424 {
2525 api_key : [ ] ,
2626 petstore_auth : [ 'write:pets' , 'read:pets' ] ,
2727 } ,
2828 ] ;
2929
30+ describe ( 'relation between schemes' , ( ) => {
31+ describe ( 'when all of the given schemes are expected to be validated against' , ( ) => {
32+ const securityFixtureWithAndRelation = securityFixture ;
33+
34+ it ( 'returns an array containing multiple elements' , ( ) => {
35+ expect (
36+ getSecurities (
37+ {
38+ securityDefinitions : securityDefinitionsFixture ,
39+ security : [ ] ,
40+ } ,
41+ securityFixtureWithAndRelation ,
42+ ) ,
43+ ) . toEqual ( [
44+ [
45+ {
46+ in : 'header' ,
47+ name : 'api_key' ,
48+ type : 'apiKey' ,
49+ } ,
50+ {
51+ authorizationUrl : 'http://swagger.io/api/oauth/dialog' ,
52+ flow : 'implicit' ,
53+ scopes : {
54+ 'read:pets' : 'read your pets' ,
55+ 'write:pets' : 'modify pets in your account' ,
56+ } ,
57+ type : 'oauth2' ,
58+ } ,
59+ ] ,
60+ ] ) ;
61+ } ) ;
62+ } ) ;
63+
64+ describe ( 'when one of the given schemes is expected to be validated against' , ( ) => {
65+ it ( 'returns arrays containing one element each' , ( ) => {
66+ const securityFixtureWithOrRelation : Array < Dictionary < string [ ] , string > > = [
67+ {
68+ petstore_auth : [ 'write:pets' , 'read:pets' ] ,
69+ } ,
70+ {
71+ api_key : [ ] ,
72+ } ,
73+ ] ;
74+
75+ expect (
76+ getSecurities (
77+ {
78+ securityDefinitions : securityDefinitionsFixture ,
79+ security : [ ] ,
80+ } ,
81+ securityFixtureWithOrRelation ,
82+ ) ,
83+ ) . toEqual ( [
84+ [
85+ {
86+ authorizationUrl : 'http://swagger.io/api/oauth/dialog' ,
87+ flow : 'implicit' ,
88+ scopes : {
89+ 'read:pets' : 'read your pets' ,
90+ 'write:pets' : 'modify pets in your account' ,
91+ } ,
92+ type : 'oauth2' ,
93+ } ,
94+ ] ,
95+ [
96+ {
97+ in : 'header' ,
98+ name : 'api_key' ,
99+ type : 'apiKey' ,
100+ } ,
101+ ] ,
102+ ] ) ;
103+ } ) ;
104+ } ) ;
105+ } ) ;
106+
30107 describe ( 'getSecurities' , ( ) => {
31108 test ( 'given no security definitions should return empty array' , ( ) => {
32109 expect (
@@ -87,7 +164,7 @@ describe('accessors', () => {
87164 } ,
88165 ] ,
89166 ) ,
90- ) . toEqual ( [ { in : 'header' , name : 'api_key' , type : 'apiKey' } ] ) ;
167+ ) . toEqual ( [ [ { in : 'header' , name : 'api_key' , type : 'apiKey' } ] ] ) ;
91168 } ) ;
92169
93170 test ( 'given security with custom scopes should override global definition' , ( ) => {
@@ -104,12 +181,14 @@ describe('accessors', () => {
104181 ] ,
105182 ) ,
106183 ) . toEqual ( [
107- {
108- authorizationUrl : 'http://swagger.io/api/oauth/dialog' ,
109- flow : 'implicit' ,
110- scopes : { 'read:pets' : 'read your pets' , 'write:pets' : 'modify pets in your account' } ,
111- type : 'oauth2' ,
112- } ,
184+ [
185+ {
186+ authorizationUrl : 'http://swagger.io/api/oauth/dialog' ,
187+ flow : 'implicit' ,
188+ scopes : { 'read:pets' : 'read your pets' , 'write:pets' : 'modify pets in your account' } ,
189+ type : 'oauth2' ,
190+ } ,
191+ ] ,
113192 ] ) ;
114193 } ) ;
115194
@@ -123,13 +202,15 @@ describe('accessors', () => {
123202 securityFixture ,
124203 ) ,
125204 ) . toEqual ( [
126- { in : 'header' , name : 'api_key' , type : 'apiKey' } ,
127- {
128- authorizationUrl : 'http://swagger.io/api/oauth/dialog' ,
129- flow : 'implicit' ,
130- scopes : { 'write:pets' : 'modify pets in your account' , 'read:pets' : 'read your pets' } ,
131- type : 'oauth2' ,
132- } ,
205+ [
206+ { in : 'header' , name : 'api_key' , type : 'apiKey' } ,
207+ {
208+ authorizationUrl : 'http://swagger.io/api/oauth/dialog' ,
209+ flow : 'implicit' ,
210+ scopes : { 'write:pets' : 'modify pets in your account' , 'read:pets' : 'read your pets' } ,
211+ type : 'oauth2' ,
212+ } ,
213+ ] ,
133214 ] ) ;
134215 } ) ;
135216 } ) ;
0 commit comments