aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/videos')
-rw-r--r--server/tests/api/videos/index.ts1
-rw-r--r--server/tests/api/videos/multiple-servers.ts40
-rw-r--r--server/tests/api/videos/single-server.ts17
-rw-r--r--server/tests/api/videos/video-channels.ts4
-rw-r--r--server/tests/api/videos/videos-history.ts73
-rw-r--r--server/tests/api/videos/videos-views-cleaner.ts101
6 files changed, 61 insertions, 175 deletions
diff --git a/server/tests/api/videos/index.ts b/server/tests/api/videos/index.ts
index 7dc826353..27b119f30 100644
--- a/server/tests/api/videos/index.ts
+++ b/server/tests/api/videos/index.ts
@@ -16,4 +16,3 @@ import './video-schedule-update'
16import './videos-common-filters' 16import './videos-common-filters'
17import './videos-history' 17import './videos-history'
18import './videos-overview' 18import './videos-overview'
19import './videos-views-cleaner'
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index a9df262dc..84c1515a3 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -504,21 +504,22 @@ describe('Test multiple servers', function () {
504 it('Should view multiple videos on owned servers', async function () { 504 it('Should view multiple videos on owned servers', async function () {
505 this.timeout(30000) 505 this.timeout(30000)
506 506
507 await servers[2].videos.view({ id: localVideosServer3[0] }) 507 await servers[2].views.simulateView({ id: localVideosServer3[0] })
508 await wait(1000) 508 await wait(1000)
509 509
510 await servers[2].videos.view({ id: localVideosServer3[0] }) 510 await servers[2].views.simulateView({ id: localVideosServer3[0] })
511 await servers[2].videos.view({ id: localVideosServer3[1] }) 511 await servers[2].views.simulateView({ id: localVideosServer3[1] })
512 512
513 await wait(1000) 513 await wait(1000)
514 514
515 await servers[2].videos.view({ id: localVideosServer3[0] }) 515 await servers[2].views.simulateView({ id: localVideosServer3[0] })
516 await servers[2].videos.view({ id: localVideosServer3[0] }) 516 await servers[2].views.simulateView({ id: localVideosServer3[0] })
517 517
518 await waitJobs(servers) 518 await waitJobs(servers)
519 519
520 // Wait the repeatable job 520 for (const server of servers) {
521 await wait(6000) 521 await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } })
522 }
522 523
523 await waitJobs(servers) 524 await waitJobs(servers)
524 525
@@ -537,23 +538,24 @@ describe('Test multiple servers', function () {
537 this.timeout(45000) 538 this.timeout(45000)
538 539
539 const tasks: Promise<any>[] = [] 540 const tasks: Promise<any>[] = []
540 tasks.push(servers[0].videos.view({ id: remoteVideosServer1[0] })) 541 tasks.push(servers[0].views.simulateView({ id: remoteVideosServer1[0] }))
541 tasks.push(servers[1].videos.view({ id: remoteVideosServer2[0] })) 542 tasks.push(servers[1].views.simulateView({ id: remoteVideosServer2[0] }))
542 tasks.push(servers[1].videos.view({ id: remoteVideosServer2[0] })) 543 tasks.push(servers[1].views.simulateView({ id: remoteVideosServer2[0] }))
543 tasks.push(servers[2].videos.view({ id: remoteVideosServer3[0] })) 544 tasks.push(servers[2].views.simulateView({ id: remoteVideosServer3[0] }))
544 tasks.push(servers[2].videos.view({ id: remoteVideosServer3[1] })) 545 tasks.push(servers[2].views.simulateView({ id: remoteVideosServer3[1] }))
545 tasks.push(servers[2].videos.view({ id: remoteVideosServer3[1] })) 546 tasks.push(servers[2].views.simulateView({ id: remoteVideosServer3[1] }))
546 tasks.push(servers[2].videos.view({ id: remoteVideosServer3[1] })) 547 tasks.push(servers[2].views.simulateView({ id: remoteVideosServer3[1] }))
547 tasks.push(servers[2].videos.view({ id: localVideosServer3[1] })) 548 tasks.push(servers[2].views.simulateView({ id: localVideosServer3[1] }))
548 tasks.push(servers[2].videos.view({ id: localVideosServer3[1] })) 549 tasks.push(servers[2].views.simulateView({ id: localVideosServer3[1] }))
549 tasks.push(servers[2].videos.view({ id: localVideosServer3[1] })) 550 tasks.push(servers[2].views.simulateView({ id: localVideosServer3[1] }))
550 551
551 await Promise.all(tasks) 552 await Promise.all(tasks)
552 553
553 await waitJobs(servers) 554 await waitJobs(servers)
554 555
555 // Wait the repeatable job 556 for (const server of servers) {
556 await wait(16000) 557 await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } })
558 }
557 559
558 await waitJobs(servers) 560 await waitJobs(servers)
559 561
diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts
index d37043aef..0e429fef7 100644
--- a/server/tests/api/videos/single-server.ts
+++ b/server/tests/api/videos/single-server.ts
@@ -179,22 +179,21 @@ describe('Test a single server', function () {
179 it('Should have the views updated', async function () { 179 it('Should have the views updated', async function () {
180 this.timeout(20000) 180 this.timeout(20000)
181 181
182 await server.videos.view({ id: videoId }) 182 await server.views.simulateView({ id: videoId })
183 await server.videos.view({ id: videoId }) 183 await server.views.simulateView({ id: videoId })
184 await server.videos.view({ id: videoId }) 184 await server.views.simulateView({ id: videoId })
185 185
186 await wait(1500) 186 await wait(1500)
187 187
188 await server.videos.view({ id: videoId }) 188 await server.views.simulateView({ id: videoId })
189 await server.videos.view({ id: videoId }) 189 await server.views.simulateView({ id: videoId })
190 190
191 await wait(1500) 191 await wait(1500)
192 192
193 await server.videos.view({ id: videoId }) 193 await server.views.simulateView({ id: videoId })
194 await server.videos.view({ id: videoId }) 194 await server.views.simulateView({ id: videoId })
195 195
196 // Wait the repeatable job 196 await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } })
197 await wait(8000)
198 197
199 const video = await server.videos.get({ id: videoId }) 198 const video = await server.videos.get({ id: videoId })
200 expect(video.views).to.equal(3) 199 expect(video.views).to.equal(3)
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts
index 09a4bfa70..6f495c42d 100644
--- a/server/tests/api/videos/video-channels.ts
+++ b/server/tests/api/videos/video-channels.ts
@@ -466,8 +466,8 @@ describe('Test video channels', function () {
466 466
467 { 467 {
468 // video has been posted on channel servers[0].store.videoChannel.id since last update 468 // video has been posted on channel servers[0].store.videoChannel.id since last update
469 await servers[0].videos.view({ id: videoUUID, xForwardedFor: '0.0.0.1,127.0.0.1' }) 469 await servers[0].views.simulateView({ id: videoUUID, xForwardedFor: '0.0.0.1,127.0.0.1' })
470 await servers[0].videos.view({ id: videoUUID, xForwardedFor: '0.0.0.2,127.0.0.1' }) 470 await servers[0].views.simulateView({ id: videoUUID, xForwardedFor: '0.0.0.2,127.0.0.1' })
471 471
472 // Wait the repeatable job 472 // Wait the repeatable job
473 await wait(8000) 473 await wait(8000)
diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts
index 8648c97f0..b1b3ff10a 100644
--- a/server/tests/api/videos/videos-history.ts
+++ b/server/tests/api/videos/videos-history.ts
@@ -3,15 +3,8 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { wait } from '@shared/core-utils' 5import { wait } from '@shared/core-utils'
6import { HttpStatusCode, Video } from '@shared/models' 6import { Video } from '@shared/models'
7import { 7import { cleanupTests, createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
8 cleanupTests,
9 createSingleServer,
10 HistoryCommand,
11 killallServers,
12 PeerTubeServer,
13 setAccessTokensToServers
14} from '@shared/server-commands'
15 8
16const expect = chai.expect 9const expect = chai.expect
17 10
@@ -23,7 +16,6 @@ describe('Test videos history', function () {
23 let video3UUID: string 16 let video3UUID: string
24 let video3WatchedDate: Date 17 let video3WatchedDate: Date
25 let userAccessToken: string 18 let userAccessToken: string
26 let command: HistoryCommand
27 19
28 before(async function () { 20 before(async function () {
29 this.timeout(30000) 21 this.timeout(30000)
@@ -32,30 +24,26 @@ describe('Test videos history', function () {
32 24
33 await setAccessTokensToServers([ server ]) 25 await setAccessTokensToServers([ server ])
34 26
35 command = server.history 27 // 10 seconds long
28 const fixture = 'video_59fps.mp4'
36 29
37 { 30 {
38 const { id, uuid } = await server.videos.upload({ attributes: { name: 'video 1' } }) 31 const { id, uuid } = await server.videos.upload({ attributes: { name: 'video 1', fixture } })
39 video1UUID = uuid 32 video1UUID = uuid
40 video1Id = id 33 video1Id = id
41 } 34 }
42 35
43 { 36 {
44 const { uuid } = await server.videos.upload({ attributes: { name: 'video 2' } }) 37 const { uuid } = await server.videos.upload({ attributes: { name: 'video 2', fixture } })
45 video2UUID = uuid 38 video2UUID = uuid
46 } 39 }
47 40
48 { 41 {
49 const { uuid } = await server.videos.upload({ attributes: { name: 'video 3' } }) 42 const { uuid } = await server.videos.upload({ attributes: { name: 'video 3', fixture } })
50 video3UUID = uuid 43 video3UUID = uuid
51 } 44 }
52 45
53 const user = { 46 userAccessToken = await server.users.generateUserAndToken('user_1')
54 username: 'user_1',
55 password: 'super password'
56 }
57 await server.users.create({ username: user.username, password: user.password })
58 userAccessToken = await server.login.getAccessToken(user)
59 }) 47 })
60 48
61 it('Should get videos, without watching history', async function () { 49 it('Should get videos, without watching history', async function () {
@@ -70,8 +58,8 @@ describe('Test videos history', function () {
70 }) 58 })
71 59
72 it('Should watch the first and second video', async function () { 60 it('Should watch the first and second video', async function () {
73 await command.watchVideo({ videoId: video2UUID, currentTime: 8 }) 61 await server.views.view({ id: video2UUID, token: server.accessToken, currentTime: 8 })
74 await command.watchVideo({ videoId: video1UUID, currentTime: 3 }) 62 await server.views.view({ id: video1UUID, token: server.accessToken, currentTime: 3 })
75 }) 63 })
76 64
77 it('Should return the correct history when listing, searching and getting videos', async function () { 65 it('Should return the correct history when listing, searching and getting videos', async function () {
@@ -124,9 +112,9 @@ describe('Test videos history', function () {
124 112
125 it('Should have these videos when listing my history', async function () { 113 it('Should have these videos when listing my history', async function () {
126 video3WatchedDate = new Date() 114 video3WatchedDate = new Date()
127 await command.watchVideo({ videoId: video3UUID, currentTime: 2 }) 115 await server.views.view({ id: video3UUID, token: server.accessToken, currentTime: 2 })
128 116
129 const body = await command.list() 117 const body = await server.history.list()
130 118
131 expect(body.total).to.equal(3) 119 expect(body.total).to.equal(3)
132 120
@@ -137,14 +125,14 @@ describe('Test videos history', function () {
137 }) 125 })
138 126
139 it('Should not have videos history on another user', async function () { 127 it('Should not have videos history on another user', async function () {
140 const body = await command.list({ token: userAccessToken }) 128 const body = await server.history.list({ token: userAccessToken })
141 129
142 expect(body.total).to.equal(0) 130 expect(body.total).to.equal(0)
143 expect(body.data).to.have.lengthOf(0) 131 expect(body.data).to.have.lengthOf(0)
144 }) 132 })
145 133
146 it('Should be able to search through videos in my history', async function () { 134 it('Should be able to search through videos in my history', async function () {
147 const body = await command.list({ search: '2' }) 135 const body = await server.history.list({ search: '2' })
148 expect(body.total).to.equal(1) 136 expect(body.total).to.equal(1)
149 137
150 const videos = body.data 138 const videos = body.data
@@ -152,11 +140,11 @@ describe('Test videos history', function () {
152 }) 140 })
153 141
154 it('Should clear my history', async function () { 142 it('Should clear my history', async function () {
155 await command.removeAll({ beforeDate: video3WatchedDate.toISOString() }) 143 await server.history.removeAll({ beforeDate: video3WatchedDate.toISOString() })
156 }) 144 })
157 145
158 it('Should have my history cleared', async function () { 146 it('Should have my history cleared', async function () {
159 const body = await command.list() 147 const body = await server.history.list()
160 expect(body.total).to.equal(1) 148 expect(body.total).to.equal(1)
161 149
162 const videos = body.data 150 const videos = body.data
@@ -168,7 +156,10 @@ describe('Test videos history', function () {
168 videosHistoryEnabled: false 156 videosHistoryEnabled: false
169 }) 157 })
170 158
171 await command.watchVideo({ videoId: video2UUID, currentTime: 8, expectedStatus: HttpStatusCode.CONFLICT_409 }) 159 await server.views.view({ id: video2UUID, token: server.accessToken, currentTime: 8 })
160
161 const { data } = await server.history.list()
162 expect(data[0].name).to.not.equal('video 2')
172 }) 163 })
173 164
174 it('Should re-enable videos history', async function () { 165 it('Should re-enable videos history', async function () {
@@ -176,14 +167,10 @@ describe('Test videos history', function () {
176 videosHistoryEnabled: true 167 videosHistoryEnabled: true
177 }) 168 })
178 169
179 await command.watchVideo({ videoId: video1UUID, currentTime: 8 }) 170 await server.views.view({ id: video2UUID, token: server.accessToken, currentTime: 8 })
180 171
181 const body = await command.list() 172 const { data } = await server.history.list()
182 expect(body.total).to.equal(2) 173 expect(data[0].name).to.equal('video 2')
183
184 const videos = body.data
185 expect(videos[0].name).to.equal('video 1')
186 expect(videos[1].name).to.equal('video 3')
187 }) 174 })
188 175
189 it('Should not clean old history', async function () { 176 it('Should not clean old history', async function () {
@@ -197,7 +184,7 @@ describe('Test videos history', function () {
197 184
198 // Should still have history 185 // Should still have history
199 186
200 const body = await command.list() 187 const body = await server.history.list()
201 expect(body.total).to.equal(2) 188 expect(body.total).to.equal(2)
202 }) 189 })
203 190
@@ -210,25 +197,25 @@ describe('Test videos history', function () {
210 197
211 await wait(6000) 198 await wait(6000)
212 199
213 const body = await command.list() 200 const body = await server.history.list()
214 expect(body.total).to.equal(0) 201 expect(body.total).to.equal(0)
215 }) 202 })
216 203
217 it('Should delete a specific history element', async function () { 204 it('Should delete a specific history element', async function () {
218 { 205 {
219 await command.watchVideo({ videoId: video1UUID, currentTime: 4 }) 206 await server.views.view({ id: video1UUID, token: server.accessToken, currentTime: 4 })
220 await command.watchVideo({ videoId: video2UUID, currentTime: 8 }) 207 await server.views.view({ id: video2UUID, token: server.accessToken, currentTime: 8 })
221 } 208 }
222 209
223 { 210 {
224 const body = await command.list() 211 const body = await server.history.list()
225 expect(body.total).to.equal(2) 212 expect(body.total).to.equal(2)
226 } 213 }
227 214
228 { 215 {
229 await command.removeElement({ videoId: video1Id }) 216 await server.history.removeElement({ videoId: video1Id })
230 217
231 const body = await command.list() 218 const body = await server.history.list()
232 expect(body.total).to.equal(1) 219 expect(body.total).to.equal(1)
233 expect(body.data[0].uuid).to.equal(video2UUID) 220 expect(body.data[0].uuid).to.equal(video2UUID)
234 } 221 }
diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts
deleted file mode 100644
index e6815a4a8..000000000
--- a/server/tests/api/videos/videos-views-cleaner.ts
+++ /dev/null
@@ -1,101 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { wait } from '@shared/core-utils'
6import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 killallServers,
11 PeerTubeServer,
12 setAccessTokensToServers,
13 waitJobs
14} from '@shared/server-commands'
15
16const expect = chai.expect
17
18describe('Test video views cleaner', function () {
19 let servers: PeerTubeServer[]
20
21 let videoIdServer1: string
22 let videoIdServer2: string
23
24 before(async function () {
25 this.timeout(120000)
26
27 servers = await createMultipleServers(2)
28 await setAccessTokensToServers(servers)
29
30 await doubleFollow(servers[0], servers[1])
31
32 videoIdServer1 = (await servers[0].videos.quickUpload({ name: 'video server 1' })).uuid
33 videoIdServer2 = (await servers[1].videos.quickUpload({ name: 'video server 2' })).uuid
34
35 await waitJobs(servers)
36
37 await servers[0].videos.view({ id: videoIdServer1 })
38 await servers[1].videos.view({ id: videoIdServer1 })
39 await servers[0].videos.view({ id: videoIdServer2 })
40 await servers[1].videos.view({ id: videoIdServer2 })
41
42 await waitJobs(servers)
43 })
44
45 it('Should not clean old video views', async function () {
46 this.timeout(50000)
47
48 await killallServers([ servers[0] ])
49
50 await servers[0].run({ views: { videos: { remote: { max_age: '10 days' } } } })
51
52 await wait(6000)
53
54 // Should still have views
55
56 {
57 for (const server of servers) {
58 const total = await server.sql.countVideoViewsOf(videoIdServer1)
59 expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views')
60 }
61 }
62
63 {
64 for (const server of servers) {
65 const total = await server.sql.countVideoViewsOf(videoIdServer2)
66 expect(total).to.equal(2, 'Server ' + server.serverNumber + ' does not have the correct amount of views')
67 }
68 }
69 })
70
71 it('Should clean old video views', async function () {
72 this.timeout(50000)
73
74 await killallServers([ servers[0] ])
75
76 await servers[0].run({ views: { videos: { remote: { max_age: '5 seconds' } } } })
77
78 await wait(6000)
79
80 // Should still have views
81
82 {
83 for (const server of servers) {
84 const total = await server.sql.countVideoViewsOf(videoIdServer1)
85 expect(total).to.equal(2)
86 }
87 }
88
89 {
90 const totalServer1 = await servers[0].sql.countVideoViewsOf(videoIdServer2)
91 expect(totalServer1).to.equal(0)
92
93 const totalServer2 = await servers[1].sql.countVideoViewsOf(videoIdServer2)
94 expect(totalServer2).to.equal(2)
95 }
96 })
97
98 after(async function () {
99 await cleanupTests(servers)
100 })
101})