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