Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Index Templates API routes to snakecase. #68463

Merged
merged 2 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type HttpResponse = Record<string, any> | any[];
// Register helpers to mock HTTP Requests
const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
const setLoadTemplatesResponse = (response: HttpResponse = []) => {
server.respondWith('GET', `${API_BASE_PATH}/index-templates`, [
server.respondWith('GET', `${API_BASE_PATH}/index_templates`, [
200,
{ 'Content-Type': 'application/json' },
JSON.stringify(response),
Expand All @@ -28,7 +28,7 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
};

const setDeleteTemplateResponse = (response: HttpResponse = []) => {
server.respondWith('POST', `${API_BASE_PATH}/delete-index-templates`, [
server.respondWith('POST', `${API_BASE_PATH}/delete_index_templates`, [
200,
{ 'Content-Type': 'application/json' },
JSON.stringify(response),
Expand All @@ -39,7 +39,7 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
const status = error ? error.status || 400 : 200;
const body = error ? error.body : response;

server.respondWith('GET', `${API_BASE_PATH}/index-templates/:id`, [
server.respondWith('GET', `${API_BASE_PATH}/index_templates/:id`, [
status,
{ 'Content-Type': 'application/json' },
JSON.stringify(body),
Expand All @@ -50,7 +50,7 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
const status = error ? error.body.status || 400 : 200;
const body = error ? JSON.stringify(error.body) : JSON.stringify(response);

server.respondWith('POST', `${API_BASE_PATH}/index-templates`, [
server.respondWith('POST', `${API_BASE_PATH}/index_templates`, [
status,
{ 'Content-Type': 'application/json' },
body,
Expand All @@ -61,7 +61,7 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
const status = error ? error.status || 400 : 200;
const body = error ? JSON.stringify(error.body) : JSON.stringify(response);

server.respondWith('PUT', `${API_BASE_PATH}/index-templates/:name`, [
server.respondWith('PUT', `${API_BASE_PATH}/index_templates/:name`, [
status,
{ 'Content-Type': 'application/json' },
body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('Index Templates tab', () => {

expect(server.requests.length).toBe(totalRequests + 1);
expect(server.requests[server.requests.length - 1].url).toBe(
`${API_BASE_PATH}/index-templates`
`${API_BASE_PATH}/index_templates`
);
});

Expand Down Expand Up @@ -318,7 +318,7 @@ describe('Index Templates tab', () => {
const latestRequest = server.requests[server.requests.length - 1];

expect(latestRequest.method).toBe('POST');
expect(latestRequest.url).toBe(`${API_BASE_PATH}/delete-index-templates`);
expect(latestRequest.url).toBe(`${API_BASE_PATH}/delete_index_templates`);
expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toEqual({
templates: [{ name: legacyTemplates[0].name, isLegacy }],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,14 @@ export async function loadIndexData(type: string, indexName: string) {

export function useLoadIndexTemplates() {
return useRequest<{ templates: TemplateListItem[]; legacyTemplates: TemplateListItem[] }>({
path: `${API_BASE_PATH}/index-templates`,
path: `${API_BASE_PATH}/index_templates`,
method: 'get',
});
}

export async function deleteTemplates(templates: Array<{ name: string; isLegacy?: boolean }>) {
const result = sendRequest({
path: `${API_BASE_PATH}/delete-index-templates`,
path: `${API_BASE_PATH}/delete_index_templates`,
method: 'post',
body: { templates },
});
Expand All @@ -232,7 +232,7 @@ export async function deleteTemplates(templates: Array<{ name: string; isLegacy?

export function useLoadIndexTemplate(name: TemplateDeserialized['name'], isLegacy?: boolean) {
return useRequest<TemplateDeserialized>({
path: `${API_BASE_PATH}/index-templates/${encodeURIComponent(name)}`,
path: `${API_BASE_PATH}/index_templates/${encodeURIComponent(name)}`,
method: 'get',
query: {
legacy: isLegacy,
Expand All @@ -242,7 +242,7 @@ export function useLoadIndexTemplate(name: TemplateDeserialized['name'], isLegac

export async function saveTemplate(template: TemplateDeserialized, isClone?: boolean) {
const result = await sendRequest({
path: `${API_BASE_PATH}/index-templates`,
path: `${API_BASE_PATH}/index_templates`,
method: 'post',
body: JSON.stringify(template),
});
Expand All @@ -257,7 +257,7 @@ export async function saveTemplate(template: TemplateDeserialized, isClone?: boo
export async function updateTemplate(template: TemplateDeserialized) {
const { name } = template;
const result = await sendRequest({
path: `${API_BASE_PATH}/index-templates/${encodeURIComponent(name)}`,
path: `${API_BASE_PATH}/index_templates/${encodeURIComponent(name)}`,
method: 'put',
body: JSON.stringify(template),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const bodySchema = templateSchema;

export function registerCreateRoute({ router, license, lib }: RouteDependencies) {
router.post(
{ path: addBasePath('/index-templates'), validate: { body: bodySchema } },
{ path: addBasePath('/index_templates'), validate: { body: bodySchema } },
license.guardApiRoute(async (ctx, req, res) => {
const { callAsCurrentUser } = ctx.core.elasticsearch.legacy.client;
const template = req.body as TemplateDeserialized;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const bodySchema = schema.object({
export function registerDeleteRoute({ router, license }: RouteDependencies) {
router.post(
{
path: addBasePath('/delete-index-templates'),
path: addBasePath('/delete_index_templates'),
validate: { body: bodySchema },
},
license.guardApiRoute(async (ctx, req, res) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { addBasePath } from '../index';

export function registerGetAllRoute({ router, license }: RouteDependencies) {
router.get(
{ path: addBasePath('/index-templates'), validate: false },
{ path: addBasePath('/index_templates'), validate: false },
license.guardApiRoute(async (ctx, req, res) => {
const { callAsCurrentUser } = ctx.core.elasticsearch.legacy.client;
const managedTemplatePrefix = await getManagedTemplatePrefix(callAsCurrentUser);
Expand Down Expand Up @@ -55,7 +55,7 @@ const querySchema = schema.object({
export function registerGetOneRoute({ router, license, lib }: RouteDependencies) {
router.get(
{
path: addBasePath('/index-templates/{name}'),
path: addBasePath('/index_templates/{name}'),
validate: { params: paramsSchema, query: querySchema },
},
license.guardApiRoute(async (ctx, req, res) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const paramsSchema = schema.object({
export function registerUpdateRoute({ router, license, lib }: RouteDependencies) {
router.put(
{
path: addBasePath('/index-templates/{name}'),
path: addBasePath('/index_templates/{name}'),
validate: { body: bodySchema, params: paramsSchema },
},
license.guardApiRoute(async (ctx, req, res) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import { API_BASE_PATH, INDEX_PATTERNS } from './constants';

export const registerHelpers = ({ supertest }) => {
const getAllTemplates = () => supertest.get(`${API_BASE_PATH}/index-templates`);
const getAllTemplates = () => supertest.get(`${API_BASE_PATH}/index_templates`);

const getOneTemplate = (name, isLegacy = true) =>
supertest.get(`${API_BASE_PATH}/index-templates/${name}?legacy=${isLegacy}`);
supertest.get(`${API_BASE_PATH}/index_templates/${name}?legacy=${isLegacy}`);

const getTemplatePayload = (name, isLegacy = true) => ({
name,
Expand Down Expand Up @@ -50,17 +50,17 @@ export const registerHelpers = ({ supertest }) => {
});

const createTemplate = (payload) =>
supertest.post(`${API_BASE_PATH}/index-templates`).set('kbn-xsrf', 'xxx').send(payload);
supertest.post(`${API_BASE_PATH}/index_templates`).set('kbn-xsrf', 'xxx').send(payload);

const deleteTemplates = (templates) =>
supertest
.post(`${API_BASE_PATH}/delete-index-templates`)
.post(`${API_BASE_PATH}/delete_index_templates`)
.set('kbn-xsrf', 'xxx')
.send({ templates });

const updateTemplate = (payload, templateName) =>
supertest
.put(`${API_BASE_PATH}/index-templates/${templateName}`)
.put(`${API_BASE_PATH}/index_templates/${templateName}`)
.set('kbn-xsrf', 'xxx')
.send(payload);

Expand Down