Skip to content

Commit

Permalink
Warn user only if provided the includeComment query param
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Feb 9, 2022
1 parent eb3c26a commit 4d293cc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
19 changes: 13 additions & 6 deletions x-pack/plugins/cases/server/routes/api/cases/get_case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,24 @@ export function initGetCaseApi({ router, logger, kibanaVersion }: RouteDeps) {
},
async (context, request, response) => {
try {
logger.warn(
`The query parameter 'includeComments' of the get case API '${CASE_DETAILS_URL}' is deprecated`
);
const isIncludeCommentsParamProvidedByTheUser =
request.url.searchParams.has('includeComments');

if (isIncludeCommentsParamProvidedByTheUser) {
logger.warn(
`The query parameter 'includeComments' of the get case API '${CASE_DETAILS_URL}' is deprecated`
);
}

const casesClient = await context.cases.getCasesClient();
const id = request.params.case_id;

return response.ok({
headers: {
...getWarningHeader(kibanaVersion, 'Deprecated query parameter includeComments'),
},
...(isIncludeCommentsParamProvidedByTheUser && {
headers: {
...getWarningHeader(kibanaVersion, 'Deprecated query parameter includeComments'),
},
}),
body: await casesClient.cases.get({
id,
includeComments: request.query.includeComments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,26 @@ export default ({ getService }: FtrProviderContext): void => {
});

describe('deprecations', () => {
it('should return a warning header', async () => {
for (const paramValue of [true, false]) {
it(`should return a warning header if includeComments=${paramValue}`, async () => {
const theCase = await createCase(supertest, postCaseReq);
const res = await supertest
.get(`${getCaseDetailsUrl(theCase.id)}?includeComments=${paramValue}`)
.expect(200);
const warningHeader = res.header.warning;

assertWarningHeader(warningHeader);

const warningValue = extractWarningValueFromWarningHeader(warningHeader);
expect(warningValue).to.be('Deprecated query parameter includeComments');
});
}

it('should not return a warning header if includeComments is not provided', async () => {
const theCase = await createCase(supertest, postCaseReq);
const res = await supertest.get(getCaseDetailsUrl(theCase.id)).expect(200);
const warningHeader = res.header.warning;

assertWarningHeader(warningHeader);

const warningValue = extractWarningValueFromWarningHeader(warningHeader);
expect(warningValue).to.be('Deprecated query parameter includeComments');
expect(warningHeader).to.be(undefined);
});
});
});
Expand Down

0 comments on commit 4d293cc

Please sign in to comment.