aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-18 10:53:54 +0100
committerChocobozzz <me@florianbigard.com>2018-01-18 15:42:20 +0100
commitf05a1c30c15d2ae35c11e241ca039a72eeb7d6ad (patch)
tree6d90c0de5dd3ad506e738d447e4f396951ed5624 /server/tests
parent1174a8479ab9ee47b3305d668fe757435057a298 (diff)
downloadPeerTube-f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad.tar.gz
PeerTube-f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad.tar.zst
PeerTube-f05a1c30c15d2ae35c11e241ca039a72eeb7d6ad.zip
Don't show videos of remote instance after unfollow
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/users.ts2
-rw-r--r--server/tests/api/server/follows.ts24
-rw-r--r--server/tests/api/users/users-multiple-servers.ts66
-rw-r--r--server/tests/api/users/users.ts4
-rw-r--r--server/tests/api/videos/multiple-servers.ts14
-rw-r--r--server/tests/api/videos/single-server.ts17
-rw-r--r--server/tests/api/videos/video-comments.ts4
-rw-r--r--server/tests/utils/miscs/miscs.ts9
-rw-r--r--server/tests/utils/users/accounts.ts25
-rw-r--r--server/tests/utils/users/users.ts2
-rw-r--r--server/tests/utils/videos/videos.ts31
11 files changed, 158 insertions, 40 deletions
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index 14fcf8703..0c9d933a7 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -185,7 +185,7 @@ describe('Test users API validators', function () {
185 path, 185 path,
186 token: server.accessToken, 186 token: server.accessToken,
187 fields: baseCorrectParams, 187 fields: baseCorrectParams,
188 statusCodeExpected: 204 188 statusCodeExpected: 200
189 }) 189 })
190 }) 190 })
191 191
diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts
index fad58e840..ac614d605 100644
--- a/server/tests/api/server/follows.ts
+++ b/server/tests/api/server/follows.ts
@@ -4,7 +4,7 @@ import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { Video, VideoPrivacy } from '../../../../shared/models/videos' 5import { Video, VideoPrivacy } from '../../../../shared/models/videos'
6import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' 6import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
7import { completeVideoCheck } from '../../utils' 7import { checkVideoFilesWereRemoved, completeVideoCheck, getVideoChannelsList } from '../../utils'
8 8
9import { 9import {
10 flushAndRunMultipleServers, flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo, 10 flushAndRunMultipleServers, flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo,
@@ -12,7 +12,7 @@ import {
12} from '../../utils/index' 12} from '../../utils/index'
13import { dateIsValid } from '../../utils/miscs/miscs' 13import { dateIsValid } from '../../utils/miscs/miscs'
14import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../../utils/server/follows' 14import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort, unfollow } from '../../utils/server/follows'
15import { expectAccountFollows } from '../../utils/users/accounts' 15import { expectAccountFollows, getAccountsList } from '../../utils/users/accounts'
16import { userLogin } from '../../utils/users/login' 16import { userLogin } from '../../utils/users/login'
17import { createUser } from '../../utils/users/users' 17import { createUser } from '../../utils/users/users'
18import { 18import {
@@ -343,6 +343,26 @@ describe('Test follows', function () {
343 expect(secondChild.comment.text).to.equal('my second answer to thread 1') 343 expect(secondChild.comment.text).to.equal('my second answer to thread 1')
344 expect(secondChild.children).to.have.lengthOf(0) 344 expect(secondChild.children).to.have.lengthOf(0)
345 }) 345 })
346
347 it('Should unfollow server 3 on server 1 and does not list server 3 videos', async function () {
348 this.timeout(5000)
349
350 await unfollow(servers[0].url, servers[0].accessToken, servers[2])
351
352 await wait(3000)
353
354 let res = await getVideosList(servers[ 0 ].url)
355 expect(res.body.total).to.equal(1)
356
357 res = await getVideoChannelsList(servers[0].url, 0, 1)
358 expect(res.body.total).to.equal(2)
359
360 res = await getAccountsList(servers[0].url)
361 expect(res.body.total).to.equal(2)
362
363 await checkVideoFilesWereRemoved(video4.uuid, servers[0].serverNumber)
364 })
365
346 }) 366 })
347 367
348 after(async function () { 368 after(async function () {
diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts
index 1c7f011a8..0483b9c3d 100644
--- a/server/tests/api/users/users-multiple-servers.ts
+++ b/server/tests/api/users/users-multiple-servers.ts
@@ -3,18 +3,20 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { Account } from '../../../../shared/models/actors' 5import { Account } from '../../../../shared/models/actors'
6import { doubleFollow, flushAndRunMultipleServers, wait } from '../../utils' 6import { checkVideoFilesWereRemoved, createUser, doubleFollow, flushAndRunMultipleServers, removeUser, userLogin, wait } from '../../utils'
7import { 7import { flushTests, getMyUserInformation, killallServers, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../utils/index'
8 flushTests, getMyUserInformation, killallServers, ServerInfo, testVideoImage, updateMyAvatar, 8import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../utils/users/accounts'
9 uploadVideo
10} from '../../utils/index'
11import { getAccount, getAccountsList } from '../../utils/users/accounts'
12import { setAccessTokensToServers } from '../../utils/users/login' 9import { setAccessTokensToServers } from '../../utils/users/login'
13 10
14const expect = chai.expect 11const expect = chai.expect
15 12
16describe('Test users with multiple servers', function () { 13describe('Test users with multiple servers', function () {
17 let servers: ServerInfo[] = [] 14 let servers: ServerInfo[] = []
15 let user
16 let userUUID
17 let userId
18 let videoUUID
19 let userAccessToken
18 20
19 before(async function () { 21 before(async function () {
20 this.timeout(120000) 22 this.timeout(120000)
@@ -34,6 +36,18 @@ describe('Test users with multiple servers', function () {
34 // The root user of server 1 is propagated to servers 2 and 3 36 // The root user of server 1 is propagated to servers 2 and 3
35 await uploadVideo(servers[0].url, servers[0].accessToken, {}) 37 await uploadVideo(servers[0].url, servers[0].accessToken, {})
36 38
39 const user = {
40 username: 'user1',
41 password: 'password'
42 }
43 const resUser = await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
44 userUUID = resUser.body.user.uuid
45 userId = resUser.body.user.id
46 userAccessToken = await userLogin(servers[0], user)
47
48 const resVideo = await uploadVideo(servers[0].url, userAccessToken, {})
49 videoUUID = resVideo.body.uuid
50
37 await wait(5000) 51 await wait(5000)
38 }) 52 })
39 53
@@ -49,9 +63,9 @@ describe('Test users with multiple servers', function () {
49 }) 63 })
50 64
51 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) 65 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
52 const user = res.body 66 user = res.body
53 67
54 const test = await testVideoImage(servers[0].url, 'avatar2-resized', user.account.avatar.path, '.png') 68 const test = await testImage(servers[0].url, 'avatar2-resized', user.account.avatar.path, '.png')
55 expect(test).to.equal(true) 69 expect(test).to.equal(true)
56 70
57 await wait(5000) 71 await wait(5000)
@@ -69,11 +83,45 @@ describe('Test users with multiple servers', function () {
69 expect(rootServer1Get.name).to.equal('root') 83 expect(rootServer1Get.name).to.equal('root')
70 expect(rootServer1Get.host).to.equal('localhost:9001') 84 expect(rootServer1Get.host).to.equal('localhost:9001')
71 85
72 const test = await testVideoImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png') 86 const test = await testImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png')
73 expect(test).to.equal(true) 87 expect(test).to.equal(true)
74 } 88 }
75 }) 89 })
76 90
91 it('Should remove the user', async function () {
92 this.timeout(10000)
93
94 for (const server of servers) {
95 const resAccounts = await getAccountsList(server.url, '-createdAt')
96
97 const userServer1List = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account
98 expect(userServer1List).not.to.be.undefined
99 }
100
101 await removeUser(servers[0].url, userId, servers[0].accessToken)
102
103 await wait(5000)
104
105 for (const server of servers) {
106 const resAccounts = await getAccountsList(server.url, '-createdAt')
107
108 const userServer1List = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:9001') as Account
109 expect(userServer1List).to.be.undefined
110 }
111 })
112
113 it('Should not have actor files', async () => {
114 for (const server of servers) {
115 await checkActorFilesWereRemoved(userUUID, server.serverNumber)
116 }
117 })
118
119 it('Should not have video files', async () => {
120 for (const server of servers) {
121 await checkVideoFilesWereRemoved(videoUUID, server.serverNumber)
122 }
123 })
124
77 after(async function () { 125 after(async function () {
78 killallServers(servers) 126 killallServers(servers)
79 127
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index b788637e7..d8004ff24 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -7,7 +7,7 @@ import {
7 createUser, flushTests, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating, getUserInformation, 7 createUser, flushTests, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating, getUserInformation,
8 getUsersList, 8 getUsersList,
9 getUsersListPaginationAndSort, getVideosList, killallServers, login, makePutBodyRequest, rateVideo, registerUser, removeUser, removeVideo, 9 getUsersListPaginationAndSort, getVideosList, killallServers, login, makePutBodyRequest, rateVideo, registerUser, removeUser, removeVideo,
10 runServer, ServerInfo, serverLogin, testVideoImage, updateMyAvatar, updateMyUser, updateUser, uploadVideo 10 runServer, ServerInfo, serverLogin, testImage, updateMyAvatar, updateMyUser, updateUser, uploadVideo
11} from '../../utils/index' 11} from '../../utils/index'
12import { follow } from '../../utils/server/follows' 12import { follow } from '../../utils/server/follows'
13import { setAccessTokensToServers } from '../../utils/users/login' 13import { setAccessTokensToServers } from '../../utils/users/login'
@@ -361,7 +361,7 @@ describe('Test users', function () {
361 const res = await getMyUserInformation(server.url, accessTokenUser) 361 const res = await getMyUserInformation(server.url, accessTokenUser)
362 const user = res.body 362 const user = res.body
363 363
364 const test = await testVideoImage(server.url, 'avatar-resized', user.account.avatar.path, '.png') 364 const test = await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png')
365 expect(test).to.equal(true) 365 expect(test).to.equal(true)
366 }) 366 })
367 367
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index 6712829d4..4c4b5123d 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -8,8 +8,9 @@ import { VideoPrivacy } from '../../../../shared/models/videos'
8import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' 8import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
9 9
10import { 10import {
11 addVideoChannel, completeVideoCheck, createUser, dateIsValid, doubleFollow, flushAndRunMultipleServers, flushTests, getVideo, 11 addVideoChannel, checkVideoFilesWereRemoved, completeVideoCheck, createUser, dateIsValid, doubleFollow, flushAndRunMultipleServers,
12 getVideoChannelsList, getVideosList, killallServers, rateVideo, removeVideo, ServerInfo, setAccessTokensToServers, testVideoImage, 12 flushTests, getVideo,
13 getVideoChannelsList, getVideosList, killallServers, rateVideo, removeVideo, ServerInfo, setAccessTokensToServers, testImage,
13 updateVideo, uploadVideo, userLogin, viewVideo, wait, webtorrentAdd 14 updateVideo, uploadVideo, userLogin, viewVideo, wait, webtorrentAdd
14} from '../../utils' 15} from '../../utils'
15import { 16import {
@@ -578,6 +579,13 @@ describe('Test multiple servers', function () {
578 await wait(5000) 579 await wait(5000)
579 }) 580 })
580 581
582 it('Should not have files of videos 3 and 3-2 on each server', async function () {
583 for (const server of servers) {
584 await checkVideoFilesWereRemoved(toRemove[0].uuid, server.serverNumber)
585 await checkVideoFilesWereRemoved(toRemove[1].uuid, server.serverNumber)
586 }
587 })
588
581 it('Should have videos 1 and 3 on each server', async function () { 589 it('Should have videos 1 and 3 on each server', async function () {
582 for (const server of servers) { 590 for (const server of servers) {
583 const res = await getVideosList(server.url) 591 const res = await getVideosList(server.url)
@@ -624,7 +632,7 @@ describe('Test multiple servers', function () {
624 const res = await getVideo(server.url, videoUUID) 632 const res = await getVideo(server.url, videoUUID)
625 const video = res.body 633 const video = res.body
626 634
627 const test = await testVideoImage(server.url, 'video_short1-preview.webm', video.previewPath) 635 const test = await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
628 expect(test).to.equal(true) 636 expect(test).to.equal(true)
629 } 637 }
630 }) 638 })
diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts
index ca20f39a0..76d265ec5 100644
--- a/server/tests/api/videos/single-server.ts
+++ b/server/tests/api/videos/single-server.ts
@@ -3,13 +3,12 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import { keyBy } from 'lodash' 4import { keyBy } from 'lodash'
5import 'mocha' 5import 'mocha'
6import { join } from 'path'
7import { VideoPrivacy } from '../../../../shared/models/videos' 6import { VideoPrivacy } from '../../../../shared/models/videos'
8import { readdirPromise } from '../../../helpers/core-utils'
9import { 7import {
10 completeVideoCheck, flushTests, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences, getVideoPrivacies, 8 checkVideoFilesWereRemoved, completeVideoCheck, flushTests, getVideo, getVideoCategories, getVideoLanguages, getVideoLicences,
11 getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, removeVideo, runServer, searchVideo, 9 getVideoPrivacies, getVideosList, getVideosListPagination, getVideosListSort, killallServers, rateVideo, removeVideo, runServer,
12 searchVideoWithPagination, searchVideoWithSort, ServerInfo, setAccessTokensToServers, testVideoImage, updateVideo, uploadVideo, viewVideo 10 searchVideo, searchVideoWithPagination, searchVideoWithSort, ServerInfo, setAccessTokensToServers, testImage, updateVideo, uploadVideo,
11 viewVideo
13} from '../../utils' 12} from '../../utils'
14 13
15const expect = chai.expect 14const expect = chai.expect
@@ -277,11 +276,7 @@ describe('Test a single server', function () {
277 it('Should remove the video', async function () { 276 it('Should remove the video', async function () {
278 await removeVideo(server.url, server.accessToken, videoId) 277 await removeVideo(server.url, server.accessToken, videoId)
279 278
280 const files1 = await readdirPromise(join(__dirname, '..', '..', '..', '..', 'test1', 'videos')) 279 await checkVideoFilesWereRemoved(videoUUID, 1)
281 expect(files1).to.have.lengthOf(0)
282
283 const files2 = await readdirPromise(join(__dirname, '..', '..', '..', '..', 'test1', 'thumbnails'))
284 expect(files2).to.have.lengthOf(0)
285 }) 280 })
286 281
287 it('Should not have videos', async function () { 282 it('Should not have videos', async function () {
@@ -346,7 +341,7 @@ describe('Test a single server', function () {
346 341
347 for (const video of videos) { 342 for (const video of videos) {
348 const videoName = video.name.replace(' name', '') 343 const videoName = video.name.replace(' name', '')
349 const test = await testVideoImage(server.url, videoName, video.thumbnailPath) 344 const test = await testImage(server.url, videoName, video.thumbnailPath)
350 345
351 expect(test).to.equal(true) 346 expect(test).to.equal(true)
352 } 347 }
diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts
index 18d484ccf..0eddac35b 100644
--- a/server/tests/api/videos/video-comments.ts
+++ b/server/tests/api/videos/video-comments.ts
@@ -3,7 +3,7 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' 5import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
6import { testVideoImage } from '../../utils' 6import { testImage } from '../../utils'
7import { 7import {
8 dateIsValid, flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, updateMyAvatar, 8 dateIsValid, flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, updateMyAvatar,
9 uploadVideo 9 uploadVideo
@@ -83,7 +83,7 @@ describe('Test video comments', function () {
83 expect(comment.account.name).to.equal('root') 83 expect(comment.account.name).to.equal('root')
84 expect(comment.account.host).to.equal('localhost:9001') 84 expect(comment.account.host).to.equal('localhost:9001')
85 85
86 const test = await testVideoImage(server.url, 'avatar-resized', comment.account.avatar.path, '.png') 86 const test = await testImage(server.url, 'avatar-resized', comment.account.avatar.path, '.png')
87 expect(test).to.equal(true) 87 expect(test).to.equal(true)
88 88
89 expect(comment.totalReplies).to.equal(0) 89 expect(comment.totalReplies).to.equal(0)
diff --git a/server/tests/utils/miscs/miscs.ts b/server/tests/utils/miscs/miscs.ts
index 2aac37791..e6666619b 100644
--- a/server/tests/utils/miscs/miscs.ts
+++ b/server/tests/utils/miscs/miscs.ts
@@ -1,3 +1,4 @@
1import { join } from 'path'
1import * as WebTorrent from 'webtorrent' 2import * as WebTorrent from 'webtorrent'
2 3
3let webtorrent = new WebTorrent() 4let webtorrent = new WebTorrent()
@@ -24,11 +25,17 @@ function webtorrentAdd (torrent: string, refreshWebTorrent = false) {
24 return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res)) 25 return new Promise<WebTorrent.Torrent>(res => webtorrent.add(torrent, res))
25} 26}
26 27
28function root () {
29 // We are in server/tests/utils/miscs
30 return join(__dirname, '..', '..', '..', '..')
31}
32
27// --------------------------------------------------------------------------- 33// ---------------------------------------------------------------------------
28 34
29export { 35export {
30 dateIsValid, 36 dateIsValid,
31 wait, 37 wait,
32 webtorrentAdd, 38 webtorrentAdd,
33 immutableAssign 39 immutableAssign,
40 root
34} 41}
diff --git a/server/tests/utils/users/accounts.ts b/server/tests/utils/users/accounts.ts
index 0ec7992b3..a5c13c319 100644
--- a/server/tests/utils/users/accounts.ts
+++ b/server/tests/utils/users/accounts.ts
@@ -1,5 +1,11 @@
1/* tslint:disable:no-unused-expression */
2
1import { expect } from 'chai' 3import { expect } from 'chai'
4import { existsSync } from 'fs'
5import { join } from 'path'
2import { Account } from '../../../../shared/models/actors' 6import { Account } from '../../../../shared/models/actors'
7import { readdirPromise } from '../../../helpers/core-utils'
8import { root } from '../index'
3import { makeGetRequest } from '../requests/requests' 9import { makeGetRequest } from '../requests/requests'
4 10
5function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) { 11function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = 200) {
@@ -32,10 +38,27 @@ async function expectAccountFollows (url: string, nameWithDomain: string, follow
32 expect(account.followingCount).to.equal(followingCount, message) 38 expect(account.followingCount).to.equal(followingCount, message)
33} 39}
34 40
41async function checkActorFilesWereRemoved (actorUUID: string, serverNumber: number) {
42 const testDirectory = 'test' + serverNumber
43
44 for (const directory of [ 'avatars' ]) {
45 const directoryPath = join(root(), testDirectory, directory)
46
47 const directoryExists = existsSync(directoryPath)
48 expect(directoryExists).to.be.true
49
50 const files = await readdirPromise(directoryPath)
51 for (const file of files) {
52 expect(file).to.not.contain(actorUUID)
53 }
54 }
55}
56
35// --------------------------------------------------------------------------- 57// ---------------------------------------------------------------------------
36 58
37export { 59export {
38 getAccount, 60 getAccount,
39 expectAccountFollows, 61 expectAccountFollows,
40 getAccountsList 62 getAccountsList,
63 checkActorFilesWereRemoved
41} 64}
diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts
index 12945a805..25351e2c7 100644
--- a/server/tests/utils/users/users.ts
+++ b/server/tests/utils/users/users.ts
@@ -11,7 +11,7 @@ function createUser (
11 password: string, 11 password: string,
12 videoQuota = 1000000, 12 videoQuota = 1000000,
13 role: UserRole = UserRole.USER, 13 role: UserRole = UserRole.USER,
14 specialStatus = 204 14 specialStatus = 200
15) { 15) {
16 const path = '/api/v1/users' 16 const path = '/api/v1/users'
17 const body = { 17 const body = {
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts
index 095d4e29d..270a6042b 100644
--- a/server/tests/utils/videos/videos.ts
+++ b/server/tests/utils/videos/videos.ts
@@ -1,13 +1,13 @@
1/* tslint:disable:no-unused-expression */ 1/* tslint:disable:no-unused-expression */
2 2
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { readFile } from 'fs' 4import { existsSync, readFile } from 'fs'
5import * as parseTorrent from 'parse-torrent' 5import * as parseTorrent from 'parse-torrent'
6import { extname, isAbsolute, join } from 'path' 6import { extname, isAbsolute, join } from 'path'
7import * as request from 'supertest' 7import * as request from 'supertest'
8import { getMyUserInformation, makeGetRequest, ServerInfo } from '../' 8import { getMyUserInformation, makeGetRequest, root, ServerInfo } from '../'
9import { VideoPrivacy } from '../../../../shared/models/videos' 9import { VideoPrivacy } from '../../../../shared/models/videos'
10import { readFileBufferPromise } from '../../../helpers/core-utils' 10import { readdirPromise, readFileBufferPromise } from '../../../helpers/core-utils'
11import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers' 11import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers'
12import { dateIsValid, webtorrentAdd } from '../index' 12import { dateIsValid, webtorrentAdd } from '../index'
13 13
@@ -203,7 +203,23 @@ function searchVideoWithSort (url: string, search: string, sort: string) {
203 .expect('Content-Type', /json/) 203 .expect('Content-Type', /json/)
204} 204}
205 205
206async function testVideoImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { 206async function checkVideoFilesWereRemoved (videoUUID: string, serverNumber: number) {
207 const testDirectory = 'test' + serverNumber
208
209 for (const directory of [ 'videos', 'thumbnails', 'torrents', 'previews' ]) {
210 const directoryPath = join(root(), testDirectory, directory)
211
212 const directoryExists = existsSync(directoryPath)
213 expect(directoryExists).to.be.true
214
215 const files = await readdirPromise(directoryPath)
216 for (const file of files) {
217 expect(file).to.not.contain(videoUUID)
218 }
219 }
220}
221
222async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') {
207 // Don't test images if the node env is not set 223 // Don't test images if the node env is not set
208 // Because we need a special ffmpeg version for this test 224 // Because we need a special ffmpeg version for this test
209 if (process.env['NODE_TEST_IMAGE']) { 225 if (process.env['NODE_TEST_IMAGE']) {
@@ -409,7 +425,7 @@ async function completeVideoCheck (
409 const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100) 425 const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100)
410 expect(file.size).to.be.above(minSize).and.below(maxSize) 426 expect(file.size).to.be.above(minSize).and.below(maxSize)
411 427
412 const test = await testVideoImage(url, attributes.fixture, videoDetails.thumbnailPath) 428 const test = await testImage(url, attributes.fixture, videoDetails.thumbnailPath)
413 expect(test).to.equal(true) 429 expect(test).to.equal(true)
414 430
415 const torrent = await webtorrentAdd(magnetUri, true) 431 const torrent = await webtorrentAdd(magnetUri, true)
@@ -437,11 +453,12 @@ export {
437 searchVideo, 453 searchVideo,
438 searchVideoWithPagination, 454 searchVideoWithPagination,
439 searchVideoWithSort, 455 searchVideoWithSort,
440 testVideoImage, 456 testImage,
441 uploadVideo, 457 uploadVideo,
442 updateVideo, 458 updateVideo,
443 rateVideo, 459 rateVideo,
444 viewVideo, 460 viewVideo,
445 parseTorrentVideo, 461 parseTorrentVideo,
446 completeVideoCheck 462 completeVideoCheck,
463 checkVideoFilesWereRemoved
447} 464}