]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/views.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / views.ts
CommitLineData
b2111066
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
b2111066
C
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 () {
ac907dc7 21 this.timeout(120000)
b2111066
C
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 // TODO: implement it when we'll remove backward compatibility in REST API
47 it('Should fail without current time')
48
49 it('Should fail with an invalid current time', async function () {
50 await servers[0].views.view({ id: videoId, currentTime: -1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
51 await servers[0].views.view({ id: videoId, currentTime: 10, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
52 })
53
54 it('Should succeed with correct parameters', async function () {
55 await servers[0].views.view({ id: videoId, currentTime: 1 })
56 })
57 })
58
59 describe('When getting overall stats', function () {
60
61 it('Should fail with a remote video', async function () {
62 await servers[0].videoStats.getOverallStats({ videoId: remoteVideoId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
63 })
64
65 it('Should fail without token', async function () {
ba2684ce 66 await servers[0].videoStats.getOverallStats({ videoId, token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
b2111066
C
67 })
68
69 it('Should fail with another token', async function () {
70 await servers[0].videoStats.getOverallStats({
ba2684ce 71 videoId,
b2111066
C
72 token: userAccessToken,
73 expectedStatus: HttpStatusCode.FORBIDDEN_403
74 })
75 })
76
49f0468d
C
77 it('Should fail with an invalid start date', async function () {
78 await servers[0].videoStats.getOverallStats({
79 videoId,
80 startDate: 'fake' as any,
81 endDate: new Date().toISOString(),
82 expectedStatus: HttpStatusCode.BAD_REQUEST_400
83 })
84 })
85
86 it('Should fail with an invalid end date', async function () {
87 await servers[0].videoStats.getOverallStats({
88 videoId,
89 startDate: new Date().toISOString(),
90 endDate: 'fake' as any,
91 expectedStatus: HttpStatusCode.BAD_REQUEST_400
92 })
93 })
94
b2111066 95 it('Should succeed with the correct parameters', async function () {
49f0468d
C
96 await servers[0].videoStats.getOverallStats({
97 videoId,
98 startDate: new Date().toISOString(),
99 endDate: new Date().toISOString()
100 })
b2111066
C
101 })
102 })
103
104 describe('When getting timeserie stats', function () {
105
106 it('Should fail with a remote video', async function () {
107 await servers[0].videoStats.getTimeserieStats({
108 videoId: remoteVideoId,
109 metric: 'viewers',
110 expectedStatus: HttpStatusCode.FORBIDDEN_403
111 })
112 })
113
114 it('Should fail without token', async function () {
115 await servers[0].videoStats.getTimeserieStats({
ba2684ce 116 videoId,
b2111066
C
117 token: null,
118 metric: 'viewers',
119 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
120 })
121 })
122
123 it('Should fail with another token', async function () {
124 await servers[0].videoStats.getTimeserieStats({
ba2684ce 125 videoId,
b2111066
C
126 token: userAccessToken,
127 metric: 'viewers',
128 expectedStatus: HttpStatusCode.FORBIDDEN_403
129 })
130 })
131
132 it('Should fail with an invalid metric', async function () {
133 await servers[0].videoStats.getTimeserieStats({ videoId, metric: 'hello' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
134 })
135
901bcf5c
C
136 it('Should fail with an invalid start date', async function () {
137 await servers[0].videoStats.getTimeserieStats({
138 videoId,
139 metric: 'viewers',
140 startDate: 'fake' as any,
141 endDate: new Date(),
142 expectedStatus: HttpStatusCode.BAD_REQUEST_400
143 })
144 })
145
146 it('Should fail with an invalid end date', async function () {
147 await servers[0].videoStats.getTimeserieStats({
148 videoId,
149 metric: 'viewers',
150 startDate: new Date(),
151 endDate: 'fake' as any,
152 expectedStatus: HttpStatusCode.BAD_REQUEST_400
153 })
154 })
155
156 it('Should fail if start date is specified but not end date', async function () {
157 await servers[0].videoStats.getTimeserieStats({
158 videoId,
159 metric: 'viewers',
160 startDate: new Date(),
161 expectedStatus: HttpStatusCode.BAD_REQUEST_400
162 })
163 })
164
165 it('Should fail if end date is specified but not start date', async function () {
166 await servers[0].videoStats.getTimeserieStats({
167 videoId,
168 metric: 'viewers',
169 endDate: new Date(),
170 expectedStatus: HttpStatusCode.BAD_REQUEST_400
171 })
172 })
173
174 it('Should fail with a too big interval', async function () {
175 await servers[0].videoStats.getTimeserieStats({
176 videoId,
177 metric: 'viewers',
f40712ab 178 startDate: new Date('2000-04-07T08:31:57.126Z'),
901bcf5c
C
179 endDate: new Date(),
180 expectedStatus: HttpStatusCode.BAD_REQUEST_400
181 })
182 })
183
b2111066
C
184 it('Should succeed with the correct parameters', async function () {
185 await servers[0].videoStats.getTimeserieStats({ videoId, metric: 'viewers' })
186 })
187 })
188
189 describe('When getting retention stats', function () {
190
191 it('Should fail with a remote video', async function () {
192 await servers[0].videoStats.getRetentionStats({
193 videoId: remoteVideoId,
194 expectedStatus: HttpStatusCode.FORBIDDEN_403
195 })
196 })
197
198 it('Should fail without token', async function () {
199 await servers[0].videoStats.getRetentionStats({
ba2684ce 200 videoId,
b2111066
C
201 token: null,
202 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
203 })
204 })
205
206 it('Should fail with another token', async function () {
207 await servers[0].videoStats.getRetentionStats({
ba2684ce 208 videoId,
b2111066
C
209 token: userAccessToken,
210 expectedStatus: HttpStatusCode.FORBIDDEN_403
211 })
212 })
213
214 it('Should fail on live video', async function () {
215 await servers[0].videoStats.getRetentionStats({ videoId: liveVideoId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
216 })
217
218 it('Should succeed with the correct parameters', async function () {
219 await servers[0].videoStats.getRetentionStats({ videoId })
220 })
221 })
222
223 after(async function () {
224 await cleanupTests(servers)
225 })
226})