Skip to content

Commit

Permalink
Add new schemas for redirect, copy, print (github#16175)
Browse files Browse the repository at this point in the history
* Add new schemas for redirect, copy, print

* Update schema-event.js

* Update events.js

* Copy -> Clipboard

* Update events.js
  • Loading branch information
heiskr committed Oct 23, 2020
1 parent 095410d commit 3daacd9
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/hydro.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
68 changes: 67 additions & 1 deletion lib/schema-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -308,6 +371,9 @@ module.exports = {
searchSchema,
navigateSchema,
surveySchema,
experimentSchema
experimentSchema,
redirectSchema,
clipboardSchema,
printSchema
]
}
48 changes: 48 additions & 0 deletions tests/rendering/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
})
})

0 comments on commit 3daacd9

Please sign in to comment.