Skip to content

Commit

Permalink
fix schema test
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Aug 14, 2020
1 parent 559e735 commit 7064e7a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 34 deletions.
35 changes: 35 additions & 0 deletions x-pack/plugins/reporting/server/config/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,41 @@ describe('Reporting Config Schema', () => {
});
});

it('allows Duration values for certain keys', () => {
expect(ConfigSchema.validate({ queue: { timeout: '2m' } }).queue.timeout).toMatchInlineSnapshot(
`"PT2M"`
);

expect(
ConfigSchema.validate({ capture: { loadDelay: '3s' } }).capture.loadDelay
).toMatchInlineSnapshot(`"PT3S"`);

expect(
ConfigSchema.validate({
capture: { timeouts: { openUrl: '1m', waitForElements: '30s', renderComplete: '10s' } },
}).capture.timeouts
).toMatchInlineSnapshot(`
Object {
"openUrl": "PT1M",
"renderComplete": "PT10S",
"waitForElements": "PT30S",
}
`);

expect(
ConfigSchema.validate({ csv: { scroll: { duration: '1m' } } }).csv.scroll.duration
).toMatchInlineSnapshot(`"1m"`);
});

it('allows ByteSizeValue values for certain keys', () => {
expect(ConfigSchema.validate({ csv: { maxSizeBytes: '12mb' } }).csv.maxSizeBytes)
.toMatchInlineSnapshot(`
ByteSizeValue {
"valueInBytes": 12582912,
}
`);
});

it(`allows optional settings`, () => {
// encryption key
expect(
Expand Down
57 changes: 23 additions & 34 deletions x-pack/plugins/reporting/server/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { schema, TypeOf } from '@kbn/config-schema';
import moment from 'moment';

const KibanaServerSchema = schema.object({
hostname: schema.maybe(
Expand Down Expand Up @@ -35,10 +34,7 @@ const QueueSchema = schema.object({
pollEnabled: schema.boolean({ defaultValue: true }),
pollInterval: schema.number({ defaultValue: 3000 }),
pollIntervalErrorMultiplier: schema.number({ defaultValue: 10 }),
timeout: schema.oneOf([
schema.number({ defaultValue: 120000 }),
schema.duration({ defaultValue: moment.duration(2, 'm') }),
]),
timeout: schema.oneOf([schema.number(), schema.duration()], { defaultValue: 120000 }),
});

const RulesSchema = schema.object({
Expand All @@ -49,18 +45,9 @@ const RulesSchema = schema.object({

const CaptureSchema = schema.object({
timeouts: schema.object({
openUrl: schema.oneOf([
schema.number({ defaultValue: 30000 }),
schema.duration({ defaultValue: moment.duration(1, 'm') }),
]),
waitForElements: schema.oneOf([
schema.number({ defaultValue: 30000 }),
schema.duration({ defaultValue: moment.duration(30, 's') }),
]),
renderComplete: schema.oneOf([
schema.number({ defaultValue: 30000 }),
schema.duration({ defaultValue: moment.duration(30, 's') }),
]),
openUrl: schema.oneOf([schema.number(), schema.duration()], { defaultValue: 30000 }),
waitForElements: schema.oneOf([schema.number(), schema.duration()], { defaultValue: 30000 }),
renderComplete: schema.oneOf([schema.number(), schema.duration()], { defaultValue: 30000 }),
}),
networkPolicy: schema.object({
enabled: schema.boolean({ defaultValue: true }),
Expand All @@ -80,10 +67,7 @@ const CaptureSchema = schema.object({
width: schema.number({ defaultValue: 1950 }),
height: schema.number({ defaultValue: 1200 }),
}),
loadDelay: schema.oneOf([
schema.number({ defaultValue: 30000 }),
schema.duration({ defaultValue: moment.duration(3, 's') }),
]),
loadDelay: schema.oneOf([schema.number(), schema.duration()], { defaultValue: 3000 }),
browser: schema.object({
autoDownload: schema.conditional(
schema.contextRef('dist'),
Expand Down Expand Up @@ -129,13 +113,24 @@ const CsvSchema = schema.object({
checkForFormulas: schema.boolean({ defaultValue: true }),
escapeFormulaValues: schema.boolean({ defaultValue: false }),
enablePanelActionDownload: schema.boolean({ defaultValue: true }),
maxSizeBytes: schema.oneOf([
schema.number({ defaultValue: 1024 * 1024 * 10 }),
schema.byteSize({ defaultValue: '10mb' }),
]),
maxSizeBytes: schema.oneOf([schema.number(), schema.byteSize()], {
defaultValue: 1024 * 1024 * 10,
}),
useByteOrderMarkEncoding: schema.boolean({ defaultValue: false }),
scroll: schema.object({
duration: schema.duration({ defaultValue: moment.duration(30, 's') }),
duration: schema.oneOf(
[
schema.string({
validate(value) {
if (!/^[0-9]+(d|h|m|s|ms|micros|nanos)$/.test(value)) {
return 'must be a duration string';
}
},
}),
schema.duration(),
],
{ defaultValue: '30s' }
),
size: schema.number({ defaultValue: 500 }),
}),
});
Expand All @@ -155,17 +150,11 @@ const IndexSchema = schema.string({ defaultValue: '.reporting' });

const PollSchema = schema.object({
jobCompletionNotifier: schema.object({
interval: schema.oneOf([
schema.number({ defaultValue: 10000 }),
schema.duration({ defaultValue: moment.duration(10, 's') }),
]),
interval: schema.oneOf([schema.number(), schema.duration()], { defaultValue: 10000 }),
intervalErrorMultiplier: schema.number({ defaultValue: 5 }),
}),
jobsRefresh: schema.object({
interval: schema.oneOf([
schema.number({ defaultValue: 5000 }),
schema.duration({ defaultValue: moment.duration(5, 's') }),
]),
interval: schema.oneOf([schema.number(), schema.duration()], { defaultValue: 5000 }),
intervalErrorMultiplier: schema.number({ defaultValue: 5 }),
}),
});
Expand Down

0 comments on commit 7064e7a

Please sign in to comment.