-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new np router and fetch. Add placeholder schema validation
- Loading branch information
Aaron Caldwell
committed
Jan 3, 2020
1 parent
b67d203
commit 9cff803
Showing
7 changed files
with
138 additions
and
35 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
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
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
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
93 changes: 93 additions & 0 deletions
93
x-pack/legacy/plugins/file_upload/server/routes/file_upload.test.js
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,93 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { CANVAS_TYPE } from '../../../../../legacy/plugins/canvas/common/lib/constants'; | ||
import { initializeDeleteWorkpadRoute } from './delete'; | ||
import { | ||
IRouter, | ||
kibanaResponseFactory, | ||
RequestHandlerContext, | ||
RequestHandler, | ||
} from 'src/core/server'; | ||
import { | ||
savedObjectsClientMock, | ||
httpServiceMock, | ||
httpServerMock, | ||
loggingServiceMock, | ||
} from 'src/core/server/mocks'; | ||
|
||
const mockRouteContext = ({ | ||
core: { | ||
savedObjects: { | ||
client: savedObjectsClientMock.create(), | ||
}, | ||
}, | ||
} as unknown) as RequestHandlerContext; | ||
|
||
describe('POST file', () => { | ||
let routeHandler: RequestHandler<any, any, any>; | ||
|
||
beforeEach(() => { | ||
const httpService = httpServiceMock.createSetupContract(); | ||
const router = httpService.createRouter('') as jest.Mocked<IRouter>; | ||
initializeDeleteWorkpadRoute({ | ||
router, | ||
logger: loggingServiceMock.create().get(), | ||
}); | ||
|
||
routeHandler = router.delete.mock.calls[0][1]; | ||
}); | ||
|
||
it(`rejects file with no content`, async () => { | ||
}); | ||
it(`accepts request with correct structure`, async () => { | ||
}); | ||
it(`rejects request with incorrect structure`, async () => { | ||
}); | ||
it(`rejects request over size limit`, async () => { | ||
}); | ||
it(`accepts request within size limit`, async () => { | ||
}); | ||
it(`requires mappings if no id present`, async () => { | ||
}); | ||
it(`requires data & settings if id is present`, async () => { | ||
}); | ||
|
||
it(`returns 200 ok when the workpad is deleted`, async () => { | ||
const id = 'some-id'; | ||
const request = httpServerMock.createKibanaRequest({ | ||
method: 'delete', | ||
path: `api/canvas/workpad/${id}`, | ||
params: { | ||
id, | ||
}, | ||
}); | ||
|
||
const response = await routeHandler(mockRouteContext, request, kibanaResponseFactory); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.payload).toEqual({ ok: true }); | ||
expect(mockRouteContext.core.savedObjects.client.delete).toBeCalledWith(CANVAS_TYPE, id); | ||
}); | ||
|
||
it(`returns bad request if delete is unsuccessful`, async () => { | ||
const request = httpServerMock.createKibanaRequest({ | ||
method: 'delete', | ||
path: `api/canvas/workpad/some-id`, | ||
params: { | ||
id: 'some-id', | ||
}, | ||
}); | ||
|
||
(mockRouteContext.core.savedObjects.client.delete as jest.Mock).mockImplementationOnce(() => { | ||
throw mockRouteContext.core.savedObjects.client.errors.createBadRequestError('bad request'); | ||
}); | ||
|
||
const response = await routeHandler(mockRouteContext, request, kibanaResponseFactory); | ||
|
||
expect(response.status).toBe(400); | ||
}); | ||
}); |