-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
3 changed files
with
129 additions
and
2 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
81 changes: 81 additions & 0 deletions
81
x-pack/plugins/case/server/routes/api/cases/configure/get_configure.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,81 @@ | ||
/* | ||
* 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 { kibanaResponseFactory, RequestHandler } from 'src/core/server'; | ||
import { httpServerMock } from 'src/core/server/mocks'; | ||
|
||
import { | ||
createMockSavedObjectsRepository, | ||
createRoute, | ||
createRouteContext, | ||
} from '../../__fixtures__'; | ||
|
||
import { mockCaseConfigure } from '../../__fixtures__/mock_saved_objects'; | ||
import { initGetCaseConfigure } from './get_configure'; | ||
|
||
describe('GET configuration', () => { | ||
let routeHandler: RequestHandler<any, any, any>; | ||
beforeAll(async () => { | ||
routeHandler = await createRoute(initGetCaseConfigure, 'get'); | ||
}); | ||
|
||
it('returns the configuration', async () => { | ||
const req = httpServerMock.createKibanaRequest({ | ||
path: '/api/cases/configure', | ||
method: 'get', | ||
}); | ||
|
||
const context = createRouteContext( | ||
createMockSavedObjectsRepository({ | ||
caseConfigureSavedObject: mockCaseConfigure, | ||
}) | ||
); | ||
|
||
const res = await routeHandler(context, req, kibanaResponseFactory); | ||
expect(res.status).toEqual(200); | ||
expect(res.payload).toEqual({ | ||
...mockCaseConfigure[0].attributes, | ||
version: mockCaseConfigure[0].version, | ||
}); | ||
}); | ||
|
||
it('handles undefined version correctly', async () => { | ||
const req = httpServerMock.createKibanaRequest({ | ||
path: '/api/cases/configure', | ||
method: 'get', | ||
}); | ||
|
||
const context = createRouteContext( | ||
createMockSavedObjectsRepository({ | ||
caseConfigureSavedObject: [{ ...mockCaseConfigure[0], version: undefined }], | ||
}) | ||
); | ||
|
||
const res = await routeHandler(context, req, kibanaResponseFactory); | ||
expect(res.status).toEqual(200); | ||
expect(res.payload).toEqual({ | ||
...mockCaseConfigure[0].attributes, | ||
version: '', | ||
}); | ||
}); | ||
|
||
it('returns an empty object when there is no configuration', async () => { | ||
const req = httpServerMock.createKibanaRequest({ | ||
path: '/api/cases/configure', | ||
method: 'get', | ||
}); | ||
|
||
const context = createRouteContext( | ||
createMockSavedObjectsRepository({ | ||
caseConfigureSavedObject: [], | ||
}) | ||
); | ||
|
||
const res = await routeHandler(context, req, kibanaResponseFactory); | ||
expect(res.status).toEqual(200); | ||
expect(res.payload).toEqual({}); | ||
}); | ||
}); |