influxdb/ui/test/shared/apis/index.test.ts

43 lines
989 B
TypeScript
Raw Normal View History

import {
2018-03-21 22:24:59 +00:00
createKapacitorBody,
kapacitor,
2018-03-21 22:24:59 +00:00
source,
updateKapacitorBody,
} from 'mocks/dummy'
2018-03-21 22:24:59 +00:00
import {createKapacitor, updateKapacitor} from 'src/shared/apis'
import AJAX from 'src/utils/ajax'
jest.mock('src/utils/ajax', () => require('mocks/utils/ajax'))
describe('Shared.Apis', () => {
afterEach(() => {
jest.clearAllMocks()
})
describe('createKapacitor', () => {
it('is called with the expected body', () => {
createKapacitor(source, createKapacitorBody)
expect(AJAX).toHaveBeenCalledWith({
data: createKapacitorBody,
2018-03-21 23:08:03 +00:00
method: 'POST',
url: source.links.kapacitors,
})
})
})
2018-03-13 22:34:54 +00:00
describe('updateKapacitor', () => {
it('is called with the expected body', () => {
updateKapacitor(updateKapacitorBody)
2018-03-21 22:24:59 +00:00
const data = {...updateKapacitorBody}
delete data.links
2018-03-13 22:34:54 +00:00
expect(AJAX).toHaveBeenCalledWith({
data,
2018-03-21 23:08:03 +00:00
method: 'PATCH',
url: kapacitor.links.self,
2018-03-13 22:34:54 +00:00
})
})
})
})