Merge branch 'master' of github.com:swagger-api/swagger-ui into bug/3511-query-formData-parameters
# Conflicts: # src/core/components/parameter-row.jsx # src/core/plugins/spec/actions.js
This commit is contained in:
@@ -1,6 +1,105 @@
|
||||
import { createXMLExample } from "corePlugins/samples/fn"
|
||||
import { createXMLExample, sampleFromSchema } from "corePlugins/samples/fn"
|
||||
import expect from "expect"
|
||||
|
||||
describe("sampleFromSchema", function() {
|
||||
it("returns object with no readonly fields for parameter", function () {
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "integer"
|
||||
},
|
||||
readOnlyDog: {
|
||||
readOnly: true,
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
var expected = {
|
||||
id: 0
|
||||
}
|
||||
|
||||
expect(sampleFromSchema(definition, { includeReadOnly: false })).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with readonly fields for parameter, with includeReadOnly", function () {
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "integer"
|
||||
},
|
||||
readOnlyDog: {
|
||||
readOnly: true,
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
var expected = {
|
||||
id: 0,
|
||||
readOnlyDog: "string"
|
||||
}
|
||||
|
||||
expect(sampleFromSchema(definition, { includeReadOnly: true })).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object without writeonly fields for parameter", function () {
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "integer"
|
||||
},
|
||||
writeOnlyDog: {
|
||||
writeOnly: true,
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
var expected = {
|
||||
id: 0
|
||||
}
|
||||
|
||||
expect(sampleFromSchema(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with writeonly fields for parameter, with includeWriteOnly", function () {
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "integer"
|
||||
},
|
||||
writeOnlyDog: {
|
||||
writeOnly: true,
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
var expected = {
|
||||
id: 0,
|
||||
writeOnlyDog: "string"
|
||||
}
|
||||
|
||||
expect(sampleFromSchema(definition, { includeWriteOnly: true })).toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
||||
describe("createXMLExample", function () {
|
||||
var sut = createXMLExample
|
||||
@@ -554,6 +653,69 @@ describe("createXMLExample", function () {
|
||||
expect(sut(definition, { includeReadOnly: false })).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with readonly fields for parameter, with includeReadOnly", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<id>0</id>\n\t<dog>string</dog>\n</animals>"
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "integer"
|
||||
},
|
||||
dog: {
|
||||
readOnly: true,
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition, { includeReadOnly: true })).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object without writeonly fields for parameter", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<id>0</id>\n</animals>"
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "integer"
|
||||
},
|
||||
dog: {
|
||||
writeOnly: true,
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition)).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with writeonly fields for parameter, with includeWriteOnly", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<id>0</id>\n\t<dog>string</dog>\n</animals>"
|
||||
var definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "integer"
|
||||
},
|
||||
dog: {
|
||||
writeOnly: true,
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
xml: {
|
||||
name: "animals"
|
||||
}
|
||||
}
|
||||
|
||||
expect(sut(definition, { includeWriteOnly: true })).toEqual(expected)
|
||||
})
|
||||
|
||||
it("returns object with passed property as attribute", function () {
|
||||
var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals id=\"0\">\n\t<dog>string</dog>\n</animals>"
|
||||
var definition = {
|
||||
|
||||
@@ -93,6 +93,55 @@ describe("spec plugin - actions", function(){
|
||||
})
|
||||
})
|
||||
|
||||
it("should pass requestInterceptor/responseInterceptor to fn.execute", function(){
|
||||
// Given
|
||||
let configs = {
|
||||
requestInterceptor: createSpy(),
|
||||
responseInterceptor: createSpy()
|
||||
}
|
||||
const system = {
|
||||
fn: {
|
||||
buildRequest: createSpy(),
|
||||
execute: createSpy().andReturn(Promise.resolve())
|
||||
},
|
||||
specActions: {
|
||||
executeRequest: createSpy(),
|
||||
setMutatedRequest: createSpy(),
|
||||
setRequest: createSpy()
|
||||
},
|
||||
specSelectors: {
|
||||
spec: () => fromJS({}),
|
||||
parameterValues: () => fromJS({}),
|
||||
contentTypeValues: () => fromJS({}),
|
||||
url: () => fromJS({}),
|
||||
isOAS3: () => false
|
||||
},
|
||||
getConfigs: () => configs
|
||||
}
|
||||
// When
|
||||
let executeFn = executeRequest({
|
||||
pathName: "/one",
|
||||
method: "GET",
|
||||
operation: fromJS({operationId: "getOne"})
|
||||
})
|
||||
let res = executeFn(system)
|
||||
|
||||
// Then
|
||||
expect(system.fn.execute.calls.length).toEqual(1)
|
||||
expect(system.fn.execute.calls[0].arguments[0]).toIncludeKey("requestInterceptor")
|
||||
expect(system.fn.execute.calls[0].arguments[0]).toInclude({
|
||||
responseInterceptor: configs.responseInterceptor
|
||||
})
|
||||
expect(system.specActions.setMutatedRequest.calls.length).toEqual(0)
|
||||
expect(system.specActions.setRequest.calls.length).toEqual(1)
|
||||
|
||||
|
||||
let wrappedRequestInterceptor = system.fn.execute.calls[0].arguments[0].requestInterceptor
|
||||
wrappedRequestInterceptor(system.fn.execute.calls[0].arguments[0])
|
||||
expect(configs.requestInterceptor.calls.length).toEqual(1)
|
||||
expect(system.specActions.setMutatedRequest.calls.length).toEqual(1)
|
||||
expect(system.specActions.setRequest.calls.length).toEqual(1)
|
||||
})
|
||||
})
|
||||
|
||||
xit("should call specActions.setResponse, when fn.execute resolves", function(){
|
||||
|
||||
Reference in New Issue
Block a user