@@ -9,18 +9,15 @@ import {
99 operationScheme ,
1010 specJsonWithResolvedSubtrees ,
1111 producesOptionsFor ,
12- } from "corePlugins/spec/selectors"
13-
14- import Petstore from "./assets/petstore.json"
15- import {
1612 operationWithMeta ,
1713 parameterWithMeta ,
1814 parameterWithMetaByIdentity ,
1915 parameterInclusionSettingFor ,
20- consumesOptionsFor
21- } from "../../../../src/core/plugins/spec/selectors"
16+ consumesOptionsFor ,
17+ taggedOperations
18+ } from "corePlugins/spec/selectors"
2219
23- describe ( "spec plugin - selectors" , function ( ) {
20+ import Petstore from "./assets/petstore.json"
2421
2522 describe ( "definitions" , function ( ) {
2623 it ( "should return definitions by default" , function ( ) {
@@ -1049,4 +1046,169 @@ describe("spec plugin - selectors", function(){
10491046 ] )
10501047 } )
10511048 } )
1052- } )
1049+ describe ( "taggedOperations" , function ( ) {
1050+ it ( "should return a List of ad-hoc tagged operations" , function ( ) {
1051+ const system = {
1052+ getConfigs : ( ) => ( { } )
1053+ }
1054+ const state = fromJS ( {
1055+ json : {
1056+ // tags: [
1057+ // "myTag"
1058+ // ],
1059+ paths : {
1060+ "/" : {
1061+ "get" : {
1062+ produces : [ ] ,
1063+ tags : [ "myTag" ] ,
1064+ description : "my operation" ,
1065+ consumes : [
1066+ "operation/one" ,
1067+ "operation/two" ,
1068+ ]
1069+ }
1070+ }
1071+ }
1072+ }
1073+ } )
1074+
1075+ const result = taggedOperations ( state ) ( system )
1076+
1077+ const op = state . getIn ( [ "json" , "paths" , "/" , "get" ] ) . toJS ( )
1078+
1079+ expect ( result . toJS ( ) ) . toEqual ( {
1080+ myTag : {
1081+ tagDetails : undefined ,
1082+ operations : [ {
1083+ id : "get-/" ,
1084+ method : "get" ,
1085+ path : "/" ,
1086+ operation : op
1087+ } ]
1088+ }
1089+ } )
1090+ } )
1091+ it ( "should return a List of defined tagged operations" , function ( ) {
1092+ const system = {
1093+ getConfigs : ( ) => ( { } )
1094+ }
1095+ const state = fromJS ( {
1096+ json : {
1097+ tags : [
1098+ {
1099+ name : "myTag"
1100+ }
1101+ ] ,
1102+ paths : {
1103+ "/" : {
1104+ "get" : {
1105+ produces : [ ] ,
1106+ tags : [ "myTag" ] ,
1107+ description : "my operation" ,
1108+ consumes : [
1109+ "operation/one" ,
1110+ "operation/two" ,
1111+ ]
1112+ }
1113+ }
1114+ }
1115+ }
1116+ } )
1117+
1118+ const result = taggedOperations ( state ) ( system )
1119+
1120+ const op = state . getIn ( [ "json" , "paths" , "/" , "get" ] ) . toJS ( )
1121+
1122+ expect ( result . toJS ( ) ) . toEqual ( {
1123+ myTag : {
1124+ tagDetails : {
1125+ name : "myTag"
1126+ } ,
1127+ operations : [ {
1128+ id : "get-/" ,
1129+ method : "get" ,
1130+ path : "/" ,
1131+ operation : op
1132+ } ]
1133+ }
1134+ } )
1135+ } )
1136+ it ( "should gracefully handle a malformed global tags array" , function ( ) {
1137+ const system = {
1138+ getConfigs : ( ) => ( { } )
1139+ }
1140+ const state = fromJS ( {
1141+ json : {
1142+ tags : [ null ] ,
1143+ paths : {
1144+ "/" : {
1145+ "get" : {
1146+ produces : [ ] ,
1147+ tags : [ "myTag" ] ,
1148+ description : "my operation" ,
1149+ consumes : [
1150+ "operation/one" ,
1151+ "operation/two" ,
1152+ ]
1153+ }
1154+ }
1155+ }
1156+ }
1157+ } )
1158+
1159+ const result = taggedOperations ( state ) ( system )
1160+
1161+ const op = state . getIn ( [ "json" , "paths" , "/" , "get" ] ) . toJS ( )
1162+
1163+ expect ( result . toJS ( ) ) . toEqual ( {
1164+ myTag : {
1165+ tagDetails : undefined ,
1166+ operations : [ {
1167+ id : "get-/" ,
1168+ method : "get" ,
1169+ path : "/" ,
1170+ operation : op
1171+ } ]
1172+ }
1173+ } )
1174+ } )
1175+ it ( "should gracefully handle a non-array global tags entry" , function ( ) {
1176+ const system = {
1177+ getConfigs : ( ) => ( { } )
1178+ }
1179+ const state = fromJS ( {
1180+ json : {
1181+ tags : "asdf" ,
1182+ paths : {
1183+ "/" : {
1184+ "get" : {
1185+ produces : [ ] ,
1186+ tags : [ "myTag" ] ,
1187+ description : "my operation" ,
1188+ consumes : [
1189+ "operation/one" ,
1190+ "operation/two" ,
1191+ ]
1192+ }
1193+ }
1194+ }
1195+ }
1196+ } )
1197+
1198+ const result = taggedOperations ( state ) ( system )
1199+
1200+ const op = state . getIn ( [ "json" , "paths" , "/" , "get" ] ) . toJS ( )
1201+
1202+ expect ( result . toJS ( ) ) . toEqual ( {
1203+ myTag : {
1204+ tagDetails : undefined ,
1205+ operations : [ {
1206+ id : "get-/" ,
1207+ method : "get" ,
1208+ path : "/" ,
1209+ operation : op
1210+ } ]
1211+ }
1212+ } )
1213+ } )
1214+ } )
0 commit comments