1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */
2 import { HttpStatusCode, VideoViewEvent } from '@shared/models'
3 import { AbstractCommand, OverrideCommandOptions } from '../shared'
5 export class ViewsCommand extends AbstractCommand {
7 view (options: OverrideCommandOptions & {
10 viewEvent?: VideoViewEvent
11 xForwardedFor?: string
13 const { id, xForwardedFor, viewEvent, currentTime } = options
14 const path = '/api/v1/videos/' + id + '/views'
16 return this.postBodyRequest({
22 currentTime: currentTime ?? 1,
26 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
30 async simulateView (options: OverrideCommandOptions & {
32 xForwardedFor?: string
34 await this.view({ ...options, currentTime: 0 })
35 await this.view({ ...options, currentTime: 5 })
38 async simulateViewer (options: OverrideCommandOptions & {
40 currentTimes: number[]
41 xForwardedFor?: string
43 let viewEvent: VideoViewEvent = 'seek'
45 for (const currentTime of options.currentTimes) {
46 await this.view({ ...options, currentTime, viewEvent })