Skip to content

Commit

Permalink
Asserts deprecation config passes to router args
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaHeiligers committed Nov 7, 2024
1 parent f21b1ea commit 621cc36
Show file tree
Hide file tree
Showing 26 changed files with 251 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ import { registerLegacyExportRoute } from './legacy_import_export/export';
import { registerBulkResolveRoute } from './bulk_resolve';
import { registerDeleteUnknownTypesRoute } from './deprecations';

// export interface RouteDeprecationInfo {
// documentationUrl: string;
// severity: 'warning';
// reason: {
// type: 'deprecate' | 'remove';
// };
// }

export function registerRoutes({
http,
coreUsageData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from '@kbn/core-saved-objects-server-internal';
import { createHiddenTypeVariants, setupServer } from '@kbn/core-test-helpers-test-utils';
import { loggerMock } from '@kbn/logging-mocks';
import { setupConfig } from '../routes_test_utils';
import { deprecationMock, setupConfig } from '../routes_test_utils';

type SetupServerReturn = Awaited<ReturnType<typeof setupServer>>;

Expand Down Expand Up @@ -56,13 +56,7 @@ describe('POST /api/saved_objects/_bulk_create with allowApiAccess true', () =>
const logger = loggerMock.create();
const config = setupConfig(true);
const access = 'public';
const deprecationMock = {
documentationUrl: 'http://elastic.co',
severity: 'warning' as const,
reason: {
type: 'deprecate' as const,
},
};

registerBulkCreateRoute(router, {
config,
coreUsageData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
type InternalSavedObjectsRequestHandlerContext,
} from '@kbn/core-saved-objects-server-internal';
import { loggerMock } from '@kbn/logging-mocks';
import { setupConfig } from '../routes_test_utils';
import { deprecationMock, setupConfig } from '../routes_test_utils';

type SetupServerReturn = Awaited<ReturnType<typeof setupServer>>;

Expand Down Expand Up @@ -60,13 +60,7 @@ describe('POST /api/saved_objects/_bulk_delete with allowApiAccess as true', ()

const config = setupConfig(true);
const access = 'public';
const deprecationMock = {
documentationUrl: 'http://elastic.co',
severity: 'warning' as const,
reason: {
type: 'deprecate' as const,
},
};

registerBulkDeleteRoute(router, {
config,
coreUsageData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
type InternalSavedObjectsRequestHandlerContext,
} from '@kbn/core-saved-objects-server-internal';
import { loggerMock } from '@kbn/logging-mocks';
import { setupConfig } from '../routes_test_utils';
import { deprecationMock, setupConfig } from '../routes_test_utils';

type SetupServerReturn = Awaited<ReturnType<typeof setupServer>>;

Expand Down Expand Up @@ -58,13 +58,7 @@ describe('POST /api/saved_objects/_bulk_get with allowApiAccess true', () => {

const config = setupConfig(true);
const access = 'public';
const deprecationMock = {
documentationUrl: 'http://elastic.co',
severity: 'warning' as const,
reason: {
type: 'deprecate' as const,
},
};

registerBulkGetRoute(router, {
config,
coreUsageData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
type InternalSavedObjectsRequestHandlerContext,
} from '@kbn/core-saved-objects-server-internal';
import { loggerMock } from '@kbn/logging-mocks';
import { setupConfig } from '../routes_test_utils';
import { deprecationMock, setupConfig } from '../routes_test_utils';

type SetupServerReturn = Awaited<ReturnType<typeof setupServer>>;

Expand Down Expand Up @@ -59,13 +59,7 @@ describe('POST /api/saved_objects/_bulk_resolve with allowApiAccess true', () =>

const config = setupConfig(true);
const access = 'public';
const deprecationMock = {
documentationUrl: 'http://elastic.co',
severity: 'warning' as const,
reason: {
type: 'deprecate' as const,
},
};

registerBulkResolveRoute(router, {
config,
coreUsageData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
type InternalSavedObjectsRequestHandlerContext,
} from '@kbn/core-saved-objects-server-internal';
import { loggerMock } from '@kbn/logging-mocks';
import { setupConfig } from '../routes_test_utils';
import { deprecationMock, setupConfig } from '../routes_test_utils';

type SetupServerReturn = Awaited<ReturnType<typeof setupServer>>;
const testTypes = [
Expand Down Expand Up @@ -52,13 +52,7 @@ describe('PUT /api/saved_objects/_bulk_update with allowApiAccess true', () => {

const config = setupConfig(true);
const access = 'public';
const deprecationMock = {
documentationUrl: 'http://elastic.co',
severity: 'warning' as const,
reason: {
type: 'deprecate' as const,
},
};

registerBulkUpdateRoute(router, {
config,
coreUsageData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
type InternalSavedObjectsRequestHandlerContext,
} from '@kbn/core-saved-objects-server-internal';
import { loggerMock } from '@kbn/logging-mocks';
import { setupConfig } from '../routes_test_utils';
import { deprecationMock, setupConfig } from '../routes_test_utils';

type SetupServerReturn = Awaited<ReturnType<typeof setupServer>>;

Expand Down Expand Up @@ -58,13 +58,7 @@ describe('POST /api/saved_objects/{type} with allowApiAccess true', () => {
const logger = loggerMock.create();
const config = setupConfig(true);
const access = 'public';
const deprecationMock = {
documentationUrl: 'http://elastic.co',
severity: 'warning' as const,
reason: {
type: 'deprecate' as const,
},
};

registerCreateRoute(router, {
config,
coreUsageData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
type InternalSavedObjectsRequestHandlerContext,
} from '@kbn/core-saved-objects-server-internal';
import { loggerMock } from '@kbn/logging-mocks';
import { setupConfig } from '../routes_test_utils';
import { deprecationMock, setupConfig } from '../routes_test_utils';

type SetupServerReturn = Awaited<ReturnType<typeof setupServer>>;

Expand Down Expand Up @@ -55,13 +55,7 @@ describe('DELETE /api/saved_objects/{type}/{id} with allowApiAccess true', () =>
const logger = loggerMock.create();
const config = setupConfig(true);
const access = 'public';
const deprecationMock = {
documentationUrl: 'http://elastic.co',
severity: 'warning' as const,
reason: {
type: 'deprecate' as const,
},
};

registerDeleteRoute(router, {
config,
coreUsageData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
registerFindRoute,
type InternalSavedObjectsRequestHandlerContext,
} from '@kbn/core-saved-objects-server-internal';
import { setupConfig } from '../routes_test_utils';
import { deprecationMock, setupConfig } from '../routes_test_utils';

type SetupServerReturn = Awaited<ReturnType<typeof setupServer>>;

Expand Down Expand Up @@ -71,13 +71,7 @@ describe('GET /api/saved_objects/_find with allowApiAccess true', () => {

const config = setupConfig(true);
const access = 'public';
const deprecationMock = {
documentationUrl: 'http://elastic.co',
severity: 'warning' as const,
reason: {
type: 'deprecate' as const,
},
};

registerFindRoute(router, {
config,
coreUsageData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from '@kbn/core-saved-objects-server-internal';
import { createHiddenTypeVariants } from '@kbn/core-test-helpers-test-utils';
import { loggerMock } from '@kbn/logging-mocks';
import { setupConfig } from '../routes_test_utils';
import { deprecationMock, setupConfig } from '../routes_test_utils';

const coreId = Symbol('core');
const testTypes = [
Expand Down Expand Up @@ -80,13 +80,7 @@ describe('GET /api/saved_objects/{type}/{id} with allowApiAccess true', () => {

const config = setupConfig(true);
const access = 'public';
const deprecationMock = {
documentationUrl: 'http://elastic.co',
severity: 'warning' as const,
reason: {
type: 'deprecate' as const,
},
};

registerGetRoute(router, {
config,
coreUsageData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from '@kbn/core-saved-objects-server-internal';
import { createHiddenTypeVariants } from '@kbn/core-test-helpers-test-utils';
import { loggerMock } from '@kbn/logging-mocks';
import { setupConfig } from '../routes_test_utils';
import { deprecationMock, setupConfig } from '../routes_test_utils';

const coreId = Symbol('core');

Expand Down Expand Up @@ -80,13 +80,7 @@ describe('GET /api/saved_objects/resolve/{type}/{id} with allowApiAccess true',

const config = setupConfig(true);
const access = 'public';
const deprecationMock = {
documentationUrl: 'http://elastic.co',
severity: 'warning' as const,
reason: {
type: 'deprecate' as const,
},
};

registerResolveRoute(router, {
config,
coreUsageData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
type InternalSavedObjectsRequestHandlerContext,
} from '@kbn/core-saved-objects-server-internal';
import { loggerMock } from '@kbn/logging-mocks';
import { setupConfig } from '../routes_test_utils';
import { deprecationMock, setupConfig } from '../routes_test_utils';

type SetupServerReturn = Awaited<ReturnType<typeof setupServer>>;

Expand Down Expand Up @@ -56,13 +56,7 @@ describe('PUT /api/saved_objects/{type}/{id?} with allowApiAccess true', () => {

const config = setupConfig(true);
const access = 'public';
const deprecationMock = {
documentationUrl: 'http://elastic.co',
severity: 'warning' as const,
reason: {
type: 'deprecate' as const,
},
};

registerUpdateRoute(router, {
config,
coreUsageData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from '@kbn/core-saved-objects-server-internal';
import { createHiddenTypeVariants, setupServer } from '@kbn/core-test-helpers-test-utils';
import { loggerMock } from '@kbn/logging-mocks';
import { setupConfig } from './routes_test_utils';
import { deprecationMock, setupConfig } from './routes_test_utils';

type SetupServerReturn = Awaited<ReturnType<typeof setupServer>>;

Expand All @@ -37,6 +37,7 @@ describe('POST /api/saved_objects/_bulk_create', () => {
let savedObjectsClient: ReturnType<typeof savedObjectsClientMock.create>;
let coreUsageStatsClient: jest.Mocked<ICoreUsageStatsClient>;
let loggerWarnSpy: jest.SpyInstance;
let registrationSpy: jest.SpyInstance;

beforeEach(async () => {
({ server, httpSetup, handlerContext } = await setupServer());
Expand All @@ -57,16 +58,11 @@ describe('POST /api/saved_objects/_bulk_create', () => {

const logger = loggerMock.create();
loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation();
registrationSpy = jest.spyOn(router, 'post');

const config = setupConfig();
const access = 'public';
const deprecationMock = {
documentationUrl: 'http://elastic.co',
severity: 'warning' as const,
reason: {
type: 'deprecate' as const,
},
};

registerBulkCreateRoute(router, {
config,
coreUsageData,
Expand Down Expand Up @@ -206,4 +202,24 @@ describe('POST /api/saved_objects/_bulk_create', () => {
.expect(200);
expect(loggerWarnSpy).toHaveBeenCalledTimes(1);
});

it('passes deprecation config to the router arguments', async () => {
await supertest(httpSetup.server.listener)
.post('/api/saved_objects/_bulk_create')
.set('x-elastic-internal-origin', 'kibana')
.send([
{
id: 'abc1234',
type: 'index-pattern',
attributes: {
title: 'foo',
},
references: [],
},
])
.expect(200);
expect(registrationSpy.mock.calls[0][0]).toMatchObject({
options: { deprecated: deprecationMock },
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
type InternalSavedObjectsRequestHandlerContext,
} from '@kbn/core-saved-objects-server-internal';
import { loggerMock } from '@kbn/logging-mocks';
import { setupConfig } from './routes_test_utils';
import { deprecationMock, setupConfig } from './routes_test_utils';

type SetupServerReturn = Awaited<ReturnType<typeof setupServer>>;

Expand All @@ -36,6 +36,7 @@ describe('POST /api/saved_objects/_bulk_delete', () => {
let savedObjectsClient: ReturnType<typeof savedObjectsClientMock.create>;
let coreUsageStatsClient: jest.Mocked<ICoreUsageStatsClient>;
let loggerWarnSpy: jest.SpyInstance;
let registrationSpy: jest.SpyInstance;

beforeEach(async () => {
({ server, httpSetup, handlerContext } = await setupServer());
Expand All @@ -59,16 +60,11 @@ describe('POST /api/saved_objects/_bulk_delete', () => {

const logger = loggerMock.create();
loggerWarnSpy = jest.spyOn(logger, 'warn').mockImplementation();
registrationSpy = jest.spyOn(router, 'post');

const config = setupConfig();
const access = 'public';
const deprecationMock = {
documentationUrl: 'http://elastic.co',
severity: 'warning' as const,
reason: {
type: 'deprecate' as const,
},
};

registerBulkDeleteRoute(router, {
config,
coreUsageData,
Expand Down Expand Up @@ -175,4 +171,21 @@ describe('POST /api/saved_objects/_bulk_delete', () => {
.expect(400);
expect(loggerWarnSpy).toHaveBeenCalledTimes(1);
});

it('passes deprecation configuration to the router arguments', async () => {
await supertest(httpSetup.server.listener)
.post('/api/saved_objects/_bulk_delete')
.set('x-elastic-internal-origin', 'kibana')
.send([
{
id: 'hiddenID',
type: 'hidden-from-http',
},
])
.expect(400);

expect(registrationSpy.mock.calls[0][0]).toMatchObject({
options: { deprecated: deprecationMock },
});
});
});
Loading

0 comments on commit 621cc36

Please sign in to comment.