aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/views.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/views.ts')
-rw-r--r--server/tests/api/check-params/views.ts227
1 files changed, 0 insertions, 227 deletions
diff --git a/server/tests/api/check-params/views.ts b/server/tests/api/check-params/views.ts
deleted file mode 100644
index 11416ccb8..000000000
--- a/server/tests/api/check-params/views.ts
+++ /dev/null
@@ -1,227 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import { HttpStatusCode, VideoPrivacy } from '@shared/models'
4import {
5 cleanupTests,
6 createMultipleServers,
7 doubleFollow,
8 PeerTubeServer,
9 setAccessTokensToServers,
10 setDefaultVideoChannel
11} from '@shared/server-commands'
12
13describe('Test videos views', function () {
14 let servers: PeerTubeServer[]
15 let liveVideoId: string
16 let videoId: string
17 let remoteVideoId: string
18 let userAccessToken: string
19
20 before(async function () {
21 this.timeout(120000)
22
23 servers = await createMultipleServers(2)
24 await setAccessTokensToServers(servers)
25 await setDefaultVideoChannel(servers)
26
27 await servers[0].config.enableLive({ allowReplay: false, transcoding: false });
28
29 ({ uuid: videoId } = await servers[0].videos.quickUpload({ name: 'video' }));
30 ({ uuid: remoteVideoId } = await servers[1].videos.quickUpload({ name: 'video' }));
31 ({ uuid: liveVideoId } = await servers[0].live.create({
32 fields: {
33 name: 'live',
34 privacy: VideoPrivacy.PUBLIC,
35 channelId: servers[0].store.channel.id
36 }
37 }))
38
39 userAccessToken = await servers[0].users.generateUserAndToken('user')
40
41 await doubleFollow(servers[0], servers[1])
42 })
43
44 describe('When viewing a video', async function () {
45
46 it('Should fail without current time', async function () {
47 await servers[0].views.view({ id: videoId, currentTime: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
48 })
49
50 it('Should fail with an invalid current time', async function () {
51 await servers[0].views.view({ id: videoId, currentTime: -1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
52 await servers[0].views.view({ id: videoId, currentTime: 10, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
53 })
54
55 it('Should succeed with correct parameters', async function () {
56 await servers[0].views.view({ id: videoId, currentTime: 1 })
57 })
58 })
59
60 describe('When getting overall stats', function () {
61
62 it('Should fail with a remote video', async function () {
63 await servers[0].videoStats.getOverallStats({ videoId: remoteVideoId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
64 })
65
66 it('Should fail without token', async function () {
67 await servers[0].videoStats.getOverallStats({ videoId, token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
68 })
69
70 it('Should fail with another token', async function () {
71 await servers[0].videoStats.getOverallStats({
72 videoId,
73 token: userAccessToken,
74 expectedStatus: HttpStatusCode.FORBIDDEN_403
75 })
76 })
77
78 it('Should fail with an invalid start date', async function () {
79 await servers[0].videoStats.getOverallStats({
80 videoId,
81 startDate: 'fake' as any,
82 endDate: new Date().toISOString(),
83 expectedStatus: HttpStatusCode.BAD_REQUEST_400
84 })
85 })
86
87 it('Should fail with an invalid end date', async function () {
88 await servers[0].videoStats.getOverallStats({
89 videoId,
90 startDate: new Date().toISOString(),
91 endDate: 'fake' as any,
92 expectedStatus: HttpStatusCode.BAD_REQUEST_400
93 })
94 })
95
96 it('Should succeed with the correct parameters', async function () {
97 await servers[0].videoStats.getOverallStats({
98 videoId,
99 startDate: new Date().toISOString(),
100 endDate: new Date().toISOString()
101 })
102 })
103 })
104
105 describe('When getting timeserie stats', function () {
106
107 it('Should fail with a remote video', async function () {
108 await servers[0].videoStats.getTimeserieStats({
109 videoId: remoteVideoId,
110 metric: 'viewers',
111 expectedStatus: HttpStatusCode.FORBIDDEN_403
112 })
113 })
114
115 it('Should fail without token', async function () {
116 await servers[0].videoStats.getTimeserieStats({
117 videoId,
118 token: null,
119 metric: 'viewers',
120 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
121 })
122 })
123
124 it('Should fail with another token', async function () {
125 await servers[0].videoStats.getTimeserieStats({
126 videoId,
127 token: userAccessToken,
128 metric: 'viewers',
129 expectedStatus: HttpStatusCode.FORBIDDEN_403
130 })
131 })
132
133 it('Should fail with an invalid metric', async function () {
134 await servers[0].videoStats.getTimeserieStats({ videoId, metric: 'hello' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
135 })
136
137 it('Should fail with an invalid start date', async function () {
138 await servers[0].videoStats.getTimeserieStats({
139 videoId,
140 metric: 'viewers',
141 startDate: 'fake' as any,
142 endDate: new Date(),
143 expectedStatus: HttpStatusCode.BAD_REQUEST_400
144 })
145 })
146
147 it('Should fail with an invalid end date', async function () {
148 await servers[0].videoStats.getTimeserieStats({
149 videoId,
150 metric: 'viewers',
151 startDate: new Date(),
152 endDate: 'fake' as any,
153 expectedStatus: HttpStatusCode.BAD_REQUEST_400
154 })
155 })
156
157 it('Should fail if start date is specified but not end date', async function () {
158 await servers[0].videoStats.getTimeserieStats({
159 videoId,
160 metric: 'viewers',
161 startDate: new Date(),
162 expectedStatus: HttpStatusCode.BAD_REQUEST_400
163 })
164 })
165
166 it('Should fail if end date is specified but not start date', async function () {
167 await servers[0].videoStats.getTimeserieStats({
168 videoId,
169 metric: 'viewers',
170 endDate: new Date(),
171 expectedStatus: HttpStatusCode.BAD_REQUEST_400
172 })
173 })
174
175 it('Should fail with a too big interval', async function () {
176 await servers[0].videoStats.getTimeserieStats({
177 videoId,
178 metric: 'viewers',
179 startDate: new Date('2000-04-07T08:31:57.126Z'),
180 endDate: new Date(),
181 expectedStatus: HttpStatusCode.BAD_REQUEST_400
182 })
183 })
184
185 it('Should succeed with the correct parameters', async function () {
186 await servers[0].videoStats.getTimeserieStats({ videoId, metric: 'viewers' })
187 })
188 })
189
190 describe('When getting retention stats', function () {
191
192 it('Should fail with a remote video', async function () {
193 await servers[0].videoStats.getRetentionStats({
194 videoId: remoteVideoId,
195 expectedStatus: HttpStatusCode.FORBIDDEN_403
196 })
197 })
198
199 it('Should fail without token', async function () {
200 await servers[0].videoStats.getRetentionStats({
201 videoId,
202 token: null,
203 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
204 })
205 })
206
207 it('Should fail with another token', async function () {
208 await servers[0].videoStats.getRetentionStats({
209 videoId,
210 token: userAccessToken,
211 expectedStatus: HttpStatusCode.FORBIDDEN_403
212 })
213 })
214
215 it('Should fail on live video', async function () {
216 await servers[0].videoStats.getRetentionStats({ videoId: liveVideoId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
217 })
218
219 it('Should succeed with the correct parameters', async function () {
220 await servers[0].videoStats.getRetentionStats({ videoId })
221 })
222 })
223
224 after(async function () {
225 await cleanupTests(servers)
226 })
227})