fix: respect OAS3 parameter default values (#4561)
* add test cases * refactor default setters into own function * reach into `schema` for default value in OAS3 * remove exclusive test
This commit is contained in:
67
test/bugs/4557-default-parameter-values.js
Normal file
67
test/bugs/4557-default-parameter-values.js
Normal file
@@ -0,0 +1,67 @@
|
||||
/* eslint-env mocha */
|
||||
import React from "react"
|
||||
import { List, fromJS } from "immutable"
|
||||
import expect, { createSpy } from "expect"
|
||||
import { render } from "enzyme"
|
||||
import ParameterRow from "components/parameter-row"
|
||||
|
||||
describe("bug #4557: default parameter values", function(){
|
||||
it("should apply a Swagger 2.0 default value", function(){
|
||||
|
||||
const paramValue = fromJS({
|
||||
description: "a pet",
|
||||
type: "string",
|
||||
default: "MyDefaultValue"
|
||||
})
|
||||
|
||||
let props = {
|
||||
getComponent: ()=> "div",
|
||||
specSelectors: {
|
||||
security(){},
|
||||
parameterWithMeta(){ return paramValue },
|
||||
isOAS3(){ return false }
|
||||
},
|
||||
operation: {get: ()=>{}},
|
||||
onChange: createSpy(),
|
||||
param: paramValue,
|
||||
onChangeConsumes: () => {},
|
||||
pathMethod: [],
|
||||
getConfigs: () => { return {} },
|
||||
specPath: List([])
|
||||
}
|
||||
|
||||
render(<ParameterRow {...props}/>)
|
||||
|
||||
expect(props.onChange).toHaveBeenCalledWith(paramValue, "MyDefaultValue")
|
||||
})
|
||||
it("should apply an OpenAPI 3.0 default value", function(){
|
||||
|
||||
const paramValue = fromJS({
|
||||
description: "a pet",
|
||||
schema: {
|
||||
type: "string",
|
||||
default: "MyDefaultValue"
|
||||
}
|
||||
})
|
||||
|
||||
let props = {
|
||||
getComponent: ()=> "div",
|
||||
specSelectors: {
|
||||
security(){},
|
||||
parameterWithMeta(){ return paramValue },
|
||||
isOAS3(){ return true }
|
||||
},
|
||||
operation: {get: ()=>{}},
|
||||
onChange: createSpy(),
|
||||
param: paramValue,
|
||||
onChangeConsumes: () => {},
|
||||
pathMethod: [],
|
||||
getConfigs: () => { return {} },
|
||||
specPath: List([])
|
||||
}
|
||||
|
||||
render(<ParameterRow {...props}/>)
|
||||
|
||||
expect(props.onChange).toHaveBeenCalledWith(paramValue, "MyDefaultValue")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user