Skip to content

Commit

Permalink
Fix jest integration tests for import and resolve import errors
Browse files Browse the repository at this point in the history
These broke due to the recently merged code for reading request ID
from the X-Opaque-Id header in #71019.
  • Loading branch information
jportner committed Aug 22, 2020
1 parent 3958c02 commit 1e8a3bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { SavedObjectsErrorHelpers } from '../..';

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

const { v4: uuidv4 } = jest.requireActual('uuid');
const allowedTypes = ['index-pattern', 'visualization', 'dashboard'];
const config = { maxImportPayloadBytes: 10485760, maxImportExportSize: 10000 } as SavedObjectConfig;
const URL = '/internal/saved_objects/_import';
Expand All @@ -54,7 +55,7 @@ describe(`POST ${URL}`, () => {

beforeEach(async () => {
mockUuidv4.mockReset();
mockUuidv4.mockImplementation(() => jest.requireActual('uuidv4'));
mockUuidv4.mockImplementation(() => uuidv4());
({ server, httpSetup, handlerContext } = await setupServer());
handlerContext.savedObjects.typeRegistry.getImportableAndExportableTypes.mockReturnValue(
allowedTypes.map(createExportableType)
Expand Down Expand Up @@ -489,6 +490,7 @@ describe(`POST ${URL}`, () => {
const result = await supertest(httpSetup.server.listener)
.post(`${URL}?createNewCopies=true`)
.set('content-Type', 'multipart/form-data; boundary=EXAMPLE')
.set('x-opaque-id', uuidv4()) // prevents src/core/server/http/http_tools.ts from using our mocked uuidv4 to generate a unique ID for this request
.send(
[
'--EXAMPLE',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { SavedObjectConfig } from '../../saved_objects_config';

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

const { v4: uuidv4 } = jest.requireActual('uuid');
const allowedTypes = ['index-pattern', 'visualization', 'dashboard'];
const config = { maxImportPayloadBytes: 10485760, maxImportExportSize: 10000 } as SavedObjectConfig;
const URL = '/api/saved_objects/_resolve_import_errors';
Expand Down Expand Up @@ -58,7 +59,7 @@ describe(`POST ${URL}`, () => {

beforeEach(async () => {
mockUuidv4.mockReset();
mockUuidv4.mockImplementation(() => jest.requireActual('uuidv4'));
mockUuidv4.mockImplementation(() => uuidv4());
({ server, httpSetup, handlerContext } = await setupServer());
handlerContext.savedObjects.typeRegistry.getImportableAndExportableTypes.mockReturnValue(
allowedTypes.map(createExportableType)
Expand Down

0 comments on commit 1e8a3bb

Please sign in to comment.