diff --git a/x-pack/test/reporting/api/chromium_tests.js b/x-pack/test/reporting/api/chromium_tests.ts similarity index 77% rename from x-pack/test/reporting/api/chromium_tests.js rename to x-pack/test/reporting/api/chromium_tests.ts index 2d5a31bb40da3..75e8e3e70b5a5 100644 --- a/x-pack/test/reporting/api/chromium_tests.js +++ b/x-pack/test/reporting/api/chromium_tests.ts @@ -4,9 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import { OSS_KIBANA_ARCHIVE_PATH, OSS_DATA_ARCHIVE_PATH } from './constants'; +import { OSS_DATA_ARCHIVE_PATH, OSS_KIBANA_ARCHIVE_PATH } from './constants'; +import { FtrProviderContext } from '../ftr_provider_context'; -export default function({ loadTestFile, getService }) { +// eslint-disable-next-line import/no-default-export +export default function({ loadTestFile, getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const kibanaServer = getService('kibanaServer'); diff --git a/x-pack/test/reporting/api/constants.js b/x-pack/test/reporting/api/constants.ts similarity index 100% rename from x-pack/test/reporting/api/constants.js rename to x-pack/test/reporting/api/constants.ts diff --git a/x-pack/test/reporting/api/generate/index.js b/x-pack/test/reporting/api/generate/index.ts similarity index 69% rename from x-pack/test/reporting/api/generate/index.js rename to x-pack/test/reporting/api/generate/index.ts index 3e5f2d1fc1eb3..b9db0d465d005 100644 --- a/x-pack/test/reporting/api/generate/index.js +++ b/x-pack/test/reporting/api/generate/index.ts @@ -4,7 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -export default function({ loadTestFile }) { +import { FtrProviderContext } from '../../ftr_provider_context'; + +// eslint-disable-next-line import/no-default-export +export default function({ loadTestFile }: FtrProviderContext) { describe('CSV', function() { this.tags('ciGroup2'); loadTestFile(require.resolve('./csv_saved_search')); diff --git a/x-pack/test/reporting/api/generation_urls.js b/x-pack/test/reporting/api/generation_urls.ts similarity index 100% rename from x-pack/test/reporting/api/generation_urls.js rename to x-pack/test/reporting/api/generation_urls.ts diff --git a/x-pack/test/reporting/api/usage.js b/x-pack/test/reporting/api/usage.ts similarity index 93% rename from x-pack/test/reporting/api/usage.js rename to x-pack/test/reporting/api/usage.ts index c1005c441f463..e3ebcf9d3bab0 100644 --- a/x-pack/test/reporting/api/usage.js +++ b/x-pack/test/reporting/api/usage.ts @@ -5,22 +5,29 @@ */ import expect from '@kbn/expect'; +import { FtrProviderContext } from '../ftr_provider_context'; +import { ReportingUsageStats } from '../services/reporting_api'; import * as GenerationUrls from './generation_urls'; -export default function({ getService }) { +interface UsageStats { + reporting: ReportingUsageStats; +} + +// eslint-disable-next-line import/no-default-export +export default function({ getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const reportingAPI = getService('reportingAPI'); - const usageAPI = getService('usageAPI'); + const usageAPI = getService('usageAPI' as any); // NOTE Usage API service is not Typescript describe('reporting usage', () => { before(() => reportingAPI.deleteAllReportingIndexes()); afterEach(() => reportingAPI.deleteAllReportingIndexes()); describe('initial state', () => { - let usage; + let usage: UsageStats; before(async () => { - usage = await usageAPI.getUsageStats(); + usage = (await usageAPI.getUsageStats()) as UsageStats; }); it('shows reporting as available and enabled', async () => { diff --git a/x-pack/test/reporting/services/index.js b/x-pack/test/reporting/ftr_provider_context.d.ts similarity index 56% rename from x-pack/test/reporting/services/index.js rename to x-pack/test/reporting/ftr_provider_context.d.ts index d181e24442d2d..e3add3748f56d 100644 --- a/x-pack/test/reporting/services/index.js +++ b/x-pack/test/reporting/ftr_provider_context.d.ts @@ -4,4 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -export { ReportingAPIProvider } from './reporting_api'; +import { GenericFtrProviderContext } from '@kbn/test/types/ftr'; + +import { services } from './services'; + +export type FtrProviderContext = GenericFtrProviderContext; diff --git a/x-pack/test/reporting/services/index.ts b/x-pack/test/reporting/services/index.ts new file mode 100644 index 0000000000000..9684f2a8abc6c --- /dev/null +++ b/x-pack/test/reporting/services/index.ts @@ -0,0 +1,15 @@ +/* + * 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 { ReportingAPIProvider } from './reporting_api'; +import { services as xpackServices } from '../../functional/services'; + +export const services = { + ...xpackServices, + reportingAPI: ReportingAPIProvider, +}; + +export { ReportingAPIProvider }; diff --git a/x-pack/test/reporting/services/reporting_api.js b/x-pack/test/reporting/services/reporting_api.ts similarity index 68% rename from x-pack/test/reporting/services/reporting_api.js rename to x-pack/test/reporting/services/reporting_api.ts index 82fe6aea08ac3..1fa5fd7135708 100644 --- a/x-pack/test/reporting/services/reporting_api.js +++ b/x-pack/test/reporting/services/reporting_api.ts @@ -5,28 +5,57 @@ */ import expect from '@kbn/expect'; +// @ts-ignore no module definition import { indexTimestamp } from '../../../legacy/plugins/reporting/server/lib/esqueue/helpers/index_timestamp'; +import { FtrProviderContext } from '../ftr_provider_context'; -function removeWhitespace(str) { +interface PDFAppCounts { + app: { + [appName: string]: number; + }; + layout: { + [layoutType: string]: number; + }; +} + +export interface ReportingUsageStats { + available: boolean; + enabled: boolean; + total: number; + last_7_days: { + total: number; + printable_pdf: PDFAppCounts; + [jobType: string]: any; + }; + printable_pdf: PDFAppCounts; + status: any; + [jobType: string]: any; +} + +interface UsageStats { + reporting: ReportingUsageStats; +} + +function removeWhitespace(str: string) { return str.replace(/\s/g, ''); } -export function ReportingAPIProvider({ getService }) { +export function ReportingAPIProvider({ getService }: FtrProviderContext) { const log = getService('log'); const supertest = getService('supertest'); const esSupertest = getService('esSupertest'); return { - async waitForJobToFinish(downloadReportPath) { + async waitForJobToFinish(downloadReportPath: string) { log.debug(`Waiting for job to finish: ${downloadReportPath}`); const JOB_IS_PENDING_CODE = 503; const statusCode = await new Promise(resolve => { const intervalId = setInterval(async () => { - const response = await supertest + const response = (await supertest .get(downloadReportPath) .responseType('blob') - .set('kbn-xsrf', 'xxx'); + .set('kbn-xsrf', 'xxx')) as any; log.debug(`Report at path ${downloadReportPath} returned code ${response.statusCode}`); if (response.statusCode !== JOB_IS_PENDING_CODE) { clearInterval(intervalId); @@ -38,7 +67,7 @@ export function ReportingAPIProvider({ getService }) { expect(statusCode).to.be(200); }, - async expectAllJobsToFinishSuccessfully(jobPaths) { + async expectAllJobsToFinishSuccessfully(jobPaths: string[]) { await Promise.all( jobPaths.map(async path => { await this.waitForJobToFinish(path); @@ -46,7 +75,7 @@ export function ReportingAPIProvider({ getService }) { ); }, - async postJob(apiPath) { + async postJob(apiPath: string) { log.debug(`ReportingAPI.postJob(${apiPath})`); const { body } = await supertest .post(removeWhitespace(apiPath)) @@ -59,7 +88,7 @@ export function ReportingAPIProvider({ getService }) { * * @return {Promise} A function to call to clean up the index alias that was added. */ - async coerceReportsIntoExistingIndex(indexName) { + async coerceReportsIntoExistingIndex(indexName: string) { log.debug(`ReportingAPI.coerceReportsIntoExistingIndex(${indexName})`); // Adding an index alias coerces the report to be generated on an existing index which means any new @@ -96,35 +125,35 @@ export function ReportingAPIProvider({ getService }) { await esSupertest.delete('/.reporting*').expect(200); }, - expectRecentPdfAppStats(stats, app, count) { + expectRecentPdfAppStats(stats: UsageStats, app: string, count: number) { expect(stats.reporting.last_7_days.printable_pdf.app[app]).to.be(count); }, - expectAllTimePdfAppStats(stats, app, count) { + expectAllTimePdfAppStats(stats: UsageStats, app: string, count: number) { expect(stats.reporting.printable_pdf.app[app]).to.be(count); }, - expectRecentPdfLayoutStats(stats, layout, count) { + expectRecentPdfLayoutStats(stats: UsageStats, layout: string, count: number) { expect(stats.reporting.last_7_days.printable_pdf.layout[layout]).to.be(count); }, - expectAllTimePdfLayoutStats(stats, layout, count) { + expectAllTimePdfLayoutStats(stats: UsageStats, layout: string, count: number) { expect(stats.reporting.printable_pdf.layout[layout]).to.be(count); }, - expectRecentJobTypeTotalStats(stats, jobType, count) { + expectRecentJobTypeTotalStats(stats: UsageStats, jobType: string, count: number) { expect(stats.reporting.last_7_days[jobType].total).to.be(count); }, - expectAllTimeJobTypeTotalStats(stats, jobType, count) { + expectAllTimeJobTypeTotalStats(stats: UsageStats, jobType: string, count: number) { expect(stats.reporting[jobType].total).to.be(count); }, - getCompletedReportCount(stats) { + getCompletedReportCount(stats: UsageStats) { return stats.reporting.status.completed; }, - expectCompletedReportCount(stats, count) { + expectCompletedReportCount(stats: UsageStats, count: number) { expect(this.getCompletedReportCount(stats)).to.be(count); }, };