diff --git a/lib/hydro.js b/lib/hydro.js index df06602ae5f5..6ef062e7e7bc 100644 --- a/lib/hydro.js +++ b/lib/hydro.js @@ -8,7 +8,10 @@ const SCHEMAS = { search: 'docs.v0.SearchEvent', navigate: 'docs.v0.NavigateEvent', survey: 'docs.v0.SurveyEvent', - experiment: 'docs.v0.ExperimentEvent' + experiment: 'docs.v0.ExperimentEvent', + redirect: 'docs.v0.RedirectEvent', + clipboard: 'docs.v0.ClipboardEvent', + print: 'docs.v0.PrintEvent' } module.exports = class Hydro { diff --git a/lib/schema-event.js b/lib/schema-event.js index 801bf8249cef..bf7fcb429e42 100644 --- a/lib/schema-event.js +++ b/lib/schema-event.js @@ -300,6 +300,69 @@ const experimentSchema = { } } +const redirectSchema = { + additionalProperties: false, + required: [ + 'type', + 'context', + 'redirect_from', + 'redirect_to' + ], + properties: { + context, + type: { + type: 'string', + pattern: '^redirect$' + }, + redirect_from: { + type: 'string', + description: 'The requested href.', + format: 'uri-reference' + }, + redirect_to: { + type: 'string', + description: 'The destination href of the redirect.', + format: 'uri-reference' + } + } +} + +const clipboardSchema = { + additionalProperties: false, + required: [ + 'type', + 'context', + 'clipboard_operation' + ], + properties: { + context, + type: { + type: 'string', + pattern: '^clipboard$' + }, + clipboard_operation: { + type: 'string', + description: 'Which clipboard operation the user is performing.', + enum: ['copy', 'paste', 'cut'] + } + } +} + +const printSchema = { + additionalProperties: false, + required: [ + 'type', + 'context' + ], + properties: { + context, + type: { + type: 'string', + pattern: '^print$' + } + } +} + module.exports = { oneOf: [ pageSchema, @@ -308,6 +371,9 @@ module.exports = { searchSchema, navigateSchema, surveySchema, - experimentSchema + experimentSchema, + redirectSchema, + clipboardSchema, + printSchema ] } diff --git a/tests/rendering/events.js b/tests/rendering/events.js index 3f1950ae4783..e7912ee80c93 100644 --- a/tests/rendering/events.js +++ b/tests/rendering/events.js @@ -411,4 +411,52 @@ describe('POST /events', () => { checkEvent({ ...experimentExample, experiment_success: undefined }, 201) ) }) + + describe('redirect', () => { + const redirectExample = { + ...baseExample, + type: 'redirect', + redirect_from: 'http://example.com/a', + redirect_to: 'http://example.com/b' + } + + it('should record an redirect event', () => + checkEvent(redirectExample, 201) + ) + + it('redirect_from is required url', () => + checkEvent({ ...redirectExample, redirect_from: ' ' }, 400) + ) + + it('redirect_to is required url', () => + checkEvent({ ...redirectExample, redirect_to: undefined }, 400) + ) + }) + + describe('clipboard', () => { + const clipboardExample = { + ...baseExample, + type: 'clipboard', + clipboard_operation: 'copy' + } + + it('should record an clipboard event', () => + checkEvent(clipboardExample, 201) + ) + + it('clipboard_operation is required copy, paste, cut', () => + checkEvent({ ...clipboardExample, clipboard_operation: 'destroy' }, 400) + ) + }) + + describe('print', () => { + const printExample = { + ...baseExample, + type: 'print' + } + + it('should record a print event', () => + checkEvent(printExample, 201) + ) + }) })