From 35769f9b47219ef12ad8cd974237a1fcb92b41e1 Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Tue, 18 Apr 2017 11:20:15 -0700 Subject: [PATCH] Fix #2918; add control/test tests --- src/core/plugins/spec/reducers.js | 6 ++- test/core/plugins/spec-reducer.js | 72 +++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 test/core/plugins/spec-reducer.js 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()) + }) + }) +})