Reorganize tests
This commit is contained in:
134
test/core/plugins/spec/actions.js
Normal file
134
test/core/plugins/spec/actions.js
Normal file
@@ -0,0 +1,134 @@
|
||||
/* eslint-env mocha */
|
||||
import expect, { createSpy } from "expect"
|
||||
import { fromJS } from "immutable"
|
||||
import { execute, executeRequest } from "corePlugins/spec/actions"
|
||||
|
||||
describe("spec plugin - actions", function(){
|
||||
|
||||
describe("execute", function(){
|
||||
|
||||
xit("should collect a full request and call fn.executeRequest", function(){
|
||||
// Given
|
||||
const system = {
|
||||
fn: {
|
||||
fetch: 1
|
||||
},
|
||||
specActions: {
|
||||
executeRequest: createSpy()
|
||||
},
|
||||
specSelectors: {
|
||||
spec: () => fromJS({spec: 1}),
|
||||
parameterValues: () => fromJS({values: 2}),
|
||||
contentTypeValues: () => fromJS({requestContentType: "one", responseContentType: "two"})
|
||||
}
|
||||
}
|
||||
|
||||
// When
|
||||
let executeFn = execute({ path: "/one", method: "get"})
|
||||
executeFn(system)
|
||||
|
||||
// Then
|
||||
expect(system.specActions.executeRequest.calls[0].arguments[0]).toEqual({
|
||||
fetch: 1,
|
||||
method: "get",
|
||||
pathName: "/one",
|
||||
parameters: {
|
||||
values: 2
|
||||
},
|
||||
requestContentType: "one",
|
||||
responseContentType: "two",
|
||||
spec: {
|
||||
spec: 1
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
xit("should allow passing _extra_ properties to executeRequest", function(){
|
||||
|
||||
// Given
|
||||
const system = {
|
||||
fn: {},
|
||||
specActions: {
|
||||
executeRequest: createSpy()
|
||||
},
|
||||
specSelectors: {
|
||||
spec: () => fromJS({}),
|
||||
parameterValues: () => fromJS({}),
|
||||
contentTypeValues: () => fromJS({})
|
||||
}
|
||||
}
|
||||
|
||||
// When
|
||||
let executeFn = execute({ hi: "hello" })
|
||||
executeFn(system)
|
||||
|
||||
// Then
|
||||
expect(system.specActions.executeRequest.calls[0].arguments[0]).toInclude({hi: "hello"})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe("executeRequest", function(){
|
||||
|
||||
xit("should call fn.execute with arg ", function(){
|
||||
|
||||
const system = {
|
||||
fn: {
|
||||
execute: createSpy().andReturn(Promise.resolve())
|
||||
},
|
||||
specActions: {
|
||||
setResponse: createSpy()
|
||||
}
|
||||
}
|
||||
|
||||
// When
|
||||
let executeFn = executeRequest({one: 1})
|
||||
let res = executeFn(system)
|
||||
|
||||
// Then
|
||||
expect(res).toBeA(Promise)
|
||||
expect(system.fn.execute.calls.length).toEqual(1)
|
||||
expect(system.fn.execute.calls[0].arguments[0]).toEqual({
|
||||
one: 1
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
xit("should call specActions.setResponse, when fn.execute resolves", function(){
|
||||
|
||||
const response = {serverResponse: true}
|
||||
const system = {
|
||||
fn: {
|
||||
execute: createSpy().andReturn(Promise.resolve(response))
|
||||
},
|
||||
specActions: {
|
||||
setResponse: createSpy()
|
||||
},
|
||||
errActions: {
|
||||
newSpecErr: createSpy()
|
||||
}
|
||||
}
|
||||
|
||||
// When
|
||||
let executeFn = executeRequest({
|
||||
pathName: "/one",
|
||||
method: "GET"
|
||||
})
|
||||
let executePromise = executeFn(system)
|
||||
|
||||
// Then
|
||||
return executePromise.then( () => {
|
||||
expect(system.specActions.setResponse.calls.length).toEqual(1)
|
||||
expect(system.specActions.setResponse.calls[0].arguments).toEqual([
|
||||
"/one",
|
||||
"GET",
|
||||
response
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
it.skip("should call errActions.newErr, if the fn.execute rejects", function(){
|
||||
})
|
||||
|
||||
})
|
||||
134
test/core/plugins/spec/selectors.js
Normal file
134
test/core/plugins/spec/selectors.js
Normal file
@@ -0,0 +1,134 @@
|
||||
/* eslint-env mocha */
|
||||
import expect from "expect"
|
||||
import { fromJS } from "immutable"
|
||||
import { parameterValues, contentTypeValues, operationScheme } from "corePlugins/spec/selectors"
|
||||
|
||||
describe("spec plugin - selectors", function(){
|
||||
|
||||
describe("parameterValue", function(){
|
||||
|
||||
it("should return Map({}) if no path found", function(){
|
||||
|
||||
// Given
|
||||
const spec = fromJS({ })
|
||||
|
||||
// When
|
||||
let paramValues = parameterValues(spec, ["/one", "get"])
|
||||
|
||||
// Then
|
||||
expect(paramValues.toJS()).toEqual({})
|
||||
|
||||
})
|
||||
|
||||
it("should return a hash of [parameterName]: value", function(){
|
||||
|
||||
// Given
|
||||
const spec = fromJS({
|
||||
resolved: {
|
||||
paths: {
|
||||
"/one": {
|
||||
get: {
|
||||
parameters: [
|
||||
{ name: "one", value: 1},
|
||||
{ name: "two", value: "duos"}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// When
|
||||
let paramValues = parameterValues(spec, ["/one", "get"])
|
||||
|
||||
// Then
|
||||
expect(paramValues.toJS()).toEqual({
|
||||
one: 1,
|
||||
two: "duos"
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe("contentTypeValues", function(){
|
||||
|
||||
it("should return { requestContentType, responseContentType } from an operation", function(){
|
||||
// Given
|
||||
let state = fromJS({
|
||||
resolved: {
|
||||
paths: {
|
||||
"/one": {
|
||||
get: {
|
||||
"consumes_value": "one",
|
||||
"produces_value": "two"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// When
|
||||
let contentTypes = contentTypeValues(state, [ "/one", "get" ])
|
||||
// Then
|
||||
expect(contentTypes.toJS()).toEqual({
|
||||
requestContentType: "one",
|
||||
responseContentType: "two"
|
||||
})
|
||||
})
|
||||
|
||||
it("should be ok, if no operation found", function(){
|
||||
// Given
|
||||
let state = fromJS({ })
|
||||
|
||||
// When
|
||||
let contentTypes = contentTypeValues(state, [ "/one", "get" ])
|
||||
// Then
|
||||
expect(contentTypes.toJS()).toEqual({
|
||||
requestContentType: undefined,
|
||||
responseContentType: undefined
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe("operationScheme", function(){
|
||||
|
||||
it("should return the correct scheme for a remote spec that doesn't specify a scheme", function(){
|
||||
// Given
|
||||
let state = fromJS({
|
||||
url: "https://generator.swagger.io/api/swagger.json",
|
||||
resolved: {
|
||||
paths: {
|
||||
"/one": {
|
||||
get: {
|
||||
"consumes_value": "one",
|
||||
"produces_value": "two"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// When
|
||||
let scheme = operationScheme(state, ["/one"], "get")
|
||||
// Then
|
||||
expect(scheme).toEqual("https")
|
||||
})
|
||||
|
||||
// it("should be ok, if no operation found", function(){
|
||||
// // Given
|
||||
// let state = fromJS({ })
|
||||
//
|
||||
// // When
|
||||
// let contentTypes = contentTypeValues(state, [ "/one", "get" ])
|
||||
// // Then
|
||||
// expect(contentTypes.toJS()).toEqual({
|
||||
// requestContentType: undefined,
|
||||
// responseContentType: undefined
|
||||
// })
|
||||
// })
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user