Skip to content

Commit

Permalink
[7.x] Convert Index Templates API routes to snakecase. (elastic#68463) (
Browse files Browse the repository at this point in the history
elastic#68653)

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
cjcenizal and elasticmachine authored Jun 9, 2020
1 parent f23ec71 commit 859201d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
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 @@ -212,14 +212,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 @@ -233,7 +233,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 @@ -244,7 +244,7 @@ export function useLoadIndexTemplate(name: TemplateDeserialized['name'], isLegac
export async function saveTemplate(template: TemplateDeserialized, isClone?: boolean) {
const includeTypeName = doMappingsHaveType(template.template.mappings);
const result = await sendRequest({
path: `${API_BASE_PATH}/index-templates`,
path: `${API_BASE_PATH}/index_templates`,
method: 'post',
body: JSON.stringify(template),
query: {
Expand All @@ -263,7 +263,7 @@ export async function updateTemplate(template: TemplateDeserialized) {
const includeTypeName = doMappingsHaveType(template.template.mappings);
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),
query: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const querySchema = schema.object({

export function registerCreateRoute({ router, license, lib }: RouteDependencies) {
router.post(
{ path: addBasePath('/index-templates'), validate: { body: bodySchema, query: querySchema } },
{ path: addBasePath('/index_templates'), validate: { body: bodySchema, query: querySchema } },
license.guardApiRoute(async (ctx, req, res) => {
const { callAsCurrentUser } = ctx.core.elasticsearch.legacy.client;
const { include_type_name } = req.query as TypeOf<typeof querySchema>;
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 @@ -57,7 +57,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 @@ -22,7 +22,7 @@ const querySchema = 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, query: querySchema },
},
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

0 comments on commit 859201d

Please sign in to comment.