-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Reporting] Convert test code to Typescript #65155
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filed an issue: #65338 |
||
} | ||
|
||
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,15 +67,15 @@ 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); | ||
}) | ||
); | ||
}, | ||
|
||
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<Function>} 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); | ||
}, | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this service is mistakenly using
/api/stats?extended
and returning the data in a different format where all the fields are snake_cased.