From 3e658bd44f3c60a1be5f681360e39969a0d5d9ab Mon Sep 17 00:00:00 2001 From: Brandon Farmer Date: Tue, 13 Mar 2018 15:10:31 -0700 Subject: [PATCH] Send insecure verify skip on kapacitor create Co-authored-by: Brandon Farmer Co-authored-by: Andrew Watkins --- ui/mocks/dummy.ts | 31 +++++++++++++++++++++ ui/mocks/shared/apis/{index.js => index.ts} | 0 ui/mocks/utils/ajax.ts | 1 + ui/src/shared/apis/index.js | 3 +- ui/test/shared/apis/index.test.ts | 19 +++++++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) rename ui/mocks/shared/apis/{index.js => index.ts} (100%) create mode 100644 ui/mocks/utils/ajax.ts create mode 100644 ui/test/shared/apis/index.test.ts diff --git a/ui/mocks/dummy.ts b/ui/mocks/dummy.ts index ffab516810..d7e408bf06 100644 --- a/ui/mocks/dummy.ts +++ b/ui/mocks/dummy.ts @@ -1,10 +1,41 @@ +export const source = { + id: '2', + name: 'minikube-influx', + type: 'influx', + url: 'http://192.168.99.100:30400', + 'default': true, + telegraf: 'telegraf', + organization: 'default', + role: 'viewer', + links: { + self: '/chronograf/v1/sources/2', + kapacitors: '/chronograf/v1/sources/2/kapacitors', + proxy: '/chronograf/v1/sources/2/proxy', + queries: '/chronograf/v1/sources/2/queries', + write: '/chronograf/v1/sources/2/write', + permissions: '/chronograf/v1/sources/2/permissions', + users: '/chronograf/v1/sources/2/users', + databases: '/chronograf/v1/sources/2/dbs', + annotations: '/chronograf/v1/sources/2/annotations' + } +} + export const kapacitor = { id: '1', name: 'Test Kapacitor', url: 'http://localhost:9092', + insecureSkipVerify: false, active: true, links: { self: '/chronograf/v1/sources/47/kapacitors/1', proxy: '/chronograf/v1/sources/47/kapacitors/1/proxy', }, } + +export const createKapacitorBody = { + name: 'Test Kapacitor', + url: 'http://localhost:9092', + insecureSkipVerify: false, + username: 'user', + password: 'pass', +} diff --git a/ui/mocks/shared/apis/index.js b/ui/mocks/shared/apis/index.ts similarity index 100% rename from ui/mocks/shared/apis/index.js rename to ui/mocks/shared/apis/index.ts diff --git a/ui/mocks/utils/ajax.ts b/ui/mocks/utils/ajax.ts new file mode 100644 index 0000000000..9798925d1e --- /dev/null +++ b/ui/mocks/utils/ajax.ts @@ -0,0 +1 @@ +export default jest.fn(() => Promise.resolve()) diff --git a/ui/src/shared/apis/index.js b/ui/src/shared/apis/index.js index d08804d848..e5cbd6b001 100644 --- a/ui/src/shared/apis/index.js +++ b/ui/src/shared/apis/index.js @@ -104,7 +104,7 @@ export const deleteKapacitor = async kapacitor => { export function createKapacitor( source, - {url, name = 'My Kapacitor', username, password} + {url, name = 'My Kapacitor', username, password, insecureSkipVerify} ) { return AJAX({ url: source.links.kapacitors, @@ -114,6 +114,7 @@ export function createKapacitor( url, username, password, + insecureSkipVerify, }, }) } diff --git a/ui/test/shared/apis/index.test.ts b/ui/test/shared/apis/index.test.ts new file mode 100644 index 0000000000..22c40a094a --- /dev/null +++ b/ui/test/shared/apis/index.test.ts @@ -0,0 +1,19 @@ +import {createKapacitor} from 'src/shared/apis' +import {source, createKapacitorBody} from 'mocks/dummy' +import AJAX from 'src/utils/ajax' + +jest.mock('src/utils/ajax', () => require('mocks/utils/ajax')) + +describe('Shared.Apis', () => { + describe('createKapacitor', () => { + it('is called with the expected body', () => { + createKapacitor(source, createKapacitorBody) + + expect(AJAX).toHaveBeenCalledWith({ + url: source.links.kapacitors, + method: 'POST', + data: createKapacitorBody + }) + }) + }) +})