Skip to content

Commit

Permalink
request no longer passed to JobServiceProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 committed Feb 12, 2020
1 parent 1d28a85 commit 9d10143
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const jobs = {

jobsWithTimerange(dateFormatTz) {
return http({
url: `${basePath()}/jobs/jobs_with_timerange`,
url: `${basePath()}/jobs/jobs_with_time_range`,
method: 'POST',
data: {
dateFormatTz,
Expand Down
10 changes: 5 additions & 5 deletions x-pack/legacy/plugins/ml/server/models/job_service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import {
topCategoriesProvider,
} from './new_job';

export function jobServiceProvider(callAsCurrentUser, request) {
export function jobServiceProvider(callAsCurrentUser) {
return {
...datafeedsProvider(callAsCurrentUser),
...jobsProvider(callAsCurrentUser),
...groupsProvider(callAsCurrentUser),
...newJobCapsProvider(callAsCurrentUser, request),
...newJobChartsProvider(callAsCurrentUser, request),
...categorizationExamplesProvider(callAsCurrentUser, request),
...topCategoriesProvider(callAsCurrentUser, request),
...newJobCapsProvider(callAsCurrentUser),
...newJobChartsProvider(callAsCurrentUser),
...categorizationExamplesProvider(callAsCurrentUser),
...topCategoriesProvider(callAsCurrentUser),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import cloudwatchJobCaps from './__mocks__/results/cloudwatch_rollup_job_caps.js
describe('job_service - job_caps', () => {
let callWithRequestNonRollupMock: jest.Mock;
let callWithRequestRollupMock: jest.Mock;
let requestMock: any;
let savedObjectsClientMock: any;

beforeEach(() => {
callWithRequestNonRollupMock = jest.fn((action: string) => {
Expand All @@ -37,32 +37,28 @@ describe('job_service - job_caps', () => {
}
});

requestMock = {
getSavedObjectsClient: jest.fn(() => {
return {
async find() {
return Promise.resolve(kibanaSavedObjects);
},
};
}),
savedObjectsClientMock = {
async find() {
return Promise.resolve(kibanaSavedObjects);
},
};
});

describe('farequote newJobCaps()', () => {
it('can get job caps for index pattern', async done => {
const indexPattern = 'farequote-*';
const isRollup = false;
const { newJobCaps } = newJobCapsProvider(callWithRequestNonRollupMock, requestMock);
const response = await newJobCaps(indexPattern, isRollup);
const { newJobCaps } = newJobCapsProvider(callWithRequestNonRollupMock);
const response = await newJobCaps(indexPattern, isRollup, savedObjectsClientMock);
expect(response).toEqual(farequoteJobCaps);
done();
});

it('can get rollup job caps for non rollup index pattern', async done => {
const indexPattern = 'farequote-*';
const isRollup = true;
const { newJobCaps } = newJobCapsProvider(callWithRequestNonRollupMock, requestMock);
const response = await newJobCaps(indexPattern, isRollup);
const { newJobCaps } = newJobCapsProvider(callWithRequestNonRollupMock);
const response = await newJobCaps(indexPattern, isRollup, savedObjectsClientMock);
expect(response).toEqual(farequoteJobCapsEmpty);
done();
});
Expand All @@ -72,17 +68,17 @@ describe('job_service - job_caps', () => {
it('can get rollup job caps for rollup index pattern', async done => {
const indexPattern = 'cloud_roll_index';
const isRollup = true;
const { newJobCaps } = newJobCapsProvider(callWithRequestRollupMock, requestMock);
const response = await newJobCaps(indexPattern, isRollup);
const { newJobCaps } = newJobCapsProvider(callWithRequestRollupMock);
const response = await newJobCaps(indexPattern, isRollup, savedObjectsClientMock);
expect(response).toEqual(cloudwatchJobCaps);
done();
});

it('can get non rollup job caps for rollup index pattern', async done => {
const indexPattern = 'cloud_roll_index';
const isRollup = false;
const { newJobCaps } = newJobCapsProvider(callWithRequestRollupMock, requestMock);
const response = await newJobCaps(indexPattern, isRollup);
const { newJobCaps } = newJobCapsProvider(callWithRequestRollupMock);
const response = await newJobCaps(indexPattern, isRollup, savedObjectsClientMock);
expect(response).not.toEqual(cloudwatchJobCaps);
done();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Request } from 'src/legacy/server/kbn_server';
import { SavedObjectsClientContract } from 'kibana/server';
import { Aggregation, Field, NewJobCaps } from '../../../../common/types/fields';
import { fieldServiceProvider } from './field_service';
Expand All @@ -13,7 +12,7 @@ interface NewJobCapsResponse {
[indexPattern: string]: NewJobCaps;
}

export function newJobCapsProvider(callWithRequest: any, request: Request) {
export function newJobCapsProvider(callWithRequest: any) {
async function newJobCaps(
indexPattern: string,
isRollup: boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const analyzerSchema = {
),
};

export const catFieldExamplesSchema = {
export const categorizationFieldExamplesSchema = {
indexPatternTitle: schema.string(),
query: schema.any(),
size: schema.number(),
Expand Down Expand Up @@ -64,6 +64,12 @@ export const lookBackProgressSchema = {
export const topCategoriesSchema = { jobId: schema.string(), count: schema.number() };

export const updateGroupsSchema = {
job_id: schema.string(),
groups: schema.arrayOf(schema.maybe(schema.string())),
jobs: schema.maybe(
schema.arrayOf(
schema.object({
job_id: schema.maybe(schema.string()),
groups: schema.arrayOf(schema.maybe(schema.string())),
})
)
),
};
13 changes: 6 additions & 7 deletions x-pack/legacy/plugins/ml/server/routes/job_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { licensePreRoutingFactory } from '../new_platform/licence_check_pre_rout
import { wrapError } from '../client/error_wrapper';
import { RouteInitialization } from '../new_platform/plugin';
import {
catFieldExamplesSchema,
categorizationFieldExamplesSchema,
chartSchema,
datafeedIdsSchema,
forceStartDatafeedSchema,
Expand Down Expand Up @@ -174,13 +174,13 @@ export function jobServiceRoutes({ xpackMainPlugin, router }: RouteInitializatio
/**
* @apiGroup JobService
*
* @api {post} /api/ml/jobs/jobs_with_timerange
* @api {post} /api/ml/jobs/jobs_with_time_range
* @apiName JobsWithTimerange
* @apiDescription Creates a list of jobs with data about the job's timerange
*/
router.post(
{
path: '/api/ml/jobs/jobs_with_timerange',
path: '/api/ml/jobs/jobs_with_time_range',
validate: {
body: schema.object(jobsWithTimerangeSchema),
},
Expand Down Expand Up @@ -359,7 +359,7 @@ export function jobServiceRoutes({ xpackMainPlugin, router }: RouteInitializatio
const { indexPattern } = request.params;
const isRollup = request.query.rollup === 'true';
const savedObjectsClient = context.core.savedObjects.client;
const { newJobCaps } = jobServiceProvider(context.ml!.mlClient.callAsCurrentUser, request);
const { newJobCaps } = jobServiceProvider(context.ml!.mlClient.callAsCurrentUser);
const resp = await newJobCaps(indexPattern, isRollup, savedObjectsClient);

return response.ok({
Expand Down Expand Up @@ -452,8 +452,7 @@ export function jobServiceRoutes({ xpackMainPlugin, router }: RouteInitializatio
} = request.body;

const { newJobPopulationChart } = jobServiceProvider(
context.ml!.mlClient.callAsCurrentUser,
request
context.ml!.mlClient.callAsCurrentUser
);
const resp = await newJobPopulationChart(
indexPatternTitle,
Expand Down Expand Up @@ -541,7 +540,7 @@ export function jobServiceRoutes({ xpackMainPlugin, router }: RouteInitializatio
{
path: '/api/ml/jobs/categorization_field_examples',
validate: {
body: schema.object(catFieldExamplesSchema),
body: schema.object(categorizationFieldExamplesSchema),
},
},
licensePreRoutingFactory(xpackMainPlugin, async (context, request, response) => {
Expand Down

0 comments on commit 9d10143

Please sign in to comment.