1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import { omit } from '@shared/core-utils'
import { HttpStatusCode, PlaybackMetricCreate, VideoResolution } from '@shared/models'
import { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
describe('Test metrics API validators', function () {
let server: PeerTubeServer
let videoUUID: string
// ---------------------------------------------------------------
before(async function () {
this.timeout(120000)
server = await createSingleServer(1, {
open_telemetry: {
metrics: {
enabled: true
}
}
})
await setAccessTokensToServers([ server ])
const { uuid } = await server.videos.quickUpload({ name: 'video' })
videoUUID = uuid
})
describe('When adding playback metrics', function () {
const path = '/api/v1/metrics/playback'
let baseParams: PlaybackMetricCreate
before(function () {
baseParams = {
playerMode: 'p2p-media-loader',
resolution: VideoResolution.H_1080P,
fps: 30,
resolutionChanges: 1,
errors: 2,
downloadedBytesP2P: 0,
downloadedBytesHTTP: 0,
uploadedBytesP2P: 0,
videoId: videoUUID
}
})
it('Should fail with an invalid resolution', async function () {
await makePostBodyRequest({
url: server.url,
path,
fields: { ...baseParams, resolution: 'toto' }
})
})
it('Should fail with an invalid fps', async function () {
await makePostBodyRequest({
url: server.url,
path,
fields: { ...baseParams, fps: 'toto' }
})
})
it('Should fail with a missing/invalid player mode', async function () {
await makePostBodyRequest({
url: server.url,
path,
fields: omit(baseParams, [ 'playerMode' ])
})
await makePostBodyRequest({
url: server.url,
path,
fields: { ...baseParams, playerMode: 'toto' }
})
})
it('Should fail with an missing/invalid resolution changes', async function () {
await makePostBodyRequest({
url: server.url,
path,
fields: omit(baseParams, [ 'resolutionChanges' ])
})
await makePostBodyRequest({
url: server.url,
path,
fields: { ...baseParams, resolutionChanges: 'toto' }
})
})
it('Should fail with a missing errors', async function () {
})
it('Should fail with an missing/invalid errors', async function () {
await makePostBodyRequest({
url: server.url,
path,
fields: omit(baseParams, [ 'errors' ])
})
await makePostBodyRequest({
url: server.url,
path,
fields: { ...baseParams, errors: 'toto' }
})
})
it('Should fail with an missing/invalid downloadedBytesP2P', async function () {
await makePostBodyRequest({
url: server.url,
path,
fields: omit(baseParams, [ 'downloadedBytesP2P' ])
})
await makePostBodyRequest({
url: server.url,
path,
fields: { ...baseParams, downloadedBytesP2P: 'toto' }
})
})
it('Should fail with an missing/invalid downloadedBytesHTTP', async function () {
await makePostBodyRequest({
url: server.url,
path,
fields: omit(baseParams, [ 'downloadedBytesHTTP' ])
})
await makePostBodyRequest({
url: server.url,
path,
fields: { ...baseParams, downloadedBytesHTTP: 'toto' }
})
})
it('Should fail with an missing/invalid uploadedBytesP2P', async function () {
await makePostBodyRequest({
url: server.url,
path,
fields: omit(baseParams, [ 'uploadedBytesP2P' ])
})
await makePostBodyRequest({
url: server.url,
path,
fields: { ...baseParams, uploadedBytesP2P: 'toto' }
})
})
it('Should fail with a bad video id', async function () {
await makePostBodyRequest({
url: server.url,
path,
fields: { ...baseParams, videoId: 'toto' }
})
})
it('Should fail with an unknown video', async function () {
await makePostBodyRequest({
url: server.url,
path,
fields: { ...baseParams, videoId: 42 },
expectedStatus: HttpStatusCode.NOT_FOUND_404
})
})
it('Should succeed with the correct params', async function () {
await makePostBodyRequest({
url: server.url,
path,
fields: baseParams,
expectedStatus: HttpStatusCode.NO_CONTENT_204
})
})
})
after(async function () {
await cleanupTests([ server ])
})
})
|