aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/tests/api/videos/videos-history.ts59
1 files changed, 29 insertions, 30 deletions
diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts
index 209b93014..731447135 100644
--- a/server/tests/api/videos/videos-history.ts
+++ b/server/tests/api/videos/videos-history.ts
@@ -9,6 +9,7 @@ import {
9 flushAndRunServer, 9 flushAndRunServer,
10 getVideosListWithToken, 10 getVideosListWithToken,
11 getVideoWithToken, 11 getVideoWithToken,
12 HistoryCommand,
12 killallServers, 13 killallServers,
13 reRunServer, 14 reRunServer,
14 ServerInfo, 15 ServerInfo,
@@ -18,7 +19,6 @@ import {
18 userLogin, 19 userLogin,
19 wait 20 wait
20} from '@shared/extra-utils' 21} from '@shared/extra-utils'
21import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '@shared/extra-utils/videos/video-history'
22import { Video, VideoDetails } from '@shared/models' 22import { Video, VideoDetails } from '@shared/models'
23 23
24const expect = chai.expect 24const expect = chai.expect
@@ -30,6 +30,7 @@ describe('Test videos history', function () {
30 let video3UUID: string 30 let video3UUID: string
31 let video3WatchedDate: Date 31 let video3WatchedDate: Date
32 let userAccessToken: string 32 let userAccessToken: string
33 let command: HistoryCommand
33 34
34 before(async function () { 35 before(async function () {
35 this.timeout(30000) 36 this.timeout(30000)
@@ -38,6 +39,8 @@ describe('Test videos history', function () {
38 39
39 await setAccessTokensToServers([ server ]) 40 await setAccessTokensToServers([ server ])
40 41
42 command = server.historyCommand
43
41 { 44 {
42 const res = await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) 45 const res = await uploadVideo(server.url, server.accessToken, { name: 'video 1' })
43 video1UUID = res.body.video.uuid 46 video1UUID = res.body.video.uuid
@@ -75,8 +78,8 @@ describe('Test videos history', function () {
75 }) 78 })
76 79
77 it('Should watch the first and second video', async function () { 80 it('Should watch the first and second video', async function () {
78 await userWatchVideo(server.url, server.accessToken, video2UUID, 8) 81 await command.wathVideo({ videoId: video2UUID, currentTime: 8 })
79 await userWatchVideo(server.url, server.accessToken, video1UUID, 3) 82 await command.wathVideo({ videoId: video1UUID, currentTime: 3 })
80 }) 83 })
81 84
82 it('Should return the correct history when listing, searching and getting videos', async function () { 85 it('Should return the correct history when listing, searching and getting videos', async function () {
@@ -132,44 +135,42 @@ describe('Test videos history', function () {
132 135
133 it('Should have these videos when listing my history', async function () { 136 it('Should have these videos when listing my history', async function () {
134 video3WatchedDate = new Date() 137 video3WatchedDate = new Date()
135 await userWatchVideo(server.url, server.accessToken, video3UUID, 2) 138 await command.wathVideo({ videoId: video3UUID, currentTime: 2 })
136 139
137 const res = await listMyVideosHistory(server.url, server.accessToken) 140 const body = await command.list()
138 141
139 expect(res.body.total).to.equal(3) 142 expect(body.total).to.equal(3)
140 143
141 const videos: Video[] = res.body.data 144 const videos = body.data
142 expect(videos[0].name).to.equal('video 3') 145 expect(videos[0].name).to.equal('video 3')
143 expect(videos[1].name).to.equal('video 1') 146 expect(videos[1].name).to.equal('video 1')
144 expect(videos[2].name).to.equal('video 2') 147 expect(videos[2].name).to.equal('video 2')
145 }) 148 })
146 149
147 it('Should not have videos history on another user', async function () { 150 it('Should not have videos history on another user', async function () {
148 const res = await listMyVideosHistory(server.url, userAccessToken) 151 const body = await command.list({ token: userAccessToken })
149 152
150 expect(res.body.total).to.equal(0) 153 expect(body.total).to.equal(0)
151 expect(res.body.data).to.have.lengthOf(0) 154 expect(body.data).to.have.lengthOf(0)
152 }) 155 })
153 156
154 it('Should be able to search through videos in my history', async function () { 157 it('Should be able to search through videos in my history', async function () {
155 const res = await listMyVideosHistory(server.url, server.accessToken, '2') 158 const body = await command.list({ search: '2' })
156 159 expect(body.total).to.equal(1)
157 expect(res.body.total).to.equal(1)
158 160
159 const videos: Video[] = res.body.data 161 const videos = body.data
160 expect(videos[0].name).to.equal('video 2') 162 expect(videos[0].name).to.equal('video 2')
161 }) 163 })
162 164
163 it('Should clear my history', async function () { 165 it('Should clear my history', async function () {
164 await removeMyVideosHistory(server.url, server.accessToken, video3WatchedDate.toISOString()) 166 await command.remove({ beforeDate: video3WatchedDate.toISOString() })
165 }) 167 })
166 168
167 it('Should have my history cleared', async function () { 169 it('Should have my history cleared', async function () {
168 const res = await listMyVideosHistory(server.url, server.accessToken) 170 const body = await command.list()
169 171 expect(body.total).to.equal(1)
170 expect(res.body.total).to.equal(1)
171 172
172 const videos: Video[] = res.body.data 173 const videos = body.data
173 expect(videos[0].name).to.equal('video 3') 174 expect(videos[0].name).to.equal('video 3')
174 }) 175 })
175 176
@@ -180,7 +181,7 @@ describe('Test videos history', function () {
180 videosHistoryEnabled: false 181 videosHistoryEnabled: false
181 }) 182 })
182 183
183 await userWatchVideo(server.url, server.accessToken, video2UUID, 8, HttpStatusCode.CONFLICT_409) 184 await command.wathVideo({ videoId: video2UUID, currentTime: 8, expectedStatus: HttpStatusCode.CONFLICT_409 })
184 }) 185 })
185 186
186 it('Should re-enable videos history', async function () { 187 it('Should re-enable videos history', async function () {
@@ -190,13 +191,12 @@ describe('Test videos history', function () {
190 videosHistoryEnabled: true 191 videosHistoryEnabled: true
191 }) 192 })
192 193
193 await userWatchVideo(server.url, server.accessToken, video1UUID, 8) 194 await command.wathVideo({ videoId: video1UUID, currentTime: 8 })
194
195 const res = await listMyVideosHistory(server.url, server.accessToken)
196 195
197 expect(res.body.total).to.equal(2) 196 const body = await command.list()
197 expect(body.total).to.equal(2)
198 198
199 const videos: Video[] = res.body.data 199 const videos = body.data
200 expect(videos[0].name).to.equal('video 1') 200 expect(videos[0].name).to.equal('video 1')
201 expect(videos[1].name).to.equal('video 3') 201 expect(videos[1].name).to.equal('video 3')
202 }) 202 })
@@ -212,9 +212,8 @@ describe('Test videos history', function () {
212 212
213 // Should still have history 213 // Should still have history
214 214
215 const res = await listMyVideosHistory(server.url, server.accessToken) 215 const body = await command.list()
216 216 expect(body.total).to.equal(2)
217 expect(res.body.total).to.equal(2)
218 }) 217 })
219 218
220 it('Should clean old history', async function () { 219 it('Should clean old history', async function () {
@@ -226,8 +225,8 @@ describe('Test videos history', function () {
226 225
227 await wait(6000) 226 await wait(6000)
228 227
229 const res = await listMyVideosHistory(server.url, server.accessToken) 228 const body = await command.list()
230 expect(res.body.total).to.equal(0) 229 expect(body.total).to.equal(0)
231 }) 230 })
232 231
233 after(async function () { 232 after(async function () {