From ade47ca40ec4e46e9b42570576bf71c1d84571e5 Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Wed, 29 Nov 2017 15:54:17 -0600 Subject: [PATCH 1/8] Add requestInterceptor to OAuth2 request authorization calls --- src/core/plugins/auth/actions.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/plugins/auth/actions.js b/src/core/plugins/auth/actions.js index 7a41a398..876a677d 100644 --- a/src/core/plugins/auth/actions.js +++ b/src/core/plugins/auth/actions.js @@ -139,7 +139,7 @@ export const authorizeAccessCodeWithBasicAuthentication = ( { auth, redirectUrl return authActions.authorizeRequest({body: buildFormData(form), name, url: schema.get("tokenUrl"), auth, headers}) } -export const authorizeRequest = ( data ) => ( { fn, authActions, errActions, authSelectors } ) => { +export const authorizeRequest = ( data ) => ( { fn, getConfigs, authActions, errActions, authSelectors } ) => { let { body, query={}, headers={}, name, url, auth } = data let { additionalQueryStringParams } = authSelectors.getConfigs() || {} let fetchUrl = url @@ -158,7 +158,8 @@ export const authorizeRequest = ( data ) => ( { fn, authActions, errActions, aut method: "post", headers: _headers, query: query, - body: body + body: body, + requestInterceptor: getConfigs().requestInterceptor }) .then(function (response) { let token = JSON.parse(response.data) From 23251185407ac0fa48eb44effada1fc0873a2ca1 Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Wed, 29 Nov 2017 15:55:15 -0600 Subject: [PATCH 2/8] Add responseInterceptor as well --- src/core/plugins/auth/actions.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/plugins/auth/actions.js b/src/core/plugins/auth/actions.js index 876a677d..d264c65d 100644 --- a/src/core/plugins/auth/actions.js +++ b/src/core/plugins/auth/actions.js @@ -159,7 +159,8 @@ export const authorizeRequest = ( data ) => ( { fn, getConfigs, authActions, err headers: _headers, query: query, body: body, - requestInterceptor: getConfigs().requestInterceptor + requestInterceptor: getConfigs().requestInterceptor, + responseInterceptor: getConfigs().responseInterceptor }) .then(function (response) { let token = JSON.parse(response.data) From e17a5f40f58382b13d4485d209b178e33c0f62b9 Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Wed, 29 Nov 2017 19:03:40 -0600 Subject: [PATCH 3/8] Add JsonSchemaForm tests, including one failing --- test/components/json-schema-form.js | 111 ++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 test/components/json-schema-form.js diff --git a/test/components/json-schema-form.js b/test/components/json-schema-form.js new file mode 100644 index 00000000..7bd528e7 --- /dev/null +++ b/test/components/json-schema-form.js @@ -0,0 +1,111 @@ +/* eslint-env mocha */ +import React from "react" +import expect, { createSpy } from "expect" +import { Select } from "components/layout-utils" +import { render } from "enzyme" +import * as JsonSchemaComponents from "core/json-schema-components" +import { JsonSchemaForm } from "core/json-schema-components" + +const components = {...JsonSchemaComponents, Select} + +const getComponentStub = (name) => { + return components[name] || (() => { + console.error(`Couldn't find "${name}"`) + return null + }) +} + +describe("", function(){ + describe("strings", function() { + it("should render the correct options for a string enum parameter", function(){ + + let props = { + getComponent: getComponentStub, + value: "", + onChange: () => {}, + keyName: "", + fn: {}, + schema: { + type: "string", + enum: ["one", "two"] + } + } + + let wrapper = render() + + expect(wrapper.find("select").length).toEqual(1) + expect(wrapper.find("select option").length).toEqual(3) + expect(wrapper.find("select option").eq(0).text()).toEqual("--") + expect(wrapper.find("select option").eq(1).text()).toEqual("one") + expect(wrapper.find("select option").eq(2).text()).toEqual("two") + }) + + it("should render the correct options for a required string enum parameter", function(){ + + let props = { + getComponent: getComponentStub, + value: "", + onChange: () => {}, + keyName: "", + fn: {}, + required: true, + schema: { + type: "string", + enum: ["one", "two"] + } + } + + let wrapper = render() + + expect(wrapper.find("select").length).toEqual(1) + expect(wrapper.find("select option").length).toEqual(2) + expect(wrapper.find("select option").eq(0).text()).toEqual("one") + expect(wrapper.find("select option").eq(1).text()).toEqual("two") + }) + }) + describe("booleans", function() { + it("should render the correct options for a boolean parameter", function(){ + + let props = { + getComponent: getComponentStub, + value: "", + onChange: () => {}, + keyName: "", + fn: {}, + schema: { + type: "boolean" + } + } + + let wrapper = render() + + expect(wrapper.find("select").length).toEqual(1) + expect(wrapper.find("select option").length).toEqual(3) + expect(wrapper.find("select option").eq(0).text()).toEqual("--") + expect(wrapper.find("select option").eq(1).text()).toEqual("true") + expect(wrapper.find("select option").eq(2).text()).toEqual("false") + }) + + it("should render the correct options for a required enum boolean parameter", function(){ + + let props = { + getComponent: getComponentStub, + value: "", + onChange: () => {}, + keyName: "", + fn: {}, + required: true, + schema: { + type: "boolean", + enum: ["true"] + } + } + + let wrapper = render() + + expect(wrapper.find("select").length).toEqual(1) + expect(wrapper.find("select option").length).toEqual(1) + expect(wrapper.find("select option").eq(1).text()).toEqual("true") + }) + }) +}) From 8d1d15ca4adf5399ef2a494b1b9708eae762e98c Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Wed, 29 Nov 2017 19:04:50 -0600 Subject: [PATCH 4/8] Simplify JsonSchemaform getComponent logic --- src/core/json-schema-components.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/core/json-schema-components.js b/src/core/json-schema-components.js index e8bf1e44..eeb294f3 100644 --- a/src/core/json-schema-components.js +++ b/src/core/json-schema-components.js @@ -36,7 +36,7 @@ export class JsonSchemaForm extends Component { let { type, format="" } = schema - let Comp = getComponent(`JsonSchema_${type}_${format}`) || getComponent(`JsonSchema_${type}`) || getComponent("JsonSchema_string") + let Comp = format ? getComponent(`JsonSchema_${type}_${format}`) : getComponent(`JsonSchema_${type}`) || getComponent("JsonSchema_string") return } @@ -68,19 +68,19 @@ export class JsonSchema_string extends Component { const isDisabled = schema["in"] === "formData" && !("FormData" in window) const Input = getComponent("Input") if (schema["type"] === "file") { - return () } else { - return () } } From 5224932cf9731f63f16623727fdda1fecd45edb9 Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Wed, 29 Nov 2017 19:21:20 -0600 Subject: [PATCH 5/8] Fix failing test --- src/core/components/layout-utils.jsx | 2 +- src/core/json-schema-components.js | 4 ++-- test/components/json-schema-form.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/components/layout-utils.jsx b/src/core/components/layout-utils.jsx index d1adfeb1..1601681f 100644 --- a/src/core/components/layout-utils.jsx +++ b/src/core/components/layout-utils.jsx @@ -183,7 +183,7 @@ export class Select extends React.Component { { allowEmptyValue ? : null } { allowedValues.map(function (item, key) { - return + return }) } diff --git a/src/core/json-schema-components.js b/src/core/json-schema-components.js index eeb294f3..222f4053 100644 --- a/src/core/json-schema-components.js +++ b/src/core/json-schema-components.js @@ -189,8 +189,8 @@ export class JsonSchema_boolean extends Component { return (