@@ -13,7 +13,8 @@ import {
13
13
parameterWithMetaByIdentity ,
14
14
parameterInclusionSettingFor ,
15
15
consumesOptionsFor ,
16
- taggedOperations
16
+ taggedOperations ,
17
+ isMediaTypeSchemaPropertiesEqual
17
18
} from "corePlugins/spec/selectors"
18
19
19
20
import Petstore from "./assets/petstore.json"
@@ -1211,3 +1212,167 @@ describe("taggedOperations", function () {
1211
1212
} )
1212
1213
} )
1213
1214
} )
1215
+ describe ( "isMediaTypeSchemaPropertiesEqual" , ( ) => {
1216
+ const stateSingleMediaType = fromJS ( {
1217
+ resolvedSubtrees : {
1218
+ paths : {
1219
+ "/test" : {
1220
+ post : {
1221
+ requestBody : {
1222
+ content : {
1223
+ "application/json" : {
1224
+ schema : {
1225
+ properties : {
1226
+ "test" : "some"
1227
+ }
1228
+ }
1229
+ }
1230
+ }
1231
+ }
1232
+ }
1233
+ }
1234
+ }
1235
+ }
1236
+ } )
1237
+ const pathMethod = [ "/test" , "post" ]
1238
+
1239
+ describe ( "Only one media type defined" , ( ) => {
1240
+ const state = stateSingleMediaType
1241
+
1242
+ it ( "should return false if currentMediaType is null" , ( ) => {
1243
+ const currentMediaType = null
1244
+ const targetMediaType = "application/json"
1245
+
1246
+ const result = isMediaTypeSchemaPropertiesEqual (
1247
+ state ,
1248
+ pathMethod ,
1249
+ currentMediaType ,
1250
+ targetMediaType
1251
+ )
1252
+
1253
+ expect ( result ) . toEqual ( false )
1254
+ } )
1255
+ it ( "should return false if currentMediaType is undefined" , ( ) => {
1256
+ const currentMediaType = undefined
1257
+ const targetMediaType = "application/json"
1258
+
1259
+ const result = isMediaTypeSchemaPropertiesEqual (
1260
+ state ,
1261
+ pathMethod ,
1262
+ currentMediaType ,
1263
+ targetMediaType
1264
+ )
1265
+
1266
+ expect ( result ) . toEqual ( false )
1267
+ } )
1268
+ it ( "should return false if targetMediaType is null" , ( ) => {
1269
+ const currentMediaType = "application/json"
1270
+ const targetMediaType = null
1271
+
1272
+ const result = isMediaTypeSchemaPropertiesEqual (
1273
+ state ,
1274
+ pathMethod ,
1275
+ currentMediaType ,
1276
+ targetMediaType
1277
+ )
1278
+
1279
+ expect ( result ) . toEqual ( false )
1280
+ } )
1281
+ it ( "should return false if targetMediaType is undefined" , ( ) => {
1282
+ const currentMediaType = "application/json"
1283
+ const targetMediaType = undefined
1284
+
1285
+ const result = isMediaTypeSchemaPropertiesEqual (
1286
+ state ,
1287
+ pathMethod ,
1288
+ currentMediaType ,
1289
+ targetMediaType
1290
+ )
1291
+
1292
+ expect ( result ) . toEqual ( false )
1293
+ } )
1294
+ it ( "should return true when currentMediaType and targetMediaType are the same" , ( ) => {
1295
+ const currentMediaType = "application/json"
1296
+ const targetMediaType = "application/json"
1297
+
1298
+ const result = isMediaTypeSchemaPropertiesEqual (
1299
+ state ,
1300
+ pathMethod ,
1301
+ currentMediaType ,
1302
+ targetMediaType
1303
+ )
1304
+
1305
+ expect ( result ) . toEqual ( true )
1306
+ } )
1307
+
1308
+ it ( "should return false if currentMediaType is not targetMediaType, but only one media type defined" , ( ) => {
1309
+ const currentMediaType = "application/json"
1310
+ const targetMediaType = "application/xml"
1311
+
1312
+ const result = isMediaTypeSchemaPropertiesEqual (
1313
+ state ,
1314
+ pathMethod ,
1315
+ currentMediaType ,
1316
+ targetMediaType
1317
+ )
1318
+
1319
+ expect ( result ) . toEqual ( false )
1320
+ } )
1321
+ } )
1322
+ describe ( "Multiple media types defined" , ( ) => {
1323
+ const keyPath = [ "resolvedSubtrees" , "paths" , ...pathMethod , "requestBody" , "content" ]
1324
+ const state = stateSingleMediaType
1325
+ . setIn (
1326
+ [ ...keyPath , "application/xml" ] ,
1327
+ stateSingleMediaType . getIn ( [ ...keyPath , "application/json" ] )
1328
+ )
1329
+ . setIn (
1330
+ [ ...keyPath , "application/other" ] ,
1331
+ stateSingleMediaType
1332
+ . getIn ( [ ...keyPath , "application/json" ] )
1333
+ . setIn ( [ "schema" , "properties" ] , "someOther" )
1334
+ )
1335
+
1336
+ it ( "should return true if same media type" , ( ) => {
1337
+ const currentMediaType = "application/json"
1338
+ const targetMediaType = "application/json"
1339
+
1340
+ const result = isMediaTypeSchemaPropertiesEqual (
1341
+ state ,
1342
+ pathMethod ,
1343
+ currentMediaType ,
1344
+ targetMediaType
1345
+ )
1346
+
1347
+ expect ( result ) . toEqual ( true )
1348
+ } )
1349
+
1350
+ it ( "should return true if target has same properties" , ( ) => {
1351
+ const currentMediaType = "application/json"
1352
+ const targetMediaType = "application/xml"
1353
+
1354
+ const result = isMediaTypeSchemaPropertiesEqual (
1355
+ state ,
1356
+ pathMethod ,
1357
+ currentMediaType ,
1358
+ targetMediaType
1359
+ )
1360
+
1361
+ expect ( result ) . toEqual ( true )
1362
+ } )
1363
+
1364
+ it ( "should return false if target has other properties" , ( ) => {
1365
+ const currentMediaType = "application/json"
1366
+ const targetMediaType = "application/other"
1367
+
1368
+ const result = isMediaTypeSchemaPropertiesEqual (
1369
+ state ,
1370
+ pathMethod ,
1371
+ currentMediaType ,
1372
+ targetMediaType
1373
+ )
1374
+
1375
+ expect ( result ) . toEqual ( false )
1376
+ } )
1377
+ } )
1378
+ } )
0 commit comments