diff --git a/.travis.yml b/.travis.yml index c1ebce9c..6d3544a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,7 @@ after_success: docker build -t $DOCKER_IMAGE_NAME .; if [ ! -z "$TRAVIS_TAG" ]; then docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG; - docker push $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG; + docker push $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG; docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:latest; docker push $DOCKER_IMAGE_NAME:latest; else diff --git a/src/core/plugins/spec/reducers.js b/src/core/plugins/spec/reducers.js index 18ce101d..b5b23098 100644 --- a/src/core/plugins/spec/reducers.js +++ b/src/core/plugins/spec/reducers.js @@ -97,7 +97,11 @@ export default { }, [UPDATE_OPERATION_VALUE]: (state, { payload: { path, value, key } }) => { - return state.setIn(["resolved", "paths", ...path, key], fromJS(value)) + let operationPath = ["resolved", "paths", ...path] + if(!state.getIn(operationPath)) { + return state + } + return state.setIn([...operationPath, key], fromJS(value)) }, [CLEAR_RESPONSE]: (state, { payload: { path, method } } ) =>{ diff --git a/test/core/plugins/spec-reducer.js b/test/core/plugins/spec-reducer.js new file mode 100644 index 00000000..32113543 --- /dev/null +++ b/test/core/plugins/spec-reducer.js @@ -0,0 +1,72 @@ +/* eslint-env mocha */ +import expect from "expect" +import { fromJS } from "immutable" +import reducer from "corePlugins/spec/reducers" + +describe("spec plugin - reducer", function(){ + + describe("update operation value", function() { + it("should update the operation at the specified key", () => { + const updateOperationValue = reducer["spec_update_operation_value"] + + const state = fromJS({ + resolved: { + "paths": { + "/pet": { + "post": { + "description": "my operation" + } + } + } + } + }) + + let result = updateOperationValue(state, { + payload: { + path: ["/pet", "post"], + value: "application/json", + key: "consumes_value" + } + }) + + let expectedResult = { + resolved: { + "paths": { + "/pet": { + "post": { + "description": "my operation", + "consumes_value": "application/json" + } + } + } + } + } + + expect(result.toJS()).toEqual(expectedResult) + }) + + it("shouldn't throw an error if we try to update the consumes_value of a null operation", () => { + const updateOperationValue = reducer["spec_update_operation_value"] + + const state = fromJS({ + resolved: { + "paths": { + "/pet": { + "post": null + } + } + } + }) + + let result = updateOperationValue(state, { + payload: { + path: ["/pet", "post"], + value: "application/json", + key: "consumes_value" + } + }) + + expect(result.toJS()).toEqual(state.toJS()) + }) + }) +})