Skip to content

Commit

Permalink
Adds Clone from template test
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey Robertson committed Jun 17, 2020
1 parent ffd2cbb commit 32311c7
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions x-pack/plugins/canvas/server/routes/workpad/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
RequestHandler,
} from 'src/core/server';

const mockRouteContext = ({
let mockRouteContext = ({
core: {
savedObjects: {
client: savedObjectsClientMock.create(),
Expand All @@ -39,6 +39,14 @@ describe('POST workpad', () => {
let clock: sinon.SinonFakeTimers;

beforeEach(() => {
mockRouteContext = ({
core: {
savedObjects: {
client: savedObjectsClientMock.create(),
},
},
} as unknown) as RequestHandlerContext;

clock = sinon.useFakeTimers(now);

const httpService = httpServiceMock.createSetupContract();
Expand Down Expand Up @@ -70,7 +78,7 @@ describe('POST workpad', () => {
const response = await routeHandler(mockRouteContext, request, kibanaResponseFactory);

expect(response.status).toBe(200);
expect(response.payload).toEqual({ ok: true });
expect(response.payload).toEqual({ ok: true, id: `workpad-${mockedUUID}` });
expect(mockRouteContext.core.savedObjects.client.create).toBeCalledWith(
CANVAS_TYPE,
{
Expand Down Expand Up @@ -99,4 +107,45 @@ describe('POST workpad', () => {

expect(response.status).toBe(400);
});

it(`returns 200 when a template is cloned`, async () => {
const cloneFromTemplateBody = {
templateId: 'template-id',
};

const mockTemplateResponse = {
attributes: {
id: 'template-id',
template: {
pages: [],
},
},
};

(mockRouteContext.core.savedObjects.client.get as jest.Mock).mockResolvedValue(
mockTemplateResponse
);

const request = httpServerMock.createKibanaRequest({
method: 'post',
path: 'api/canvas/workpad',
body: cloneFromTemplateBody,
});

const response = await routeHandler(mockRouteContext, request, kibanaResponseFactory);

expect(response.status).toBe(200);
expect(response.payload).toEqual({ ok: true, id: `workpad-${mockedUUID}` });
expect(mockRouteContext.core.savedObjects.client.create).toBeCalledWith(
CANVAS_TYPE,
{
...mockTemplateResponse.attributes.template,
'@timestamp': nowIso,
'@created': nowIso,
},
{
id: `workpad-${mockedUUID}`,
}
);
});
});

0 comments on commit 32311c7

Please sign in to comment.