Skip to content

Commit

Permalink
adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiqueclarke committed May 10, 2022
1 parent 647e7da commit 5fa8d3e
Showing 1 changed file with 51 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,40 +83,10 @@ const createTestConfig = (extraConfigs: Record<string, any>, updatedAt?: string)

describe('monitor upgrade telemetry helpers', () => {
it('formats telemetry events', () => {
const actual = formatTelemetryEvent({ monitor: testConfig, kibanaVersion, errors });
expect(actual).toEqual({
stackVersion: kibanaVersion,
configId: sha256.create().update(testConfig.id).hex(),
locations: ['us_central', 'other'],
locationsCount: 2,
monitorNameLength: testConfig.attributes[ConfigKey.NAME].length,
updatedAt: testConfig.updated_at,
type: testConfig.attributes[ConfigKey.MONITOR_TYPE],
scriptType: undefined,
monitorInterval: 180000,
lastUpdatedAt: undefined,
deletedAt: undefined,
errors,
durationSinceLastUpdated: undefined,
revision: 1,
});
});

it.each([
[ConfigKey.SOURCE_INLINE, 'recorder', true],
[ConfigKey.SOURCE_INLINE, 'inline', false],
[ConfigKey.SOURCE_ZIP_URL, 'zip', false],
])('handles formatting scriptType for browser monitors', (config, scriptType, isRecorder) => {
const actual = formatTelemetryEvent({
monitor: createTestConfig({
[config]: 'test',
[ConfigKey.METADATA]: {
script_source: {
is_generated_script: isRecorder,
},
},
}),
monitor: testConfig,
kibanaVersion,
isInlineScript: false,
errors,
});
expect(actual).toEqual({
Expand All @@ -127,7 +97,7 @@ describe('monitor upgrade telemetry helpers', () => {
monitorNameLength: testConfig.attributes[ConfigKey.NAME].length,
updatedAt: testConfig.updated_at,
type: testConfig.attributes[ConfigKey.MONITOR_TYPE],
scriptType,
scriptType: undefined,
monitorInterval: 180000,
lastUpdatedAt: undefined,
deletedAt: undefined,
Expand All @@ -137,11 +107,51 @@ describe('monitor upgrade telemetry helpers', () => {
});
});

it.each([
[ConfigKey.SOURCE_INLINE, 'recorder', true, true],
[ConfigKey.SOURCE_INLINE, 'inline', false, true],
[ConfigKey.SOURCE_ZIP_URL, 'zip', false, false],
])(
'handles formatting scriptType for browser monitors',
(config, scriptType, isRecorder, isInlineScript) => {
const actual = formatTelemetryEvent({
monitor: createTestConfig({
[config]: 'test',
[ConfigKey.METADATA]: {
script_source: {
is_generated_script: isRecorder,
},
},
}),
isInlineScript,
kibanaVersion,
errors,
});
expect(actual).toEqual({
stackVersion: kibanaVersion,
configId: sha256.create().update(testConfig.id).hex(),
locations: ['us_central', 'other'],
locationsCount: 2,
monitorNameLength: testConfig.attributes[ConfigKey.NAME].length,
updatedAt: testConfig.updated_at,
type: testConfig.attributes[ConfigKey.MONITOR_TYPE],
scriptType,
monitorInterval: 180000,
lastUpdatedAt: undefined,
deletedAt: undefined,
errors,
durationSinceLastUpdated: undefined,
revision: 1,
});
}
);

it('handles formatting update events', () => {
const actual = formatTelemetryUpdateEvent(
createTestConfig({}, '2011-10-05T16:48:00.000Z'),
testConfig,
kibanaVersion,
false,
errors
);
expect(actual).toEqual({
Expand All @@ -167,6 +177,7 @@ describe('monitor upgrade telemetry helpers', () => {
testConfig,
kibanaVersion,
'2011-10-05T16:48:00.000Z',
false,
errors
);
expect(actual).toEqual({
Expand Down Expand Up @@ -198,12 +209,13 @@ describe('sendTelemetryEvents', () => {
});

it('should queue telemetry events with generic error', () => {
const event = formatTelemetryEvent({ monitor: testConfig, kibanaVersion, errors });
sendTelemetryEvents(
loggerMock,
eventsTelemetryMock,
formatTelemetryEvent({ monitor: testConfig, kibanaVersion, errors })
);
const event = formatTelemetryEvent({
monitor: testConfig,
kibanaVersion,
isInlineScript: true,
errors,
});
sendTelemetryEvents(loggerMock, eventsTelemetryMock, event);

expect(eventsTelemetryMock.queueTelemetryEvents).toHaveBeenCalledWith(MONITOR_UPDATE_CHANNEL, [
event,
Expand Down

0 comments on commit 5fa8d3e

Please sign in to comment.