Skip to content

Commit 53eae61

Browse files
authored
repo sync
2 parents 641d1ac + 3daacd9 commit 53eae61

File tree

3 files changed

+119
-2
lines changed

3 files changed

+119
-2
lines changed

lib/hydro.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ const SCHEMAS = {
88
search: 'docs.v0.SearchEvent',
99
navigate: 'docs.v0.NavigateEvent',
1010
survey: 'docs.v0.SurveyEvent',
11-
experiment: 'docs.v0.ExperimentEvent'
11+
experiment: 'docs.v0.ExperimentEvent',
12+
redirect: 'docs.v0.RedirectEvent',
13+
clipboard: 'docs.v0.ClipboardEvent',
14+
print: 'docs.v0.PrintEvent'
1215
}
1316

1417
module.exports = class Hydro {

lib/schema-event.js

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,69 @@ const experimentSchema = {
300300
}
301301
}
302302

303+
const redirectSchema = {
304+
additionalProperties: false,
305+
required: [
306+
'type',
307+
'context',
308+
'redirect_from',
309+
'redirect_to'
310+
],
311+
properties: {
312+
context,
313+
type: {
314+
type: 'string',
315+
pattern: '^redirect$'
316+
},
317+
redirect_from: {
318+
type: 'string',
319+
description: 'The requested href.',
320+
format: 'uri-reference'
321+
},
322+
redirect_to: {
323+
type: 'string',
324+
description: 'The destination href of the redirect.',
325+
format: 'uri-reference'
326+
}
327+
}
328+
}
329+
330+
const clipboardSchema = {
331+
additionalProperties: false,
332+
required: [
333+
'type',
334+
'context',
335+
'clipboard_operation'
336+
],
337+
properties: {
338+
context,
339+
type: {
340+
type: 'string',
341+
pattern: '^clipboard$'
342+
},
343+
clipboard_operation: {
344+
type: 'string',
345+
description: 'Which clipboard operation the user is performing.',
346+
enum: ['copy', 'paste', 'cut']
347+
}
348+
}
349+
}
350+
351+
const printSchema = {
352+
additionalProperties: false,
353+
required: [
354+
'type',
355+
'context'
356+
],
357+
properties: {
358+
context,
359+
type: {
360+
type: 'string',
361+
pattern: '^print$'
362+
}
363+
}
364+
}
365+
303366
module.exports = {
304367
oneOf: [
305368
pageSchema,
@@ -308,6 +371,9 @@ module.exports = {
308371
searchSchema,
309372
navigateSchema,
310373
surveySchema,
311-
experimentSchema
374+
experimentSchema,
375+
redirectSchema,
376+
clipboardSchema,
377+
printSchema
312378
]
313379
}

tests/rendering/events.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,4 +411,52 @@ describe('POST /events', () => {
411411
checkEvent({ ...experimentExample, experiment_success: undefined }, 201)
412412
)
413413
})
414+
415+
describe('redirect', () => {
416+
const redirectExample = {
417+
...baseExample,
418+
type: 'redirect',
419+
redirect_from: 'http://example.com/a',
420+
redirect_to: 'http://example.com/b'
421+
}
422+
423+
it('should record an redirect event', () =>
424+
checkEvent(redirectExample, 201)
425+
)
426+
427+
it('redirect_from is required url', () =>
428+
checkEvent({ ...redirectExample, redirect_from: ' ' }, 400)
429+
)
430+
431+
it('redirect_to is required url', () =>
432+
checkEvent({ ...redirectExample, redirect_to: undefined }, 400)
433+
)
434+
})
435+
436+
describe('clipboard', () => {
437+
const clipboardExample = {
438+
...baseExample,
439+
type: 'clipboard',
440+
clipboard_operation: 'copy'
441+
}
442+
443+
it('should record an clipboard event', () =>
444+
checkEvent(clipboardExample, 201)
445+
)
446+
447+
it('clipboard_operation is required copy, paste, cut', () =>
448+
checkEvent({ ...clipboardExample, clipboard_operation: 'destroy' }, 400)
449+
)
450+
})
451+
452+
describe('print', () => {
453+
const printExample = {
454+
...baseExample,
455+
type: 'print'
456+
}
457+
458+
it('should record a print event', () =>
459+
checkEvent(printExample, 201)
460+
)
461+
})
414462
})

0 commit comments

Comments
 (0)