Add getSuggestions AJAX call to chronograf FE

pull/3033/head
Andrew Watkins 2018-03-23 13:11:27 -07:00 committed by Brandon Farmer
parent 00c7d9a6e2
commit b7cf32873a
3 changed files with 41 additions and 1 deletions

12
ui/src/ifql/apis/index.ts Normal file
View File

@ -0,0 +1,12 @@
import AJAX from 'src/utils/ajax'
export const getSuggestions = async (url: string) => {
try {
return await AJAX({
url,
})
} catch (error) {
console.error('Could not get suggestions', error)
throw error
}
}

View File

@ -41,7 +41,15 @@ const generateResponseWithLinks = (response, newLinks) => {
}
const AJAX = async (
{url, resource, id, method = 'GET', data = {}, params = {}, headers = {}},
{
url,
resource = null,
id = null,
method = 'GET',
data = {},
params = {},
headers = {},
},
{excludeBasepath} = {}
) => {
try {

View File

@ -0,0 +1,20 @@
import {getSuggestions} from 'src/ifql/apis'
import AJAX from 'src/utils/ajax'
jest.mock('src/utils/ajax', () => require('mocks/utils/ajax'))
describe('IFQL.Apis', () => {
afterEach(() => {
jest.clearAllMocks()
})
describe('getSuggestions', () => {
it('is called with the expected body', () => {
const url = '/chronograf/v1/suggestions'
getSuggestions(url)
expect(AJAX).toHaveBeenCalledWith({
url,
})
})
})
})