1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { omit } from '@shared/core-utils'
4 import { HttpStatusCode, PlaybackMetricCreate, VideoResolution } from '@shared/models'
5 import { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
7 describe('Test metrics API validators', function () {
8 let server: PeerTubeServer
11 // ---------------------------------------------------------------
13 before(async function () {
16 server = await createSingleServer(1, {
24 await setAccessTokensToServers([ server ])
26 const { uuid } = await server.videos.quickUpload({ name: 'video' })
30 describe('When adding playback metrics', function () {
31 const path = '/api/v1/metrics/playback'
32 let baseParams: PlaybackMetricCreate
36 playerMode: 'p2p-media-loader',
37 resolution: VideoResolution.H_1080P,
41 downloadedBytesP2P: 0,
42 downloadedBytesHTTP: 0,
48 it('Should fail with an invalid resolution', async function () {
49 await makePostBodyRequest({
52 fields: { ...baseParams, resolution: 'toto' }
56 it('Should fail with an invalid fps', async function () {
57 await makePostBodyRequest({
60 fields: { ...baseParams, fps: 'toto' }
64 it('Should fail with a missing/invalid player mode', async function () {
65 await makePostBodyRequest({
68 fields: omit(baseParams, [ 'playerMode' ])
71 await makePostBodyRequest({
74 fields: { ...baseParams, playerMode: 'toto' }
78 it('Should fail with an missing/invalid resolution changes', async function () {
79 await makePostBodyRequest({
82 fields: omit(baseParams, [ 'resolutionChanges' ])
85 await makePostBodyRequest({
88 fields: { ...baseParams, resolutionChanges: 'toto' }
92 it('Should fail with a missing errors', async function () {
96 it('Should fail with an missing/invalid errors', async function () {
97 await makePostBodyRequest({
100 fields: omit(baseParams, [ 'errors' ])
103 await makePostBodyRequest({
106 fields: { ...baseParams, errors: 'toto' }
110 it('Should fail with an missing/invalid downloadedBytesP2P', async function () {
111 await makePostBodyRequest({
114 fields: omit(baseParams, [ 'downloadedBytesP2P' ])
117 await makePostBodyRequest({
120 fields: { ...baseParams, downloadedBytesP2P: 'toto' }
124 it('Should fail with an missing/invalid downloadedBytesHTTP', async function () {
125 await makePostBodyRequest({
128 fields: omit(baseParams, [ 'downloadedBytesHTTP' ])
131 await makePostBodyRequest({
134 fields: { ...baseParams, downloadedBytesHTTP: 'toto' }
138 it('Should fail with an missing/invalid uploadedBytesP2P', async function () {
139 await makePostBodyRequest({
142 fields: omit(baseParams, [ 'uploadedBytesP2P' ])
145 await makePostBodyRequest({
148 fields: { ...baseParams, uploadedBytesP2P: 'toto' }
152 it('Should fail with a bad video id', async function () {
153 await makePostBodyRequest({
156 fields: { ...baseParams, videoId: 'toto' }
160 it('Should fail with an unknown video', async function () {
161 await makePostBodyRequest({
164 fields: { ...baseParams, videoId: 42 },
165 expectedStatus: HttpStatusCode.NOT_FOUND_404
169 it('Should succeed with the correct params', async function () {
170 await makePostBodyRequest({
174 expectedStatus: HttpStatusCode.NO_CONTENT_204
179 after(async function () {
180 await cleanupTests([ server ])