Skip to content

Commit

Permalink
add FTR test for endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Nov 12, 2020
1 parent b085dee commit 83abbe1
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/core/server/i18n/routes/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const registerTranslationsRoute = (router: IRouter, locale: string) => {
},
},
(ctx, req, res) => {
if (req.params.locale !== locale) {
if (req.params.locale.toLowerCase() !== locale.toLowerCase()) {
return res.notFound({
body: `Unknown locale: ${req.params.locale}`,
});
Expand Down
55 changes: 55 additions & 0 deletions test/api_integration/apis/core/compression.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');

describe('compression', () => {
it(`uses compression when there isn't a referer`, async () => {
await supertest
.get('/app/kibana')
.set('accept-encoding', 'gzip')
.then((response) => {
expect(response.header).to.have.property('content-encoding', 'gzip');
});
});

it(`uses compression when there is a whitelisted referer`, async () => {
await supertest
.get('/app/kibana')
.set('accept-encoding', 'gzip')
.set('referer', 'https://some-host.com')
.then((response) => {
expect(response.header).to.have.property('content-encoding', 'gzip');
});
});

it(`doesn't use compression when there is a non-whitelisted referer`, async () => {
await supertest
.get('/app/kibana')
.set('accept-encoding', 'gzip')
.set('referer', 'https://other.some-host.com')
.then((response) => {
expect(response.header).not.to.have.property('content-encoding');
});
});
});
}
56 changes: 0 additions & 56 deletions test/api_integration/apis/core/index.js

This file was deleted.

27 changes: 27 additions & 0 deletions test/api_integration/apis/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ loadTestFile }: FtrProviderContext) {
describe('core', () => {
loadTestFile(require.resolve('./compression'));
loadTestFile(require.resolve('./translations'));
});
}
42 changes: 42 additions & 0 deletions test/api_integration/apis/core/translations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');

describe('translations', () => {
it(`returns the translations with the correct headers`, async () => {
await supertest.get('/translations/en.json').then((response) => {
expect(response.body.locale).to.eql('en');

expect(response.header).to.have.property('content-type', 'application/json; charset=utf-8');
expect(response.header).to.have.property('cache-control', 'must-revalidate');
expect(response.header).to.have.property('etag');
});
});

it(`returns a 404 when not using the correct locale`, async () => {
await supertest.get('/translations/foo.json').then((response) => {
expect(response.status).to.eql(404);
});
});
});
}

0 comments on commit 83abbe1

Please sign in to comment.