]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
6e46de09 | 2 | |
6e46de09 | 3 | import 'mocha' |
af971e06 C |
4 | import * as chai from 'chai' |
5 | import { HttpStatusCode } from '@shared/core-utils' | |
6e46de09 | 6 | import { |
7c3b7976 | 7 | cleanupTests, |
8b9a525a | 8 | createUser, |
7c3b7976 | 9 | flushAndRunServer, |
6e46de09 C |
10 | getVideosListWithToken, |
11 | getVideoWithToken, | |
7c3b7976 C |
12 | killallServers, |
13 | reRunServer, | |
6e46de09 C |
14 | ServerInfo, |
15 | setAccessTokensToServers, | |
8b9a525a C |
16 | updateMyUser, |
17 | uploadVideo, | |
8f0bc73d C |
18 | userLogin, |
19 | wait | |
af971e06 C |
20 | } from '@shared/extra-utils' |
21 | import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '@shared/extra-utils/videos/video-history' | |
22 | import { Video, VideoDetails } from '@shared/models' | |
6e46de09 C |
23 | |
24 | const expect = chai.expect | |
25 | ||
26 | describe('Test videos history', function () { | |
27 | let server: ServerInfo = null | |
28 | let video1UUID: string | |
29 | let video2UUID: string | |
30 | let video3UUID: string | |
8b9a525a C |
31 | let video3WatchedDate: Date |
32 | let userAccessToken: string | |
6e46de09 C |
33 | |
34 | before(async function () { | |
35 | this.timeout(30000) | |
36 | ||
210feb6c | 37 | server = await flushAndRunServer(1) |
6e46de09 C |
38 | |
39 | await setAccessTokensToServers([ server ]) | |
40 | ||
41 | { | |
42 | const res = await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) | |
43 | video1UUID = res.body.video.uuid | |
44 | } | |
45 | ||
46 | { | |
47 | const res = await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) | |
48 | video2UUID = res.body.video.uuid | |
49 | } | |
50 | ||
51 | { | |
52 | const res = await uploadVideo(server.url, server.accessToken, { name: 'video 3' }) | |
53 | video3UUID = res.body.video.uuid | |
54 | } | |
8b9a525a C |
55 | |
56 | const user = { | |
57 | username: 'user_1', | |
58 | password: 'super password' | |
59 | } | |
1eddc9a7 | 60 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
8b9a525a | 61 | userAccessToken = await userLogin(server, user) |
6e46de09 C |
62 | }) |
63 | ||
64 | it('Should get videos, without watching history', async function () { | |
65 | const res = await getVideosListWithToken(server.url, server.accessToken) | |
66 | const videos: Video[] = res.body.data | |
67 | ||
68 | for (const video of videos) { | |
69 | const resDetail = await getVideoWithToken(server.url, server.accessToken, video.id) | |
70 | const videoDetails: VideoDetails = resDetail.body | |
71 | ||
72 | expect(video.userHistory).to.be.undefined | |
73 | expect(videoDetails.userHistory).to.be.undefined | |
74 | } | |
75 | }) | |
76 | ||
77 | it('Should watch the first and second video', async function () { | |
6e46de09 | 78 | await userWatchVideo(server.url, server.accessToken, video2UUID, 8) |
8b9a525a | 79 | await userWatchVideo(server.url, server.accessToken, video1UUID, 3) |
6e46de09 C |
80 | }) |
81 | ||
82 | it('Should return the correct history when listing, searching and getting videos', async function () { | |
83 | const videosOfVideos: Video[][] = [] | |
84 | ||
85 | { | |
86 | const res = await getVideosListWithToken(server.url, server.accessToken) | |
87 | videosOfVideos.push(res.body.data) | |
88 | } | |
89 | ||
90 | { | |
af971e06 C |
91 | const body = await server.searchCommand.searchVideos({ token: server.accessToken, search: 'video' }) |
92 | videosOfVideos.push(body.data) | |
6e46de09 C |
93 | } |
94 | ||
95 | for (const videos of videosOfVideos) { | |
96 | const video1 = videos.find(v => v.uuid === video1UUID) | |
97 | const video2 = videos.find(v => v.uuid === video2UUID) | |
98 | const video3 = videos.find(v => v.uuid === video3UUID) | |
99 | ||
100 | expect(video1.userHistory).to.not.be.undefined | |
101 | expect(video1.userHistory.currentTime).to.equal(3) | |
102 | ||
103 | expect(video2.userHistory).to.not.be.undefined | |
104 | expect(video2.userHistory.currentTime).to.equal(8) | |
105 | ||
106 | expect(video3.userHistory).to.be.undefined | |
107 | } | |
108 | ||
109 | { | |
110 | const resDetail = await getVideoWithToken(server.url, server.accessToken, video1UUID) | |
111 | const videoDetails: VideoDetails = resDetail.body | |
112 | ||
113 | expect(videoDetails.userHistory).to.not.be.undefined | |
114 | expect(videoDetails.userHistory.currentTime).to.equal(3) | |
115 | } | |
116 | ||
117 | { | |
118 | const resDetail = await getVideoWithToken(server.url, server.accessToken, video2UUID) | |
119 | const videoDetails: VideoDetails = resDetail.body | |
120 | ||
121 | expect(videoDetails.userHistory).to.not.be.undefined | |
122 | expect(videoDetails.userHistory.currentTime).to.equal(8) | |
123 | } | |
124 | ||
125 | { | |
126 | const resDetail = await getVideoWithToken(server.url, server.accessToken, video3UUID) | |
127 | const videoDetails: VideoDetails = resDetail.body | |
128 | ||
129 | expect(videoDetails.userHistory).to.be.undefined | |
130 | } | |
131 | }) | |
132 | ||
8b9a525a C |
133 | it('Should have these videos when listing my history', async function () { |
134 | video3WatchedDate = new Date() | |
135 | await userWatchVideo(server.url, server.accessToken, video3UUID, 2) | |
136 | ||
137 | const res = await listMyVideosHistory(server.url, server.accessToken) | |
138 | ||
139 | expect(res.body.total).to.equal(3) | |
140 | ||
141 | const videos: Video[] = res.body.data | |
142 | expect(videos[0].name).to.equal('video 3') | |
143 | expect(videos[1].name).to.equal('video 1') | |
144 | expect(videos[2].name).to.equal('video 2') | |
145 | }) | |
146 | ||
147 | it('Should not have videos history on another user', async function () { | |
148 | const res = await listMyVideosHistory(server.url, userAccessToken) | |
149 | ||
150 | expect(res.body.total).to.equal(0) | |
151 | expect(res.body.data).to.have.lengthOf(0) | |
152 | }) | |
153 | ||
d8b34ee5 RK |
154 | it('Should be able to search through videos in my history', async function () { |
155 | const res = await listMyVideosHistory(server.url, server.accessToken, '2') | |
156 | ||
157 | expect(res.body.total).to.equal(1) | |
158 | ||
159 | const videos: Video[] = res.body.data | |
160 | expect(videos[0].name).to.equal('video 2') | |
161 | }) | |
162 | ||
8b9a525a C |
163 | it('Should clear my history', async function () { |
164 | await removeMyVideosHistory(server.url, server.accessToken, video3WatchedDate.toISOString()) | |
165 | }) | |
166 | ||
167 | it('Should have my history cleared', async function () { | |
168 | const res = await listMyVideosHistory(server.url, server.accessToken) | |
169 | ||
170 | expect(res.body.total).to.equal(1) | |
171 | ||
172 | const videos: Video[] = res.body.data | |
173 | expect(videos[0].name).to.equal('video 3') | |
174 | }) | |
175 | ||
176 | it('Should disable videos history', async function () { | |
177 | await updateMyUser({ | |
178 | url: server.url, | |
179 | accessToken: server.accessToken, | |
180 | videosHistoryEnabled: false | |
181 | }) | |
182 | ||
f2eb23cd | 183 | await userWatchVideo(server.url, server.accessToken, video2UUID, 8, HttpStatusCode.CONFLICT_409) |
8b9a525a C |
184 | }) |
185 | ||
186 | it('Should re-enable videos history', async function () { | |
187 | await updateMyUser({ | |
188 | url: server.url, | |
189 | accessToken: server.accessToken, | |
190 | videosHistoryEnabled: true | |
191 | }) | |
192 | ||
193 | await userWatchVideo(server.url, server.accessToken, video1UUID, 8) | |
194 | ||
195 | const res = await listMyVideosHistory(server.url, server.accessToken) | |
196 | ||
197 | expect(res.body.total).to.equal(2) | |
198 | ||
199 | const videos: Video[] = res.body.data | |
200 | expect(videos[0].name).to.equal('video 1') | |
201 | expect(videos[1].name).to.equal('video 3') | |
202 | }) | |
203 | ||
8f0bc73d C |
204 | it('Should not clean old history', async function () { |
205 | this.timeout(50000) | |
206 | ||
207 | killallServers([ server ]) | |
208 | ||
209 | await reRunServer(server, { history: { videos: { max_age: '10 days' } } }) | |
210 | ||
211 | await wait(6000) | |
212 | ||
213 | // Should still have history | |
214 | ||
215 | const res = await listMyVideosHistory(server.url, server.accessToken) | |
216 | ||
217 | expect(res.body.total).to.equal(2) | |
218 | }) | |
219 | ||
220 | it('Should clean old history', async function () { | |
221 | this.timeout(50000) | |
222 | ||
223 | killallServers([ server ]) | |
224 | ||
225 | await reRunServer(server, { history: { videos: { max_age: '5 seconds' } } }) | |
226 | ||
227 | await wait(6000) | |
228 | ||
229 | const res = await listMyVideosHistory(server.url, server.accessToken) | |
230 | expect(res.body.total).to.equal(0) | |
231 | }) | |
232 | ||
7c3b7976 C |
233 | after(async function () { |
234 | await cleanupTests([ server ]) | |
6e46de09 C |
235 | }) |
236 | }) |