-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
146 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
x-pack/plugins/integration_assistant/server/routes/build_integration_routes.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { serverMock } from '../__mocks__/mock_server'; | ||
import { requestMock } from '../__mocks__/request'; | ||
import { requestContextMock } from '../__mocks__/request_context'; | ||
import { INTEGRATION_BUILDER_PATH } from '../../common'; | ||
import { registerIntegrationBuilderRoutes } from './build_integration_routes'; | ||
|
||
jest.mock('../integration_builder', () => { | ||
return { | ||
buildPackage: jest.fn().mockReturnValue(Buffer.from('{"test" : "test"}')), | ||
}; | ||
}); | ||
|
||
describe('registerIntegrationBuilderRoutes', () => { | ||
let server: ReturnType<typeof serverMock.create>; | ||
let { context } = requestContextMock.createTools(); | ||
|
||
const req = requestMock.create({ | ||
method: 'post', | ||
path: INTEGRATION_BUILDER_PATH, | ||
body: { | ||
integration: { | ||
name: 'Test', | ||
title: 'Title', | ||
description: 'Description', | ||
dataStreams: [ | ||
{ | ||
name: 'dsName', | ||
title: 'dsTitle', | ||
description: 'dsDesc', | ||
inputTypes: ['filestream'], | ||
rawSamples: ['{"ei":0}'], | ||
pipeline: { | ||
processors: [{ script: { source: {} } }], | ||
}, | ||
docs: [], | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
server = serverMock.create(); | ||
({ context } = requestContextMock.createTools()); | ||
registerIntegrationBuilderRoutes(server.router); | ||
}); | ||
|
||
it('Runs route and gets CheckPipelineResponse', async () => { | ||
const response = await server.inject(req, requestContextMock.convertContext(context)); | ||
expect(response.body).toEqual({ test: 'test' }); | ||
expect(response.status).toEqual(200); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
x-pack/plugins/integration_assistant/server/routes/related_routes.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { serverMock } from '../__mocks__/mock_server'; | ||
import { requestMock } from '../__mocks__/request'; | ||
import { requestContextMock } from '../__mocks__/request_context'; | ||
import { RELATED_GRAPH_PATH } from '../../common'; | ||
import { registerRelatedRoutes } from './related_routes'; | ||
|
||
const mockResult = jest.fn().mockResolvedValue({ | ||
results: { | ||
pipeline: { | ||
processors: [{ script: { source: {} } }], | ||
}, | ||
docs: [], | ||
}, | ||
}); | ||
|
||
jest.mock('../graphs/related', () => { | ||
return { | ||
getRelatedGraph: jest.fn().mockResolvedValue({ | ||
invoke: () => mockResult(), | ||
}), | ||
}; | ||
}); | ||
|
||
describe('registerRelatedRoutes', () => { | ||
let server: ReturnType<typeof serverMock.create>; | ||
let { context } = requestContextMock.createTools(); | ||
|
||
const req = requestMock.create({ | ||
method: 'post', | ||
path: RELATED_GRAPH_PATH, | ||
body: { | ||
packageName: 'pack', | ||
dataStreamName: 'testStream', | ||
rawSamples: ['{"ei":0}'], | ||
currentPipeline: { processors: [{ script: { source: {} } }] }, | ||
connectorId: 'testConnector', | ||
}, | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
server = serverMock.create(); | ||
({ context } = requestContextMock.createTools()); | ||
registerRelatedRoutes(server.router); | ||
}); | ||
|
||
it('Runs route and gets RelatedResponse', async () => { | ||
const response = await server.inject(req, requestContextMock.convertContext(context)); | ||
expect(response.body).toEqual({ | ||
results: { docs: [], pipeline: { processors: [{ script: { source: {} } }] } }, | ||
}); | ||
expect(response.status).toEqual(200); | ||
}); | ||
|
||
it('Runs route with badRequest', async () => { | ||
mockResult.mockResolvedValueOnce({}); | ||
const response = await server.inject(req, requestContextMock.convertContext(context)); | ||
expect(response.status).toEqual(400); | ||
}); | ||
}); |