Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some type issues in x-pack/test #167343

Merged
merged 12 commits into from
Sep 27, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function createWithCircuitBreakerTests({ getService }: FtrProvide
.expect(200);
objectRemover.add('space1', createdRule.id, 'rule', 'alerting');

const { body } = await supertest
await supertest
.post(`${getUrlPrefix('space1')}/api/alerting/rule`)
.set('kbn-xsrf', 'foo')
.send(getTestRuleData({ schedule: { interval: '10s' } }))
Expand All @@ -41,7 +41,7 @@ export default function createWithCircuitBreakerTests({ getService }: FtrProvide
.expect(200);
objectRemover.add('space1', createdRule.id, 'rule', 'alerting');

const { body } = await supertest
await supertest
.post(`${getUrlPrefix('space2')}/api/alerting/rule`)
.set('kbn-xsrf', 'foo')
.send(getTestRuleData({ schedule: { interval: '10s' } }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default function createRuleSuggestionValuesTests({ getService }: FtrProvi
describe('alerts/suggestions/values', async () => {
const esArchiver = getService('esArchiver');
const supertest = getService('supertest');
const supertestWithoutAuth = getService('supertestWithoutAuth');

before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/observability/alerts');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
IngestPutPipelineRequest,
} from '@elastic/elasticsearch/lib/api/types';

interface Pipeline {
export interface Pipeline {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see that this is used outside of this file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it's no longer relevant, but it was used in another time when this was fixed :/

name: string;
description?: string;
onFailureProcessors?: IngestProcessorContainer[];
Expand All @@ -21,7 +21,7 @@ interface Pipeline {
metadata?: Metadata;
}

interface IngestPutPipelineInternalRequest extends Omit<IngestPutPipelineRequest, 'id'> {
export interface IngestPutPipelineInternalRequest extends Omit<IngestPutPipelineRequest, 'id'> {
delanni marked this conversation as resolved.
Show resolved Hide resolved
name: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import expect from '@kbn/expect';
import {
AuthStackByField,
Direction,
UserAuthenticationsRequestOptions,
UserAuthenticationsStrategyResponse,
UsersQueries,
} from '@kbn/security-solution-plugin/common/search_strategy';
import type { UserAuthenticationsRequestOptions } from '@kbn/security-solution-plugin/common/api/search_strategy';

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

Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/apm_api_integration/common/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function RegistryProvider({ getService }: FtrProviderContext) {
await supertest
.get('/api/ml/saved_objects/sync')
.set('kbn-xsrf', 'foo')
.auth(ApmUsername.editorUser, kbnTestConfig.getUrlParts().password);
.auth(ApmUsername.editorUser, kbnTestConfig.getUrlParts().password!);
}
if (condition.archives.length) {
log('Loaded all archives');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

expect(status).to.be(200);
expect(body.validIndices.length).to.be.greaterThan(0);
expect(body.validIndices?.length).to.be.greaterThan(0);
expect(body.invalidIndices).to.eql([]);
});
});
Expand Down Expand Up @@ -102,7 +102,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

expect(status).to.be(200);
expect(body.validIndices.length).to.be.greaterThan(0);
expect(body.validIndices?.length).to.be.greaterThan(0);
expect(body.invalidIndices).to.eql([
{
isValid: false,
Expand Down Expand Up @@ -158,10 +158,10 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

expect(status).to.be(200);
expect(body.validIndices.length).to.be.greaterThan(0);
expect(body.invalidIndices.length).to.be(1);
expect(body.validIndices?.length).to.be.greaterThan(0);
expect(body.invalidIndices?.length).to.be(1);

expect(omit(body.invalidIndices[0], 'index')).to.eql({
expect(omit(body.invalidIndices?.[0], 'index')).to.eql({
isValid: false,
fieldMappings: { isValid: true },
ingestPipeline: { isValid: false },
Expand All @@ -187,9 +187,9 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

expect(status).to.be(200);
expect(body.validIndices.length).to.be.greaterThan(0);
expect(body.invalidIndices.length).to.be(1);
expect(omit(body.invalidIndices[0], 'index')).to.eql({
expect(body.validIndices?.length).to.be.greaterThan(0);
expect(body.invalidIndices?.length).to.be(1);
expect(omit(body.invalidIndices?.[0], 'index')).to.eql({
isValid: false,
fieldMappings: { isValid: true },
ingestPipeline: { isValid: false, id: 'logs-default-pipeline' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default ({ getService }: FtrProviderContext) => {
await waitForSignalsToBePresent(supertest, log, 1, [id]);
const signalsOpen = await getSignalsById(supertest, log, id);
const ips = signalsOpen.hits.hits.map((hit) => hit._source?.ip).sort();
expect(ips.flat(Number.MAX_SAFE_INTEGER)).to.eql([]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would kill the typescript typecheck by saying the expanded type is infinitely deep

expect(ips.flat(10)).to.eql([]);
});

it('should filter a CIDR range of "127.0.0.1/30"', async () => {
Expand Down Expand Up @@ -347,7 +347,7 @@ export default ({ getService }: FtrProviderContext) => {
await waitForSignalsToBePresent(supertest, log, 1, [id]);
const signalsOpen = await getSignalsById(supertest, log, id);
const ips = signalsOpen.hits.hits.map((hit) => hit._source?.ip).sort();
expect(ips.flat(Number.MAX_SAFE_INTEGER)).to.eql([]);
expect(ips.flat(10)).to.eql([]);
});
});

Expand Down Expand Up @@ -409,7 +409,7 @@ export default ({ getService }: FtrProviderContext) => {
await waitForSignalsToBePresent(supertest, log, 1, [id]);
const signalsOpen = await getSignalsById(supertest, log, id);
const ips = signalsOpen.hits.hits.map((hit) => hit._source?.ip).sort();
expect(ips.flat(Number.MAX_SAFE_INTEGER)).to.eql([]);
expect(ips.flat(10)).to.eql([]);
});
});

Expand Down Expand Up @@ -514,7 +514,7 @@ export default ({ getService }: FtrProviderContext) => {
await waitForSignalsToBePresent(supertest, log, 1, [id]);
const signalsOpen = await getSignalsById(supertest, log, id);
const ips = signalsOpen.hits.hits.map((hit) => hit._source?.ip).sort();
expect(ips.flat(Number.MAX_SAFE_INTEGER)).to.eql([]);
expect(ips.flat(10)).to.eql([]);
});

it('will return 2 results if we have a list which contains the CIDR ranges of "127.0.0.1/32, 127.0.0.2/31, 127.0.0.4/30"', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default ({ getService }: FtrProviderContext) => {
await waitForSignalsToBePresent(supertest, log, 1, [id]);
const signalsOpen = await getSignalsById(supertest, log, id);
const hits = signalsOpen.hits.hits.map((hit) => hit._source?.text).sort();
expect(hits.flat(Number.MAX_SAFE_INTEGER)).to.eql([]);
expect(hits.flat(10)).to.eql([]);
});
});

Expand Down Expand Up @@ -280,7 +280,7 @@ export default ({ getService }: FtrProviderContext) => {
await waitForSignalsToBePresent(supertest, log, 1, [id]);
const signalsOpen = await getSignalsById(supertest, log, id);
const hits = signalsOpen.hits.hits.map((hit) => hit._source?.text).sort();
expect(hits.flat(Number.MAX_SAFE_INTEGER)).to.eql([]);
expect(hits.flat(10)).to.eql([]);
});
});

Expand Down Expand Up @@ -342,7 +342,7 @@ export default ({ getService }: FtrProviderContext) => {
await waitForSignalsToBePresent(supertest, log, 1, [id]);
const signalsOpen = await getSignalsById(supertest, log, id);
const hits = signalsOpen.hits.hits.map((hit) => hit._source?.text).sort();
expect(hits.flat(Number.MAX_SAFE_INTEGER)).to.eql([]);
expect(hits.flat(10)).to.eql([]);
});
});

Expand Down Expand Up @@ -522,7 +522,7 @@ export default ({ getService }: FtrProviderContext) => {
await waitForSignalsToBePresent(supertest, log, 1, [id]);
const signalsOpen = await getSignalsById(supertest, log, id);
const hits = signalsOpen.hits.hits.map((hit) => hit._source?.text).sort();
expect(hits.flat(Number.MAX_SAFE_INTEGER)).to.eql([]);
expect(hits.flat(10)).to.eql([]);
});
});

Expand Down
1 change: 1 addition & 0 deletions x-pack/test/disable_ems/tests/fonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

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

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const PageObjects = getPageObjects(['maps']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export default function (providerContext: FtrProviderContext) {
'https://some.source.proxy:3232'
);

const res = await supertest
await supertest
.put(`/api/fleet/agent_download_sources/${downloadSourceId}`)
.set('kbn-xsrf', 'xxxx')
.send({
Expand Down
6 changes: 5 additions & 1 deletion x-pack/test/fleet_api_integration/apis/fleet_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ export default function (providerContext: FtrProviderContext) {
);
});

async function waitForAgents(expectedAgentCount: number, attempts: number, _attemptsMade = 0) {
async function waitForAgents(
expectedAgentCount: number,
attempts: number,
_attemptsMade = 0
): Promise<any> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Promise<GetAgentsResponse> that should be imported from @kbn/fleet-plugin/common

Copy link
Contributor

@watson watson Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip. I opened a PR to fix: #167488

const { body: apiResponse } = await supertest
.get(`/api/fleet/agents?showInactive=true`)
.set('kbn-xsrf', 'xxxx')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ACTION_TEST_SUBJ = `embeddablePanelAction-${ACTION_ID}`;

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const drilldowns = getService('dashboardDrilldownsManage');
const { dashboard, discover, common, timePicker } = getPageObjects([
const { dashboard, discover, timePicker } = getPageObjects([
'dashboard',
'discover',
'common',
Expand All @@ -28,7 +28,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
describe('Explore underlying data - chart action', () => {
describe('value click action', () => {
it('action exists in chart click popup menu', async () => {
await PageObjects.dashboard.navigateToApp();
await dashboard.navigateToApp();
await dashboard.preserveCrossAppState();
await dashboard.loadSavedDashboard(drilldowns.DASHBOARD_WITH_PIE_CHART_NAME);
await pieChart.clickOnPieSlice('160,000');
Expand Down Expand Up @@ -60,7 +60,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
let originalTimeRangeDurationHours: number | undefined;

it('action exists in chart brush popup menu', async () => {
await PageObjects.dashboard.navigateToApp();
await dashboard.navigateToApp();
await dashboard.preserveCrossAppState();
await dashboard.loadSavedDashboard(drilldowns.DASHBOARD_WITH_AREA_CHART_NAME);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { TRANSFORM_STATE } from '@kbn/transform-plugin/common/constants';
import type { MappingTypeMapping } from '@elastic/elasticsearch/lib/api/types';

import type { FtrProviderContext } from '../../../../ftr_provider_context';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ class TagAssignmentFlyout extends FtrService {
*/
export class TagManagementPageObject extends FtrService {
private readonly testSubjects = this.ctx.getService('testSubjects');
private readonly find = this.ctx.getService('find');
private readonly browser = this.ctx.getService('browser');
private readonly retry = this.ctx.getService('retry');
private readonly header = this.ctx.getPageObject('header');
Expand Down