Skip to content

Commit

Permalink
Adds api integration tests for core to serverless common (#167570)
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaHeiligers authored Oct 2, 2023
1 parent 0ae3b23 commit 642ad7f
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const svlCommonApi = getService('svlCommonApi');
describe('/api/core/capabilities', () => {
it(`returns a 400 when an invalid app id is provided`, async () => {
const { body } = await supertest
.post('/api/core/capabilities')
.set(svlCommonApi.getInternalRequestHeader())
.send({
applications: ['dashboard', 'discover', 'bad%app'],
})
.expect(400);
expect(body).to.eql({
statusCode: 400,
error: 'Bad Request',
message: '[request body.applications.2]: Invalid application id',
});
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';

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

const compressionSuite = (url: string) => {
it(`uses compression when there isn't a referer`, async () => {
await supertest
.get(url)
.set('accept-encoding', 'gzip')
.set(svlCommonApi.getInternalRequestHeader())
.then((response) => {
expect(response.header).to.have.property('content-encoding', 'gzip');
});
});

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

describe('compression', () => {
describe('against an application page', () => {
compressionSuite('/app/kibana');
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

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

export default function ({ loadTestFile }: FtrProviderContext) {
describe('core', () => {
loadTestFile(require.resolve('./compression'));
loadTestFile(require.resolve('./translations'));
loadTestFile(require.resolve('./capabilities'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

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);
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
require.resolve('../../common/scripts_tests'),
require.resolve('../../common/search_oss'),
require.resolve('../../common/search_xpack'),
require.resolve('../../common/core'),
],
junit: {
reportName: 'Serverless Observability API Integration Tests - Common Group 1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
require.resolve('../../common/scripts_tests'),
require.resolve('../../common/search_oss'),
require.resolve('../../common/search_xpack'),
require.resolve('../../common/core'),
],
junit: {
reportName: 'Serverless Search API Integration Tests - Common Group 1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
require.resolve('../../common/scripts_tests'),
require.resolve('../../common/search_oss'),
require.resolve('../../common/search_xpack'),
require.resolve('../../common/core'),
],
junit: {
reportName: 'Serverless Security API Integration Tests - Common Group 1',
Expand Down

0 comments on commit 642ad7f

Please sign in to comment.