]>
Commit | Line | Data |
---|---|---|
b2111066 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import { HttpStatusCode, VideoPrivacy } from '@shared/models' | |
5 | import { | |
6 | cleanupTests, | |
7 | createMultipleServers, | |
8 | doubleFollow, | |
9 | PeerTubeServer, | |
10 | setAccessTokensToServers, | |
11 | setDefaultVideoChannel | |
12 | } from '@shared/server-commands' | |
13 | ||
14 | describe('Test videos views', function () { | |
15 | let servers: PeerTubeServer[] | |
16 | let liveVideoId: string | |
17 | let videoId: string | |
18 | let remoteVideoId: string | |
19 | let userAccessToken: string | |
20 | ||
21 | before(async function () { | |
ac907dc7 | 22 | this.timeout(120000) |
b2111066 C |
23 | |
24 | servers = await createMultipleServers(2) | |
25 | await setAccessTokensToServers(servers) | |
26 | await setDefaultVideoChannel(servers) | |
27 | ||
28 | await servers[0].config.enableLive({ allowReplay: false, transcoding: false }); | |
29 | ||
30 | ({ uuid: videoId } = await servers[0].videos.quickUpload({ name: 'video' })); | |
31 | ({ uuid: remoteVideoId } = await servers[1].videos.quickUpload({ name: 'video' })); | |
32 | ({ uuid: liveVideoId } = await servers[0].live.create({ | |
33 | fields: { | |
34 | name: 'live', | |
35 | privacy: VideoPrivacy.PUBLIC, | |
36 | channelId: servers[0].store.channel.id | |
37 | } | |
38 | })) | |
39 | ||
40 | userAccessToken = await servers[0].users.generateUserAndToken('user') | |
41 | ||
42 | await doubleFollow(servers[0], servers[1]) | |
43 | }) | |
44 | ||
45 | describe('When viewing a video', async function () { | |
46 | ||
47 | // TODO: implement it when we'll remove backward compatibility in REST API | |
48 | it('Should fail without current time') | |
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: 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: videoId, | |
73 | token: userAccessToken, | |
74 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
75 | }) | |
76 | }) | |
77 | ||
78 | it('Should succeed with the correct parameters', async function () { | |
79 | await servers[0].videoStats.getOverallStats({ videoId }) | |
80 | }) | |
81 | }) | |
82 | ||
83 | describe('When getting timeserie stats', function () { | |
84 | ||
85 | it('Should fail with a remote video', async function () { | |
86 | await servers[0].videoStats.getTimeserieStats({ | |
87 | videoId: remoteVideoId, | |
88 | metric: 'viewers', | |
89 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
90 | }) | |
91 | }) | |
92 | ||
93 | it('Should fail without token', async function () { | |
94 | await servers[0].videoStats.getTimeserieStats({ | |
95 | videoId: videoId, | |
96 | token: null, | |
97 | metric: 'viewers', | |
98 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | |
99 | }) | |
100 | }) | |
101 | ||
102 | it('Should fail with another token', async function () { | |
103 | await servers[0].videoStats.getTimeserieStats({ | |
104 | videoId: videoId, | |
105 | token: userAccessToken, | |
106 | metric: 'viewers', | |
107 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
108 | }) | |
109 | }) | |
110 | ||
111 | it('Should fail with an invalid metric', async function () { | |
112 | await servers[0].videoStats.getTimeserieStats({ videoId, metric: 'hello' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | |
113 | }) | |
114 | ||
901bcf5c C |
115 | it('Should fail with an invalid start date', async function () { |
116 | await servers[0].videoStats.getTimeserieStats({ | |
117 | videoId, | |
118 | metric: 'viewers', | |
119 | startDate: 'fake' as any, | |
120 | endDate: new Date(), | |
121 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
122 | }) | |
123 | }) | |
124 | ||
125 | it('Should fail with an invalid end date', async function () { | |
126 | await servers[0].videoStats.getTimeserieStats({ | |
127 | videoId, | |
128 | metric: 'viewers', | |
129 | startDate: new Date(), | |
130 | endDate: 'fake' as any, | |
131 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
132 | }) | |
133 | }) | |
134 | ||
135 | it('Should fail if start date is specified but not end date', async function () { | |
136 | await servers[0].videoStats.getTimeserieStats({ | |
137 | videoId, | |
138 | metric: 'viewers', | |
139 | startDate: new Date(), | |
140 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
141 | }) | |
142 | }) | |
143 | ||
144 | it('Should fail if end date is specified but not start date', async function () { | |
145 | await servers[0].videoStats.getTimeserieStats({ | |
146 | videoId, | |
147 | metric: 'viewers', | |
148 | endDate: new Date(), | |
149 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
150 | }) | |
151 | }) | |
152 | ||
153 | it('Should fail with a too big interval', async function () { | |
154 | await servers[0].videoStats.getTimeserieStats({ | |
155 | videoId, | |
156 | metric: 'viewers', | |
157 | startDate: new Date('2021-04-07T08:31:57.126Z'), | |
158 | endDate: new Date(), | |
159 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
160 | }) | |
161 | }) | |
162 | ||
b2111066 C |
163 | it('Should succeed with the correct parameters', async function () { |
164 | await servers[0].videoStats.getTimeserieStats({ videoId, metric: 'viewers' }) | |
165 | }) | |
166 | }) | |
167 | ||
168 | describe('When getting retention stats', function () { | |
169 | ||
170 | it('Should fail with a remote video', async function () { | |
171 | await servers[0].videoStats.getRetentionStats({ | |
172 | videoId: remoteVideoId, | |
173 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
174 | }) | |
175 | }) | |
176 | ||
177 | it('Should fail without token', async function () { | |
178 | await servers[0].videoStats.getRetentionStats({ | |
179 | videoId: videoId, | |
180 | token: null, | |
181 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | |
182 | }) | |
183 | }) | |
184 | ||
185 | it('Should fail with another token', async function () { | |
186 | await servers[0].videoStats.getRetentionStats({ | |
187 | videoId: videoId, | |
188 | token: userAccessToken, | |
189 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
190 | }) | |
191 | }) | |
192 | ||
193 | it('Should fail on live video', async function () { | |
194 | await servers[0].videoStats.getRetentionStats({ videoId: liveVideoId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | |
195 | }) | |
196 | ||
197 | it('Should succeed with the correct parameters', async function () { | |
198 | await servers[0].videoStats.getRetentionStats({ videoId }) | |
199 | }) | |
200 | }) | |
201 | ||
202 | after(async function () { | |
203 | await cleanupTests(servers) | |
204 | }) | |
205 | }) |